Physics Simulation Forum

 

All times are UTC




Post new topic Reply to topic  [ 73 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next
Author Message
 Post subject: Re: Vehicle demo
PostPosted: Wed Mar 02, 2011 9:34 am 
Offline

Joined: Fri Aug 01, 2008 6:36 am
Posts: 144
Location: Bonn, Germany
<...>


Last edited by mi076 on Sat Jul 16, 2011 11:24 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Vehicle demo
PostPosted: Wed Mar 02, 2011 11:04 am 
Offline

Joined: Sun Jan 30, 2011 8:46 pm
Posts: 64
Thanks proof, for the code .

@mi076
I was wondering if a torque can be applied on each of the wheels separately after I calculate it using the gear ratio.


Top
 Profile  
 
 Post subject: Re: Vehicle demo
PostPosted: Wed Mar 02, 2011 11:57 am 
Offline

Joined: Tue Mar 01, 2011 11:00 pm
Posts: 18
dumbo2007 wrote:
I was wondering if a torque can be applied on each of the wheels separately after I calculate it using the gear ratio.


You can, but I don't see the point of applying different torques to different wheels, if that's what you meant. It's something like:

Code:
vehicle->applyEngineForce(force, wheelIndex);


@mi076
Could you explain the math behind the camera? I was looking through the code but you're playing around with matrices too much so it's kinda too complicated for me, I just need the position/look at points :D


Top
 Profile  
 
 Post subject: Re: Vehicle demo
PostPosted: Thu Mar 03, 2011 2:11 am 
Offline

Joined: Sun Jan 30, 2011 8:46 pm
Posts: 64
@proof

Yeah you are right I dont. I was hoping to apply the torque only on the back wheels for a rear wheel drive and use the forward wheel for steering.

By the way the engine is always operated at a particular RPM range correct. The harder the user presses on the accelerator pedal the higher RPM. From Wikipedia I see that the RPM range is about 1000 to 3000 RPM :

http://en.wikipedia.org/wiki/Revolutions_per_minute

So I think I ll assume a linear increase in RPM for the moment based on how long a key is kept pressed. I will not be calculating RPM based on fuel input and engine structure etc. I ll simply apply the gear ratios you have suggested and see how the car behaves for starters.

The only term that I am not sure about is the base torque. How much can I assume it to be ? Is it based on the current engine RPM ?

The way I see it as of now, the calculation goes like this :
Calculate Engine RPM based on any amount of detail about the engine
Calculate the base torque from the current engine RPM
Apply current gear ratio to calculate the output torque
Apply the torque to the rear wheels using applyEngineForce()


Top
 Profile  
 
 Post subject: Re: Vehicle demo
PostPosted: Thu Mar 03, 2011 3:32 pm 
Offline

Joined: Tue Mar 01, 2011 11:00 pm
Posts: 18
Quote:
Automobile engines are usually operated at around 2500 rpm (41 Hz), with the minimum speed usually around 1000 rpm (16 Hz), and the redline at 6000-10,000 rpm (100–166 Hz).


BMW dashboard

I'm calculating the RPM currently by adding m_deltaRotation from all wheels, something like this:

Code:
wheelRot += wi.m_deltaRotation;
rpm = std::abs((int)(wheelRot / 2*Ogre::Math::PI * 600 * getCurrentGearRatio()));


It works ok because the more the wheels rotate, the higher rpm is and since you multiply it with the gear ratio, the rpm is always in range. The only problem I got is that for reverse gear, I have to multiply with 4000 instead of 600 because the reverse gear ratio is smaller, so I could get some decent rpm.

On the other side, I don't need a real rpm and gears simulation, because I'm not even going to show them to the end user because it would just clutter up the interface too much. I only need a fictional rpm and gear shifting for sounds :D

However, your approach does seem nice, except there's 1 problem. If the vehicle is steering and accelerating, it's not going to speed up much but you would still have linear rpm applied which would lead to being in 6th gear and going extremely slow. You need the velocity in your calculations.


Top
 Profile  
 
 Post subject: Re: Vehicle demo
PostPosted: Thu Mar 03, 2011 7:12 pm 
Offline

Joined: Sun Jan 30, 2011 8:46 pm
Posts: 64
Quote:
If the vehicle is steering and accelerating, it's not going to speed up much but you would still have linear rpm applied which would lead to being in 6th gear and going extremely slow. You need the velocity in your calculations.


Yeah see that is the thing. I will not be stepping up gears automatically based on the rpm. I will let the user decide that for the moment. For automatic transmission(I am not aware of how its done so please pardon any silly statements :) ) I guess the vehicle senses the current wheel RPM and steps up/down the gear. But it should take into account the engine RPM too I think.


So as I understand you are using the rotation of the wheels to calculate the rpm variable, and then use the rpm variable to calculate the gear.

But then how do you calculate the engine force value that you set using applyEngineForce() ?

In a previous post you mentioned that it can be calculated using currentGearRatio * baseTorque. But then how do you get the baseTorque ?

As I said I am planning to let the user set the gear - so manual transmission. Now the current engine RPM(not the current wheel RPM) is the primary input. Using this RPM I must somehow calculate the torque to be applied using applyEngineForce() . However currentGearRatio * baseTorque does not account for the engine RPM.

So I am guessing there is someway to determine the current engine torque from the current engine RPM ?


Top
 Profile  
 
 Post subject: Re: Vehicle demo
PostPosted: Thu Mar 03, 2011 8:50 pm 
Offline

Joined: Tue Mar 01, 2011 11:00 pm
Posts: 18
Well, I'm setting the baseTorque in my cars config file, and some cars are going to be slow, some are going to be fast. Yes, the torque stays the same for all RPM's for the current gear, but you can modify that to accommodate your needs by using linear interpolation. Here's a class you can use (ripped off from nvidia's sdk ^^):

