Script v1.4.4.0
Engine v7.0.0.2
- General
- Entity
- Node
- Scenegraph
- Lighting
- Camera
- Shape
- Particle System
- Physics
- Spline
- Animation
- Overlays
- Sound
- Input
- XML
- Network
- Callbacks
- Text Rendering
- Terrain Detail
- Tire Track
- Editor
- Rendering
- String
- Math
- I3D
- Fillplanes
Foundation Reference
VehicleMotor
DescriptionClass for vehicle motorsFunctions
- new
- setLowBrakeForce
- getMaxClutchTorque
- getRotInertia
- setRotInertia
- getDampingRate
- setDampingRate
- getMaxTorque
- getBrakeForce
- getMinRpm
- getMaxRpm
- getLastMotorRpm
- getLastRealMotorRpm
- setLastRpm
- getMotorLoad
- getEqualizedMotorRpm
- setEqualizedMotorRpm
- getPtoMotorRpmRatio
- getNonClampedMotorRpm
- getClutchRpm
- getTorqueCurve
- getTorque
- getMaximumForwardSpeed
- getMaximumBackwardSpeed
- calculatePhysicalMaximumForwardSpeed
- calculatePhysicalMaximumBackwardSpeed
- calculatePhysicalMaximumSpeed
- updateMotorRpm
- getBestGearRatio
- getBestGear
- updateGear
- getGearRatio
- getCurMaxRpm
- setSpeedLimit
- setRpmLimit
new
DescriptionCreating new motorDefinition
new(integer minRpm, integer maxRpm, float maxForwardSpeed, float maxBackwardSpeed, table torqueCurve, float brakeForce, float forwardGearRatio, float backwardGearRatio, float minForwardGearRatio, float maxForwardGearRatio, float minBackwardGearRatio, float maxBackwardGearRatio, integer ptoMotorRpmRatio, float rpmFadeOutRange, float maxTorque, float maxMotorPower)Arguments
integer | minRpm | min rpm |
integer | maxRpm | max rpm |
float | maxForwardSpeed | max forward speed |
float | maxBackwardSpeed | max backward speed |
table | torqueCurve | torque curve (AnimCurve) |
float | brakeForce | brake force |
float | forwardGearRatio | forward gear ratio |
float | backwardGearRatio | backward gear ratio |
float | minForwardGearRatio | min forward gear ratio |
float | maxForwardGearRatio | max forward gear ratio |
float | minBackwardGearRatio | min backward gear ratio |
float | maxBackwardGearRatio | max backward gear ratio |
integer | ptoMotorRpmRatio | pto motor rpm ratio |
float | rpmFadeOutRange | rpm fade out range |
float | maxTorque | max torque |
float | maxMotorPower | max motor power |
table | motorInstance | motor instance |
35 | function VehicleMotor:new(vehicle, minRpm, maxRpm, maxForwardSpeed, maxBackwardSpeed, torqueCurve, brakeForce, forwardGearRatio, backwardGearRatio, minForwardGearRatio, maxForwardGearRatio, minBackwardGearRatio, maxBackwardGearRatio, ptoMotorRpmRatio, rpmFadeOutRange, maxTorque, maxMotorPower, minSpeed) |
36 | |
37 | local self = {}; |
38 | setmetatable(self, VehicleMotor_mt); |
39 | |
40 | self.vehicle = vehicle; |
41 | self.minRpm = minRpm; |
42 | self.maxRpm = maxRpm; |
43 | self.minSpeed = minSpeed; |
44 | self.maxForwardSpeed = maxForwardSpeed; -- speed in m/s |
45 | self.maxBackwardSpeed = maxBackwardSpeed; |
46 | |
47 | self.maxClutchTorque = 5; -- amount of torque that can be transferred from motor to clutch/wheels [t m s^-2] |
48 | |
49 | self.torqueCurve = torqueCurve; |
50 | self.brakeForce = brakeForce; |
51 | |
52 | self.gear = 0; |
53 | self.gearRatio = 0; |
54 | |
55 | self.forwardGearRatios = {forwardGearRatio}; |
56 | self.backwardGearRatios = {backwardGearRatio}; |
57 | self.minForwardGearRatio = minForwardGearRatio; |
58 | self.maxForwardGearRatio = maxForwardGearRatio; |
59 | self.minBackwardGearRatio = minBackwardGearRatio; |
60 | self.maxBackwardGearRatio = maxBackwardGearRatio; |
61 | |
62 | self.lastRealMotorRpm = 0; |
63 | self.lastMotorRpm = 0; |
64 | |
65 | self.rpmFadeOutRange = rpmFadeOutRange; |
66 | self.rpmLimit = math.huge; |
67 | self.speedLimit = math.huge; -- Speed limit in km/h |
68 | self.speedLimitAcc = math.huge; |
69 | |
70 | -- this is not clamped by minRpm |
71 | self.nonClampedMotorRpm = 0; |
72 | self.equalizedMotorRpm = 0; |
73 | self.clutchRpm = 0; |
74 | self.motorLoad = 0; |
75 | self.requiredMotorPower = 0; |
76 | |
77 | if self.maxForwardSpeed == nil then |
78 | self.maxForwardSpeed = self:calculatePhysicalMaximumForwardSpeed(); |
79 | end |
80 | if self.maxBackwardSpeed == nil then |
81 | self.maxBackwardSpeed = self:calculatePhysicalMaximumBackwardSpeed(); |
82 | end |
83 | |
84 | self.maxMotorTorque = self.torqueCurve:getMaximum(); |
85 | |
86 | self.ptoMotorRpmRatio = ptoMotorRpmRatio; |
87 | |
88 | self.maxMotorPower = maxMotorPower; |
89 | |
90 | self.rotInertia = 0.001; -- Rotational inertia of the motor, mostly defined by the flywheel [t m^2] |
91 | self.dampingRate = 0.0007; -- Damping rate of the motor if the acceleration pedal is 0 [t m^2 s^-1] |
92 | |
93 | return self; |
94 | end; |
setLowBrakeForce
DescriptionSet low brake forceDefinition
setLowBrakeForce(float lowBrakeForceScale, float lowBrakeForceSpeedLimit)Arguments
float | lowBrakeForceScale | low brake force scale |
float | lowBrakeForceSpeedLimit | low brake force speed limit |
100 | function VehicleMotor:setLowBrakeForce(lowBrakeForceScale, lowBrakeForceSpeedLimit) |
101 | self.lowBrakeForceScale = lowBrakeForceScale; |
102 | self.lowBrakeForceSpeedLimit = lowBrakeForceSpeedLimit; |
103 | end; |
getMaxClutchTorque
DescriptionReturns max clutch torqueDefinition
getMaxClutchTorque()Return Values
float | maxClutchTorque | max clutch torque |
108 | function VehicleMotor:getMaxClutchTorque() |
109 | return self.maxClutchTorque; |
110 | end |
getRotInertia
DescriptionReturns rotation inertiaDefinition
getRotInertia()Return Values
float | rotInertia | rotation inertia |
115 | function VehicleMotor:getRotInertia() |
116 | return self.rotInertia; |
117 | end |
setRotInertia
DescriptionSets rotation inertiaDefinition
setRotInertia(float rotInertia)Arguments
float | rotInertia | rotation inertia |
122 | function VehicleMotor:setRotInertia(rotInertia) |
123 | self.rotInertia = rotInertia; |
124 | end |
getDampingRate
DescriptionReturns damping rateDefinition
getDampingRate()Return Values
float | dampingRate | damping rate |
129 | function VehicleMotor:getDampingRate() |
130 | return self.dampingRate; |
131 | end |
setDampingRate
DescriptionSets damping rateDefinition
setDampingRate(float dampingRate)Arguments
float | dampingRate | new damping rate |
136 | function VehicleMotor:setDampingRate(dampingRate) |
137 | self.dampingRate = dampingRate; |
138 | end |
getMaxTorque
DescriptionReturns max torqueDefinition
getMaxTorque()Return Values
float | maxMotorTorque | max motor torque |
143 | function VehicleMotor:getMaxTorque() |
144 | return self.maxMotorTorque; |
145 | end |
getBrakeForce
DescriptionReturns brake forceDefinition
getBrakeForce()Return Values
float | brakeForce | brake force |
150 | function VehicleMotor:getBrakeForce() |
151 | return self.brakeForce; |
152 | end |
getMinRpm
DescriptionReturns min rpmDefinition
getMinRpm()Return Values
integer | minRpm | min rpm |
157 | function VehicleMotor:getMinRpm() |
158 | return self.minRpm; |
159 | end |
getMaxRpm
DescriptionReturns max rpmDefinition
getMaxRpm()Return Values
integer | maxRpm | max rpm |
164 | function VehicleMotor:getMaxRpm() |
165 | return self.maxRpm; |
166 | end |
getLastMotorRpm
DescriptionReturns last motor rpm dampedDefinition
getLastMotorRpm()Return Values
integer | lastMotorRpm | last motor rpm |
171 | function VehicleMotor:getLastMotorRpm() |
172 | return self.lastMotorRpm; |
173 | end |
getLastRealMotorRpm
DescriptionReturns last motor rpm realDefinition
getLastRealMotorRpm()Return Values
integer | lastMotorRpm | last motor rpm |
178 | function VehicleMotor:getLastRealMotorRpm() |
179 | return self.lastRealMotorRpm; |
180 | end |
setLastRpm
DescriptionSets last motor rpmDefinition
setLastRpm(integer lastRpm)Arguments
integer | lastRpm | new last motor rpm |
185 | function VehicleMotor:setLastRpm(lastRpm) |
186 | self.lastRealMotorRpm = lastRpm; |
187 | |
188 | self.lastMotorRpm = self.lastMotorRpm * 0.95 + self.lastRealMotorRpm * 0.05; |
189 | end |
getMotorLoad
DescriptionReturns motor loadDefinition
getMotorLoad()Return Values
float | motorLoad | motor load |
194 | function VehicleMotor:getMotorLoad() |
195 | return self.motorLoad; |
196 | end |
getEqualizedMotorRpm
DescriptionReturns equalized motor rpmDefinition
getEqualizedMotorRpm()Return Values
integer | equalizedMotorRpm | equalized motor rpm |
201 | function VehicleMotor:getEqualizedMotorRpm() |
202 | return self.equalizedMotorRpm; |
203 | end |
setEqualizedMotorRpm
DescriptionSets equalized motor rpmDefinition
setEqualizedMotorRpm(integer equalizedMotorRpm)Arguments
integer | equalizedMotorRpm | equalized motor rpm |
208 | function VehicleMotor:setEqualizedMotorRpm(rpm) |
209 | self.equalizedMotorRpm = rpm; |
210 | self:setLastRpm(rpm); |
211 | end |
getPtoMotorRpmRatio
DescriptionReturns pto motor rpm ratioDefinition
getPtoMotorRpmRatio()Return Values
float | ptoMotorRpmRatio | pto motor rpm ratio |
216 | function VehicleMotor:getPtoMotorRpmRatio() |
217 | return self.ptoMotorRpmRatio; |
218 | end |
getNonClampedMotorRpm
DescriptionReturns non clamped motor rpmDefinition
getNonClampedMotorRpm()Return Values
integer | nonClampedMotorRpm | non clamped motor rpm |
223 | function VehicleMotor:getNonClampedMotorRpm() |
224 | return self.nonClampedMotorRpm; |
225 | end |
getClutchRpm
DescriptionReturns clutch rpmDefinition
getClutchRpm()Return Values
integer | clutchRpm | clutch rpm |
230 | function VehicleMotor:getClutchRpm() |
231 | return self.clutchRpm; |
232 | end |
getTorqueCurve
DescriptionReturns torque curveDefinition
getTorqueCurve()Return Values
table | torqueCurve | torque curve |
237 | function VehicleMotor:getTorqueCurve() |
238 | return self.torqueCurve; |
239 | end |
getTorque
DescriptionReturns torqueDefinition
getTorque(float acceleration, boolean limitRpm)Arguments
float | acceleration | acceleration |
boolean | limitRpm | limit rpm |
float | torque | torque |
float | brakePedal | brake pedal |
247 | function VehicleMotor:getTorque(acceleration, limitRpm) |
248 | -- Note: the torque curve is undefined outside the min/max rpm range. Clamping makes the curve flat at the outside range |
249 | local torque = self.torqueCurve:get(Utils.clamp(self.nonClampedMotorRpm, self.minRpm, self.maxRpm)); |
250 | local brakePedal = 0; |
251 | |
252 | if limitRpm then |
253 | local maxRpm = self:getCurMaxRpm(); |
254 | |
255 | local rpmFadeOutRange = self.rpmFadeOutRange*self:getGearRatio(); |
256 | |
257 | local fadeStartRpm = maxRpm - rpmFadeOutRange; |
258 | if self.nonClampedMotorRpm > fadeStartRpm then |
259 | if self.nonClampedMotorRpm > maxRpm then |
260 | brakePedal = math.min((self.nonClampedMotorRpm-maxRpm)/rpmFadeOutRange, 1); |
261 | torque = 0; |
262 | else |
263 | torque = torque * math.max((fadeStartRpm-self.nonClampedMotorRpm)/rpmFadeOutRange, 0); |
264 | end; |
265 | end; |
266 | end |
267 | torque = torque * math.abs(acceleration); |
268 | |
269 | local neededPtoTorque = PowerConsumer.getTotalConsumedPtoTorque(self.vehicle); |
270 | if neededPtoTorque > 0 then |
271 | torque = math.max(torque - neededPtoTorque/self.ptoMotorRpmRatio, torque*0.1); |
272 | end |
273 | |
274 | return torque, brakePedal; |
275 | end; |
getMaximumForwardSpeed
DescriptionReturns maximum forward speedDefinition
getMaximumForwardSpeed()Return Values
float | maxForwardSpeed | maximum forward speed |
280 | function VehicleMotor:getMaximumForwardSpeed() |
281 | return self.maxForwardSpeed; |
282 | end |
getMaximumBackwardSpeed
DescriptionReturns maximum backward speedDefinition
getMaximumBackwardSpeed()Return Values
float | maxBackwardSpeed | maximum backward speed |
287 | function VehicleMotor:getMaximumBackwardSpeed() |
288 | return self.maxBackwardSpeed; |
289 | end |
calculatePhysicalMaximumForwardSpeed
DescriptionReturns physical maximum forward speedDefinition
calculatePhysicalMaximumForwardSpeed()Return Values
float | physicalMaxForwardSpeed | physical maximum forward speed |
294 | function VehicleMotor:calculatePhysicalMaximumForwardSpeed() |
295 | return VehicleMotor.calculatePhysicalMaximumSpeed(self.minForwardGearRatio, self.forwardGearRatios, self.maxRpm) |
296 | end |
calculatePhysicalMaximumBackwardSpeed
DescriptionReturns physical maximum backward speedDefinition
calculatePhysicalMaximumBackwardSpeed()Return Values
float | physicalMaxBackwardSpeed | physical maximum backward speed |
301 | function VehicleMotor:calculatePhysicalMaximumBackwardSpeed() |
302 | return VehicleMotor.calculatePhysicalMaximumSpeed(self.minBackwardGearRatio, self.backwardGearRatios, self.maxRpm) |
303 | end |
calculatePhysicalMaximumSpeed
DescriptionReturns physical maximum speedDefinition
calculatePhysicalMaximumSpeed(float minGearRatio, table gearRatios, integer maxRpm)Arguments
float | minGearRatio | min gear ratio |
table | gearRatios | gear ratios |
integer | maxRpm | max rpm |
float | physicalMaxSpeed | physical maximum speed |
311 | function VehicleMotor.calculatePhysicalMaximumSpeed(minGearRatio, gearRatios, maxRpm) |
312 | local minRatio; |
313 | if minGearRatio ~= nil then |
314 | minRatio = minGearRatio |
315 | else |
316 | minRatio = math.huge; |
317 | for _, ratio in pairs(gearRatios) do |
318 | minRatio = math.min(minRatio, ratio); |
319 | end |
320 | end |
321 | return maxRpm * math.pi / (30 * minRatio); |
322 | end |
updateMotorRpm
DescriptionUpdate motor rpmDefinition
updateMotorRpm(float dt)Arguments
float | dt | time since last call in ms |
327 | function VehicleMotor:updateMotorRpm(dt) |
328 | local vehicle = self.vehicle; |
329 | if next(vehicle.differentials) ~= nil and vehicle.motorizedNode ~= nil then |
330 | self.nonClampedMotorRpm, self.clutchRpm, self.motorLoad = getMotorRotationSpeed(vehicle.motorizedNode) |
331 | self.nonClampedMotorRpm = self.nonClampedMotorRpm * 30 / math.pi; |
332 | self.clutchRpm = self.clutchRpm * 30 / math.pi; |
333 | |
334 | self.requiredMotorPower = math.huge; |
335 | |
336 | else |
337 | local gearRatio = self:getGearRatio(); |
338 | if vehicle.isServer then |
339 | self.nonClampedMotorRpm = math.max(WheelsUtil.computeRpmFromWheels(vehicle) * gearRatio, 0); |
340 | else |
341 | self.nonClampedMotorRpm = math.max(WheelsUtil.computeRpmFromSpeed(vehicle) * gearRatio, 0); |
342 | end |
343 | self.clutchRpm = self.nonClampedMotorRpm; |
344 | end |
345 | self:setLastRpm(math.max(self.nonClampedMotorRpm, self.minRpm)); |
346 | |
347 | -- the clamped motor rpm always is higher-equal than the required rpm by the pto |
348 | --local ptoRpm = math.min(PowerConsumer.getMaxPtoRpm(self.vehicle)*self.ptoMotorRpmRatio, self.maxRpm); |
349 | -- smoothing for raise/fall of ptoRpm |
350 | if self.lastPtoRpm == nil then |
351 | self.lastPtoRpm = self.minRpm; |
352 | end; |
353 | local ptoRpm = PowerConsumer.getMaxPtoRpm(self.vehicle)*self.ptoMotorRpmRatio; |
354 | if ptoRpm > self.lastPtoRpm then |
355 | self.lastPtoRpm = math.min(ptoRpm, self.lastPtoRpm + self.maxRpm*dt/2000); |
356 | elseif ptoRpm < self.lastPtoRpm then |
357 | self.lastPtoRpm = math.max(self.minRpm, self.lastPtoRpm - self.maxRpm*dt/1000); |
358 | end; |
359 | local ptoRpm = math.min(self.lastPtoRpm, self.maxRpm); |
360 | self:setLastRpm(math.max(self.lastMotorRpm, ptoRpm)); |
361 | |
362 | self.equalizedMotorRpm = self.minRpm + ( (math.max(self.nonClampedMotorRpm, (self.lastPtoRpm-self.minRpm))/self.maxRpm) * (self.maxRpm-self.minRpm) ); |
363 | end; |
getBestGearRatio
DescriptionReturns best gear ratioDefinition
getBestGearRatio(float wheelSpeedRpm, float minRatio, float maxRatio, float accSafeMotorRpm, float requiredMotorPower, float requiredMotorRpm)Arguments
float | wheelSpeedRpm | wheel speed rpm |
float | minRatio | min ratio |
float | maxRatio | max ratio |
float | accSafeMotorRpm | acc save motor rpm |
float | requiredMotorPower | the required motor power [kW] (can be bigger than what the motor can actually achieve) |
float | requiredMotorRpm | fixed motor rpm to be used (if not 0) |
float | bestGearRatio | best gear ratio |
375 | function VehicleMotor:getBestGearRatio(wheelSpeedRpm, minRatio, maxRatio, accSafeMotorRpm, requiredMotorPower, requiredMotorRpm) |
376 | |
377 | if requiredMotorRpm ~= 0 then |
378 | local gearRatio = math.max(requiredMotorRpm-accSafeMotorRpm, requiredMotorRpm*0.8) / math.max(wheelSpeedRpm, 0.001); |
379 | gearRatio = Utils.clamp(gearRatio, minRatio, maxRatio); |
380 | return gearRatio; |
381 | end |
382 | |
383 | -- Use a minimum wheel rpm to avoid that gearRatio is ignored |
384 | wheelSpeedRpm = math.max(wheelSpeedRpm, 0.0001); |
385 | |
386 | local bestMotorPower = 0; |
387 | local bestGearRatio = minRatio; |
388 | --local bestRPM = 0; |
389 | -- TODO make this more efficient |
390 | for gearRatio = minRatio, maxRatio, 0.5 do |
391 | local motorRpm = wheelSpeedRpm * gearRatio; |
392 | if motorRpm > self.maxRpm - accSafeMotorRpm then |
393 | break; |
394 | end |
395 | local motorPower = self.torqueCurve:get(math.max(motorRpm, self.minRpm)) * motorRpm *math.pi/30; |
396 | if motorPower > bestMotorPower then |
397 | bestMotorPower = motorPower; |
398 | bestGearRatio = gearRatio; |
399 | --bestRPM = motorRpm; |
400 | end |
401 | |
402 | if motorPower >= requiredMotorPower then |
403 | break; |
404 | end |
405 | end |
406 | --print(string.format("Selected best gear: %f, %.2fkW rpm %.2f wheel %.2f", bestGearRatio, bestMotorPower, bestRPM, wheelSpeedRpm,)); |
407 | |
408 | return bestGearRatio; |
409 | end |
getBestGear
DescriptionReturns best gearDefinition
getBestGear(float acceleration, float wheelSpeedRpm, float accSafeMotorRpm, float requiredMotorPower, float requiredMotorRpm)Arguments
float | acceleration | acceleration |
float | wheelSpeedRpm | wheel speed rpm |
float | accSafeMotorRpm | acc save motor rpm |
float | requiredMotorPower | required wheel torque |
float | requiredMotorRpm | required motor rpm |
float | bestGear | best gear |
float | gearRatio | gear ratio |
420 | function VehicleMotor:getBestGear(acceleration, wheelSpeedRpm, accSafeMotorRpm, requiredMotorPower, requiredMotorRpm) |
421 | if math.abs(acceleration) < 0.001 then |
422 | acceleration = 1; |
423 | if wheelSpeedRpm < 0 then |
424 | acceleration = -1; |
425 | end |
426 | end |
427 | if acceleration > 0 then |
428 | if self.minForwardGearRatio ~= nil then |
429 | local wheelSpeedRpm = math.max(wheelSpeedRpm, 0); |
430 | local bestGearRatio = self:getBestGearRatio(wheelSpeedRpm, self.minForwardGearRatio, self.maxForwardGearRatio, accSafeMotorRpm, requiredMotorPower, requiredMotorRpm); |
431 | return 1, bestGearRatio; |
432 | else |
433 | return 1, self.forwardGearRatios[1]; |
434 | end |
435 | else |
436 | if self.minBackwardGearRatio ~= nil then |
437 | local wheelSpeedRpm = math.max(-wheelSpeedRpm, 0) |
438 | local bestGearRatio = self:getBestGearRatio(wheelSpeedRpm, self.minBackwardGearRatio, self.maxBackwardGearRatio, accSafeMotorRpm, requiredMotorPower, requiredMotorRpm); |
439 | return -1, -bestGearRatio; |
440 | else |
441 | return -1, -self.backwardGearRatios[1]; |
442 | end |
443 | end |
444 | end |
updateGear
DescriptionUpdate gearDefinition
updateGear(float acceleration)Arguments
float | acceleration | acceleration |
449 | function VehicleMotor:updateGear(acceleration, dt) |
450 | local requiredMotorPower = math.huge; |
451 | if (acceleration >= 0) == (self.gearRatio >= 0) then |
452 | requiredMotorPower = self.requiredMotorPower; |
453 | end |
454 | local requiredMotorRpm = PowerConsumer.getMaxPtoRpm(self.vehicle)*self.ptoMotorRpmRatio; |
455 | -- 1) safe rpm for acceleration is 10% of the motor max rpm, so it will take at least 10 frames (=0.16s) until a vehicle has fully accelerated |
456 | -- 2) replaced lastSpeedReal with clutchRPM/gearRatio => better acceleration when using high values for differentials and steeringAngle is at max/min |
457 | local wheelSpeedRpm; |
458 | if math.abs(self.gearRatio) < 0.001 then |
459 | wheelSpeedRpm = self.vehicle.lastSpeedReal*self.vehicle.movingDirection * 30000/ math.pi; |
460 | else |
461 | wheelSpeedRpm = (self.clutchRpm/self.gearRatio); |
462 | end |
463 | self.gear, self.gearRatio = self:getBestGear(acceleration, wheelSpeedRpm, self.maxRpm*0.1, requiredMotorPower, requiredMotorRpm); |
464 | |
465 | if acceleration >= 0 then |
466 | self.speedLimitAcc = self.maxForwardSpeed * 3.6 * acceleration; |
467 | else |
468 | self.speedLimitAcc = -self.maxBackwardSpeed * 3.6 * acceleration; |
469 | end |
470 | end |
getGearRatio
DescriptionReturns gear ratioDefinition
getGearRatio()Return Values
float | gearRatio | gear ratio |
475 | function VehicleMotor:getGearRatio() |
476 | return self.gearRatio; |
477 | end; |
getCurMaxRpm
DescriptionReturns current max rpmDefinition
getCurMaxRpm()Return Values
integer | maxRpm | current max rpm |
482 | function VehicleMotor:getCurMaxRpm() |
483 | local maxRpm = self.maxRpm; |
484 | |
485 | local gearRatio = self:getGearRatio(); |
486 | if gearRatio ~= 0 then |
487 | --local speedLimit = self.speedLimit * 0.277778; |
488 | local speedLimit = math.min(self.speedLimit, math.max(self.speedLimitAcc, self.vehicle.lastSpeedReal*3600)) * 0.277778; |
489 | if gearRatio > 0 then |
490 | speedLimit = math.min(speedLimit, self.maxForwardSpeed); |
491 | else |
492 | speedLimit = math.min(speedLimit, self.maxBackwardSpeed); |
493 | end |
494 | |
495 | maxRpm = math.min(maxRpm, speedLimit * 30 / math.pi * math.abs(gearRatio)); |
496 | end |
497 | |
498 | maxRpm = math.min(maxRpm, self.rpmLimit); |
499 | return maxRpm; |
500 | end; |
setSpeedLimit
DescriptionSets speed limitDefinition
setSpeedLimit(float limit)Arguments
float | limit | new limit |
505 | function VehicleMotor:setSpeedLimit(limit) |
506 | self.speedLimit = math.max(limit, self.minSpeed); |
507 | end |
setRpmLimit
DescriptionSets rpm limitDefinition
setRpmLimit(float limit)Arguments
float | limit | new limit |
512 | function VehicleMotor:setRpmLimit(rpmLimit) |
513 | self.rpmLimit = rpmLimit; |
514 | end; |