Semi-realistic power curve engine

About advanced scenes, and the Thyme scripting language used in Algodoo.

Semi-realistic power curve engine

Postby Kilinich » Mon Jan 02, 2012 12:49 am

It's shipped with a lot of custom variables:

_accelRatio - acceleration pedal 0..1
_maxRPM - max engine possible RPM without any load and full accel
_idleRPM - engine speed on idle
_minRPM - minimum of possible RPM before stall
_maxTorque - maximum value of torque at _maxRPM/2
_maxEBTorque - maximum value of torque if engine brake happened (at _maxRPM withour acceleration)
_idleTorque - maximum value of torque on idle at _idleRPM/2

Power curve is approximated as parabola and as linear funcion on engine braking.
You can just copy that code and paste into hinge's script window.

Code: Select all
_accelRatio = 0.0;
_maxRPM = 300.0;
_idleRPM = 30.0;
_minRPM = 5.0;
_maxTorque = 100.0;
_maxEBTorque = 50.0;
_idleTorque = 10.0;
_torque = (x) =>{
    x2 := owner -> {_idleRPM + (_maxRPM - _idleRPM) * _accelRatio};
    x > x2 ? {
        owner._maxEBTorque * (x2 - x) / owner._maxRPM
    } : {
        x0 := owner._minRPM;
        x1 := (x0 + x2) / 2;
        y1 := owner -> {_idleTorque + (_maxTorque - _idleTorque) * _accelRatio};
        (y1) * (x - x0) * (x - x2) / (x1 - x0) / (x1 - x2)
    }
};
_rpm = {hinge := readable(owner);
    angvel := (readable(Scene.entityByGeomID(hinge.geom1))).angvel - (readable(Scene.entityByGeomID(hinge.geom0))).angvel;
    angvel * 9.5492966
};
motorTorque = {owner._torque(owner._rpm)};
autoBrake = {owner.motorTorque < 0};
motorSpeed = 52.359879;
motor = true;


Rating: rated 5.4
Filesize: 49 kB
Comments: 5
Ratings: 2
download
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 7 guests