Code:
#ifndef _LinearInterpolationValues_H_
#define _LinearInterpolationValues_H_

#include <map>

class LinearInterpolationValues
{
public:
    LinearInterpolationValues() : min(0), max(0), map() { }
    void clear() { map.clear(); }
    void insert(float index, float value)
    {
        if (map.empty())
            min = max = index;
        else
        {
            min = std::min(min, index);
            max = std::min(max, index);
        }

        map[index] = value;
    }

    float getValue(float number) const
    {
        constMapIterator lower = map.begin();
        if (number < min)
            return lower->second;

        constMapIterator upper = map.end();
        upper--;

        if (number > max)
            return upper->second;

        upper = map.lower_bound(number);
        if (upper == lower)
            return upper->second;

        lower = upper;
        lower--;

        float w1 = number - lower->first;
        float w2 = upper->first - number;
        return ((w2 * lower->second) + (w1 * upper->second)) / (w1 + w2);
    }

    float getValueAtIndex(unsigned int index)
    {
        constMapIterator it = map.begin();

        for (unsigned int i = 0; i < index; i++)
            ++it;
       
        return it->second;
    }

    unsigned int getSize() { return map.size(); }

protected:
    float min, max;
    std::map<float, float> map;

    typedef std::map<float, float>::iterator mapIterator;
    typedef std::map<float, float>::const_iterator constMapIterator;
};
#endif


What this will allow you to do, is set torque for some rpm ranges, like for example:
Code:
LinearInterpolationValues* torqueCurve = new LinearInterpolationValues();
torqueCurve->insert(1000, 300);
torqueCurve->insert(2000, 320);
torqueCurve->insert(3000, 340);
torqueCurve->insert(4000, 320);
torqueCurve->insert(5000, 300);

// when computing the torque to apply, you use this
float torqueToApply = currentGearRatio * torqueCurve->getValue(currentRpm);


What this class will allow you to do is interpolate between torque values - this allows you to apply more/less torque at different rpm values.


Top
 Profile  
 
 Post subject: Re: Vehicle demo
PostPosted: Fri Mar 04, 2011 11:55 pm 
Offline

Joined: Sun Jan 30, 2011 8:46 pm
Posts: 64
Thanks for the code. I think I ll go ahead and engage 1st gear now :) ...on to coding


Top
 Profile  
 
 Post subject: Re: Vehicle demo
PostPosted: Sat Mar 05, 2011 12:16 am 
Offline

Joined: Tue Mar 01, 2011 11:00 pm
Posts: 18
Also, what just came to mind, manual gear switching will probably be a little tricky because I haven't found a way to limit the speed of the car, so for the reverse gear I set chassis linear damping to 0.3f so it gets limited a little but that's just a hackfix imo :/


Top
 Profile  
 
 Post subject: Re: Vehicle demo
PostPosted: Sat Mar 05, 2011 1:44 pm 
Offline

Joined: Fri Aug 01, 2008 6:36 am
Posts: 144
Location: Bonn, Germany
<...>


Last edited by mi076 on Sat Jul 16, 2011 11:25 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Vehicle demo
PostPosted: Sat Mar 05, 2011 2:08 pm 
Offline

Joined: Tue Mar 01, 2011 11:00 pm
Posts: 18
I'm applying linear damping to the chassis when the vehicle isn't accelerating, which makes it lose speed over time to make it kinda "realistic". Without it, when you don't accelerate the vehicle keeps it speed for... forever :D


Top
 Profile  
 
 Post subject: Re: Vehicle demo
PostPosted: Sat Mar 05, 2011 3:04 pm 
Offline

Joined: Sun Jan 30, 2011 8:46 pm
Posts: 64
ok I think 4 forces contribute to the deceleration :
1. Rolling Friction
2. Distortion of the shape of the wheel at the area of contact
3. Air Flow around the vehicle
4. Internal friction of the parts transmitting power to the wheels

So for low speeds we neglect 3. 2 & 4 is taken care of by Linear Damping. But I thought 1 would be simulated by Bullet. So if the friction value of the ground and the wheels are made high enough then the vehicle should slow down. In fact the higher the weight of the vehicle the higher the friction.

So isnt this effect visible in btRayCastVehicle ? If there is no friction then how does the vehicle move at all ?

Recently I was trying to simulate a bike and I saw this strange thing too...somehow the wheels do roll but friction does not slow the bike. I ll try once more long enough maybe its just a matter of time.

Edit : In fact friction is the reason why gears are needed in the first place as starting the car from rest means overcoming the greater static friction(more torque less rpm) and then higher gears deal only with lesser rolling friction(less torque high rpm) with the total engine power (which should be torque*rpm) remaining the same.


Top
 Profile  
 
 Post subject: Re: Vehicle demo
PostPosted: Sat Mar 05, 2011 3:55 pm 
Offline

Joined: Fri Aug 01, 2008 6:36 am
Posts: 144
Location: Bonn, Germany
<...>


Last edited by mi076 on Sat Jul 16, 2011 11:20 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Vehicle demo
PostPosted: Mon Mar 07, 2011 1:25 am 
Offline

Joined: Tue Mar 01, 2011 11:00 pm
Posts: 18
I still don't like the raycast vehicle model :(

Might try to use joints to connect a car for GTA4 like behavior, has to be better.


Top
 Profile  
 
 Post subject: Re: Vehicle demo
PostPosted: Mon Mar 07, 2011 8:57 am 
Offline

Joined: Fri Aug 01, 2008 6:36 am
Posts: 144
Location: Bonn, Germany
<...>


Last edited by mi076 on Sat Jul 16, 2011 11:25 pm, edited 1 time in total.

Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 73 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group