# Pyjamas (online and desktop) EV Calculator / Simulator



## gor (Nov 25, 2009)

thanks,L

what is "gear 0"?
http://lkcl.net/ev/vehicle_simulator/output/Simulator.html


----------



## lkcl (Sep 16, 2011)

ahh, that'll be the index into the list of gear ratios, which in programming of course starts from zero  i've made a few shortcuts in the print/display side, to save time getting results. ah... i know a way... yeah i know what to do. i'll update it soon... no time like the present: i just added one to the results returned from the accelerate_to_top_speed function.


----------



## charliehorse55 (Sep 23, 2011)

Units?

I assume everything is in metric?


----------



## lkcl (Sep 16, 2011)

yes for now, units are metric (can't get my head round hectares per potato for science stuff like this, even though yes i know, if i wanted to be a purist it'd be m/sec for speed...)

if you'd like to help add some code for that, here's how you could help: create a conversion for each thing that's printed and also inputted, as follows:

convert_to_imperial_units = {
'm/s': 'mph',
'Nm': 'lbft',
'm/s/s': 'mph/s',
'kg': 'lb',
anything else you can think of...

}

then:
scale_to_imperial_units = {
'mph': 2.237, # i know this one already 
'lbft': 1.32, # i know also that lbin to Nm is 0.11
'lb': 2.2, # and this one 
etc etc
}

_then_, also, for each of the inputs i need to know its scientific unit, so another python dictionary:

units_for_inputs = {
'weight': 'kg',
'drivetrain_efficiency':None,
'drag_coefficient':None,
'surface_area':'sqm',
'rolling_resistance':None,
'gear_ratios':None,
'axle_ratio':None,
'max_rpm':'rpm',
'max_accel':'m/sec', # m/sec
'max_power':'W',
'max_available_power':'W',
'peak_torque':'Nm', # Nm
'wheel_radius':'m'}

ok yeah seems i did those already  but you can see i'm missing a conversion factor for 'm' - metres and 'W' - power (watts).

help yourself, i can help you, ok? you cover the units, i'll cover the code for _printing_ in those units, ok?

l.


----------



## DavidDymaxion (Dec 1, 2008)

Thank you for posting, that looks like a nice tool.

It would improve the accuracy to have a pause in the power for shifting (just add a bit of time every shift). If you want to be really accurate, use the equations of motion to calculate how much the vehicle slows during the shift time, too. Don't forget distance will still increase during the shift.

That gave me an idea that going clutchless saves power in having less weight and rotational inertia, but takes more power to reaccelerate, especially up hills, since it can take so long to shift. Hmmm, could be fun to figure that out on a sim.


----------



## charliehorse55 (Sep 23, 2011)

I'm a metric guy anyways, it's just that the app is confusing because it lists power in kW in the results even though it's clearly in watts. 

If you could just change the texts to say 
Acceleration (m/s/s)
Weight (kg)
etc...

that would be great. 

I am not familiar python, I only know how to program C.


----------



## lkcl (Sep 16, 2011)

charliehorse55 said:


> I'm a metric guy anyways, it's just that the app is confusing because it lists power in kW in the results even though it's clearly in watts.


oh that was silly of me!



> If you could just change the texts to say
> Acceleration (m/s/s)
> Weight (kg)
> etc...
> ...


ah but that would push the column widths out - i'll think of a way round that.



> I am not familiar python, I only know how to program C.


it's literally... ok, just cut/paste that previous post, fill in the blanks. i'll do the rest.

l.


----------



## lkcl (Sep 16, 2011)

DavidDymaxion said:


> Thank you for posting, that looks like a nice tool.
> 
> It would improve the accuracy to have a pause in the power for shifting (just add a bit of time every shift). If you want to be really accurate, use the equations of motion to calculate how much the vehicle slows during the shift time, too. Don't forget distance will still increase during the shift.


 done that already  what i didn't say was that i've done this before - not just for manual gearbox vehicles but also for automatic transmissions *including* with the torque converters jaezzuss that was a bitch. there's 4 variables: the tables are based on _two_ inputs (torque and RPM) and the output is, yep you got it: torque and RPM on the other side. however, the company that asked us to do the work didn't supply us with 4D tables (whoops) so i had to make the best of it (after getting my head into a twizzie for weeks trying to revive my A-Level differential calculus i gave up and, like Dr Spock, gave it my "best guess"  )

so, yeah, with that as background, whilst i haven't gone over it with a fine-tooth-comb and the code hasn't had "peer review", it does the job (of gear changing, including not having any acceleration during the gear-change) to *my* satisfaction, which should in no way be taken as an indication of any warranty, fitness for purpose or any guarantee WHATSOEVER that the code quotes works quotes for quotes you quotes. any misunderstanding on that point, read the AGPL Software License.

sorry david that's not directed at you, that last bit's directed at the archives of the forum, for anyone reading this who might misunderstand what Software Libre is about.



> That gave me an idea that going clutchless saves power in having less weight and rotational inertia, but takes more power to reaccelerate, especially up hills, since it can take so long to shift. Hmmm, could be fun to figure that out on a sim.


oo naaasty - i like it  yes, in the simulation i did when working for Pi Technology, we just used 1.5 seconds as the gear-shift time, and that was the end of the discussion. turns out that it's not a bad approximation. as these were diesel trucks, 1.5 seconds is enough for the engine RPM to climb down (or for the driver to "blip" the accelerator and match during a downshift), and, along with the rest of the decisions made, it resulted in real world fuel economy that was accurate to 0.5%. except for one "known" and horribly complex situation 

