Simulating a small vehicle, scaling, steering

Post Reply
age
Posts: 1
Joined: Thu Aug 29, 2013 12:08 pm

Simulating a small vehicle, scaling, steering

Post by age »

Hello!

I need to simulate a very small vehicle -- 16x25x10 cm with wheel radius of 2 cm. For that I use btRaycastVehicle. At first, I tried simulating without scaling anything, just by setting a very small simulation step and doing setConvexConvexMultipointIterations(3) for btCollisionConfiguration. That still yields unstable behavior, so I'm attempting to scale the world.

After a bit of experimentation things seem to work, the vehicle correctly falls on the track as I drop it and rolls forward, but I cannot get it to steer. Do I need to somehow scale the steering value too? Right now the simulation goes like this:

Code: Select all

    static constexpr btScalar SIMULATION_STEP = 0.001;
    static constexpr btScalar SCALING_FACTOR = 100.0;
...

Code: Select all

    static const btScalar speed_multiplier = -32 * SCALING_FACTOR * SCALING_FACTOR;

    m_vehicle->applyEngineForce(control[WheelSpeedL].toFloat() * speed_multiplier, 2);
    m_vehicle->applyEngineForce(control[WheelSpeedR].toFloat() * speed_multiplier, 3);
    m_vehicle->setBrake(0, 2);
    m_vehicle->setBrake(0, 3);
    m_vehicle->setSteeringValue(control[MovementAngle].toFloat(), 0);
    m_vehicle->setSteeringValue(control[MovementAngle].toFloat(), 1);

    for (int i = 0; i < m_vehicle->getNumWheels(); i++)
        m_vehicle->updateWheelTransform(i);
    m_world->stepSimulation(m_frame_duration, m_frame_duration / SIMULATION_STEP,
                            SIMULATION_STEP);
And the vehicle is created like this. Can

Code: Select all

    static btRaycastVehicle::btVehicleTuning tuning;

    const btScalar vw = 0.16 * SCALING_FACTOR; // 16cm width
    const btScalar vl = 0.25 * SCALING_FACTOR; // 25cm length
    const btScalar vh = 0.1 * SCALING_FACTOR; // 10cm height
    const btScalar wheel_dist = 0.025 * SCALING_FACTOR; // 2.5cm from chasis
    const btScalar wheel_radius = 0.02 * SCALING_FACTOR; // 2cm wheel radius
    const btScalar connection_height = -vh * 2;
    const btScalar mass = 1.27;

    btVector3 connection_point;
    btVector3 wheel_direction(0, 0, -1);
    btVector3 wheel_axis(1, 0, 0);

    btCollisionShape * s = new btBoxShape(btVector3(vw, vl, vh));
    btVector3 inertia;
    s->setMargin(0);
    s->calculateLocalInertia(mass, inertia);
    m_v_chasis = new btRigidBody(mass, new btDefaultMotionState, s, inertia);
    m_v_chasis->setActivationState(DISABLE_DEACTIVATION);
    m_world->addRigidBody(m_v_chasis);

    m_v_raycaster = new btDefaultVehicleRaycaster(m_world);
    m_vehicle = new btRaycastVehicle(tuning, m_v_chasis, m_v_raycaster);

    m_world->addVehicle(m_vehicle);
    m_vehicle->setCoordinateSystem(0, 2, 1);

    //front left
    connection_point = btVector3(-vw - wheel_dist, vl, connection_height);
    m_vehicle->addWheel(connection_point, wheel_direction, wheel_axis,
                        connection_height / 2, wheel_radius, tuning, true);

    //front right
    connection_point = btVector3(vw + wheel_dist, vl, connection_height);
    m_vehicle->addWheel(connection_point, wheel_direction, wheel_axis,
                        connection_height / 2, wheel_radius, tuning, true);


    //rear left
    connection_point = btVector3(-vw - wheel_dist, -vl, connection_height);
    m_vehicle->addWheel(connection_point, wheel_direction, wheel_axis,
                        connection_height / 2, wheel_radius, tuning, false);

    //rear right
    connection_point = btVector3(vw + wheel_dist, -vl, connection_height);
    m_vehicle->addWheel(connection_point, wheel_direction, wheel_axis,
                        connection_height / 2, wheel_radius, tuning, false);

    for (int i = 0; i < m_vehicle->getNumWheels(); i++)
    {
        btWheelInfo & wheel = m_vehicle->getWheelInfo(i);
        wheel.m_suspensionStiffness = 20.0;
        wheel.m_wheelsDampingRelaxation = 3;
        wheel.m_wheelsDampingCompression = 9;
        wheel.m_frictionSlip = 1000;
        wheel.m_rollInfluence = 0.1;
    }
Any advice on this task is very appreciated. Full source of simulation class: http://codepad.org/AXKHqlYx
DannyChapman
Posts: 84
Joined: Sun Jan 07, 2007 4:29 pm
Location: Oxford, England
Contact:

Re: Simulating a small vehicle, scaling, steering

Post by DannyChapman »

I'm not sure how relevant it is, but in my flight sim (http://rowlhouse.co.uk/PicaSim/)it's possible to scale the size of the planes (including scaling the mass appropriately), and separately scale the mass. The planes with undercarriages use the bullet raycast vehicle.

I found that the only way to work out what parameter is what, and what its units are - essential for scaling - is to work through the code (which is pretty ridiculous). In addition, one of the parameters doesn't scale with timestep, so I fixed it in the SDK.

I'll try to remember to look up my code and paste the relevant bits here...
Post Reply