[ODE] Finding Force to reach desired speed(Urgent!!)

c2sode@gmail.com c2sode at gmail.com
Wed Apr 19 08:22:54 MST 2006


hi all,
I need to set my vehicle's speed to a desired value in one world step. As
far as I understand ı need to give force so that the vehicle reaches that
speed in one world step, but ı don't know how to set this force. what is
this force. in my update function, ı'm changing speed as below. but how to
change the force? I will be very very very glad if anybody can help me.

{
    if (_world == 0 || _space == 0)
        return 0;

    // simulate drag/friction as a factor of speed
    dReal drag = 1.5 * _speed * PHYS_FORCE_SCALE;

    // motor
    _speed += _accel - drag;

    if (_speed < 0) _speed = 0;


    // The following determines the car's drive:
    //
    //        Drive        startWheel        endWheel
    //        ------------------------------------
    //        front            0                2
    //        rear            2                4
    //        4WD                0                4
    //
    int startWheel    = 2;
    int endWheel    = 4;


    dReal totalForce = _pCarData->power * PHYS_FORCE_SCALE;
    if (_accel < 0)
    {
        totalForce = 30; // TODO: put braking force in Car file
    }
    dReal force     = totalForce/(endWheel - startWheel); // force per wheel


    // apply force to wheels
    for(int i = startWheel; i != endWheel; ++i)
    {
        dJointSetHinge2Param (_joint[i], dParamVel2, - _gearMod * _speed);
        dJointSetHinge2Param (_joint[i], dParamFMax2, force);
    }

    // steering //

    // compute current wheel angle
    dReal langle = dJointGetHinge2Angle1 (_joint[0]);

    // compute velocity needed to bring wheel to desired angle
    dReal vl = (_steering * STEER_LIMIT_ANGLE) - langle;
    if (vl > 0.1) vl = 0.1;
    if (vl < -0.1) vl = -0.1;
    vl *= 10.0;

    dJointSetHinge2Param (_joint[0],dParamVel, vl);
    dJointSetHinge2Param (_joint[0],dParamFMax, 0.2);
    dJointSetHinge2Param (_joint[0],dParamLoStop, -STEER_LIMIT_ANGLE);
    dJointSetHinge2Param (_joint[0],dParamHiStop, STEER_LIMIT_ANGLE);
    dJointSetHinge2Param (_joint[0],dParamFudgeFactor, 0.1);


    dReal rangle = dJointGetHinge2Angle1 (_joint[1]);

    dReal vr = (_steering*STEER_LIMIT_ANGLE) - rangle;
    if (vr > 0.1) vr = 0.1;
    if (vr < -0.1) vr = -0.1;
    vr *= 10.0;

    dJointSetHinge2Param (_joint[1],dParamVel, vr);
    dJointSetHinge2Param (_joint[1],dParamFMax, 0.2);
    dJointSetHinge2Param (_joint[1],dParamLoStop, -STEER_LIMIT_ANGLE);
    dJointSetHinge2Param (_joint[1],dParamHiStop, STEER_LIMIT_ANGLE);
    dJointSetHinge2Param (_joint[1],dParamFudgeFactor, 0.1);


    return _speed;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://q12.org/pipermail/ode/attachments/20060419/7c073f4a/attachment-0001.htm


More information about the ODE mailing list