so yes... a more "accurate" simulation would involve taking into account the fact that up hills, the engine RPM is pretty high, and takes a long time to come down again.

but - let's look at this from another perspective: you've got a Brushless DC Motor. you've also got a taco. you also can put switches on the gear levers. therefore, because it's BLDC, you can ask the speed controller to set a particular RPM (and pretty fast, too) because that corresponds to a particular voltage, meaning you _should_ be able to do really fast gear changes, even with a "simple" manual clutch.

in fact, you could probably, with a gearbox which had those cable-pulls, use solenoids to turn the manual transmission into a good approximation of an automatic.

then you'd be good on those shift times 

l.


----------



## steven4601 (Nov 11, 2010)

Your graph starts at a fixed power input until the gear-change which is highly unlikely to be accurate. 

rpm * torque = power.
if the motor rpm is zero, while producing maximum torque, the produced power is zero.

The only input power at stand-still acceleration will be the losses. 

So in other words, starting from a standstill will require very little input power. The required power will increase until the motor voltage is equal to the battery voltage. (base-speed) from there torque will decay and the power will decay to a lesser rate depending on the setup & motor-type.
An oversized AC traction motor can hold-up the output power without decay until the maximum rpm has been reached. BLDC require field reversal above base-speed which is slightly more difficult / newer in the industry


----------



## lkcl (Sep 16, 2011)

hi steven, thanks for looking at this stuff.

ok, you really need to examine the source code, carefully. remember that i've done this stuff before, but it was 18 years ago.

i have used the calculations from the spreadsheet *but* what i have then done is back-calculated to a torque value, which is then "limited" to peak torque; also it is *only* the "available" power that is assumed to be turned into acceleration, then once that has been calculated, back-calculated it into a "power" figure, and that's what you see in the 2nd column.

it really isn't as straightforward to do these simulations as it first appears, so the source code really does need to be reviewed and understood.

now, the one i did 18 years ago i had access to the fuel maps, and even there we had to do interpolation and make a few assumptions.

in this case, this is an EV not a diesel engine, so i've just made assumptions that power is a straight one-to-one map onto torque. scale the power, you scale the torque. that's strictly speaking not true, but it's a good enough approximation.

l.


----------



## lkcl (Sep 16, 2011)

steven4601 said:


> Your graph starts at a fixed power input until the gear-change which is highly unlikely to be accurate.


no it doesn't: what happens is that the acceleration is limited to "max acceleration" in order to simulate-avoid wheel-spin. it's a long story. you really do need to examine the source code, steven, and i'll answer further questions then.


btw, we ran into this difficulty in the original simulation, 18 years ago. the problem was that they'd used HP which of course is velocity-dependent.

at the time, i got round this by analysing the maths equations and taking that extra factor of "V" out of the equations.

so what i've done is a mixture: i back-calculate to Nm and then use F=ma and stuff like that, *not* the HP or Watt figure.

the "solution" that i was asked 18 years ago to deploy was to assume that the vehicle was moving in 0.5mph increments, and started off at at least 0.5mph. which i thought was silly, but is another way to get round the problem you've highlighted. if you examine the source code you'll see that i chose not to go down that route this time, but to remove "V" from the equation.


----------



## DavidDymaxion (Dec 1, 2008)

A question I have thought about is how do things change if you rev the motor and use a clutch, like you would with an ICE? I'm planning to experiment with this on my car to see if that might be a faster take-off than starting from 0 rpm. If nothing else, it would help keep the motor cooler (at the expense of a hotter clutch!).

On the sims thing I have done something similar to what you did lkcl. I figure out the torque from power at the point where you drop out of PWM to steady on, and then assume constant torque from 0 rpm to the constant power point. I also checked that torque never exceeded available traction (in other words, limit torque to available traction).


steven4601 said:


> Your graph starts at a fixed power input until the gear-change which is highly unlikely to be accurate.
> 
> rpm * torque = power.
> if the motor rpm is zero, while producing maximum torque, the produced power is zero.
> ...


----------



## lkcl (Sep 16, 2011)

you know what? it's a bitch having written something 18 years ago  details are slowly being extricated out of my brain's chemical memory.

and yes, one of the assumptions is that a standard ICE clutch is involved (sorry, i didn't spell that out but it's outlined as a conclusion here: http://lkcl.net/ev/drivetrain.html )

i remember now: 18 years ago we had to assume that the engine would stall below 500RPM *but* the fuel maps only went as far as 800RPM. so not only did we have to work with the assumption that you only worked from a minimum of 0.5mph, but also the engine had to be assumed to be working at at least 500RPM until it reached the _real_ speed in that gear, and that the "driver" would be burning the clutch-plate until that happened 

so yes, for the EV conversion i'm planning, yes i will be leaving the clutch entirely intact, just replace the ICE motor on the suzuki swift gearbox with a kelly controller BLDC MARS0913 (unless anyone has any better suggestions for items that have a better "bang-per-buck" ratio)?

http://kellycontroller.com/mars-0913etek-comparablepmsmbldc-motor-p-874.html

then it fits onto here:










the reason for picking the MARS0913 is because it is only 8in x 8in diameter, that fits really neatly onto that suzuki swift gearbox, leaving something that would only be about 24in wide, and still 17in long.

so, the default stuff i've done on the simulation page, you can see it uses the ratios of the suzuki swift, uses the MARS0913 rated torque as a "top limit", etc. etc.

but anyone can play with it, plug in alternative numbers.


----------



## lkcl (Sep 16, 2011)

ok, i've just corrected a bug in the simulator, which is actually carried over from the spreadsheet. i'll try to find the error in the original spreadsheet and report that there, too.


----------

