Constraints for wheels

Post Reply
Zoomulator
Posts: 2
Joined: Thu Jul 19, 2012 7:21 pm

Constraints for wheels

Post by Zoomulator »

I'm pretty new to bullet and I'm trying to set up a little demo with a racing car. It's proving a lot more difficult than I expected. Using bullet-2.80-rev2531

I tried the hinge constraint first, since I figured it'd be the most straight forward to get working. I'm using two cylinders and a box at the moment to represent some kind of vehicle. It'll be four wheels eventually, but I can't even get two working.. If I add one wheel, the constraint works and falls into the right place. When I add the second wheel to the body however, it gets all wonky and the placement gets all wrong. And apart from that, the box's weight doesn't seem to affect the wheels at all, making for quite impressive acts of balance.

Trying the hinge constraint for some hours I finally gave up and went on to try out the Generic6DofConstraint. Surely again, the first constraint added works fine, but the second makes the system freak out. This time it even started moving making weird rotations so that it "walked" away.. and I'm pretty sure I didn't tell it to do that.

I tried adding only the second wheel and it behaves as it should on its own.. except for the balancing.

Is it just me that can't get this working or is the constraints just wonky? If what I've said here makes no sense I'd greatly appreciate if someone could whip up an example of some constraints that works for a car model.

On another matter, I've tried using applyTorque on a few bodies too, with no affect. I've disabled deactivation on the bodies (spheres) in question, but still wont budge by applying torque. Setting the angular velocity works as expected though and applying force from the center works too.
quzox
Posts: 7
Joined: Wed Aug 01, 2012 9:08 pm

Re: Constraints for wheels

Post by quzox »

Hiya I'm doing something similar.

First thing I got wrong was leaving the localInertia vector to zero for the tyre object (last parameter in the RigidBodyConstructionInfo constructor), which meant it couldn't spin. Just set it to all ones (for both tyre and chassis) and it'll behave as expected.

The HingeConstraint took awhile to get right. I'm using this constructor:

btHingeConstraint(btRigidBody& rbA,btRigidBody& rbB, const btVector3& pivotInA,const btVector3& pivotInB, const btVector3& axisInA,const btVector3& axisInB, bool useReferenceFrameA = false);

A is the chassis and B is the tyre. The pivot in A is the mount point for the tyre on the chassis, the pivot in B is just the centre of the tyre (i.e. zero vector). The axis in A should be equal to to the axis in B and point away from the car off to the side.

Note that you can't use a HingeConstraint for the front tyres because they're locked on the axis, making them impossible to steer. This is where I'm stuck at. I'm thinking a generic6DOF is the answer but not sure about the details. Will post here if I make further progress.
quzox
Posts: 7
Joined: Wed Aug 01, 2012 9:08 pm

Re: Constraints for wheels

Post by quzox »

Managed to fix the front tyre issue. It's possible to use a Generic6DOF for the front tyres, just lock all 3 linear axes and all angular axes except for the x-axis (because it needs to spin around the x-axis). Then set your upper and lower limits for the y-axis to be equal to the current steering angle. When setting the btTransform object just initialise it to identity and then set the origin to be the tyre mounting point on the chassis.
Also make sure that when adding the constraint to the world that you've disabled collisions between the 2 rigid bodies, otherwise the tyre will bump into the chassis (unless it doesn't, it depends on your wheel arch geometry).

HTH.

For what it's worth the slip between the tyre and the road is way too high, it feels like I'm steering a truck on ice. I suspect a custom friction model for the tyres and the ground will be needed, although not sure where to begin looking.
Zoomulator
Posts: 2
Joined: Thu Jul 19, 2012 7:21 pm

Re: Constraints for wheels

Post by Zoomulator »

Thanks a quzox!
That was way too simple.. I hate things that are painfully obvious in hindsight =D

Setting the right inertia instantly made all the difference. Seems odd to have zero inertia as default..
I'm still gonna try out the 6dof constraints a bit more, but they seem sensible enough to use.

With the slippy tires, maybe you've got too much torque compared to the weight of the "car"? I'll be looking into it a bit the coming days.
monkeyman
Posts: 22
Joined: Sat Nov 26, 2011 5:41 pm

Re: Constraints for wheels

Post by monkeyman »

In your opinion is it possible at all to simulate a vehicle using actual turning cylinders as wheels in Bullet?

I thought most people doing vehicle simulations did a hack when modelling wheels, so they seem to spin by the renderer, but in the physics engine they are just collision-detection cylinders and the rubber vs. road friction is modelled using manually inserted forces etc.
quzox
Posts: 7
Joined: Wed Aug 01, 2012 9:08 pm

Re: Constraints for wheels

Post by quzox »

Hi monkeyman,

I think it's still possible although I may have to start toying around with the tyre contact model and giving it special consideration. The frictional force should be proportional to the force along the contact normal (and then bounded at some point) which I'm not sure if Bullet is doing by default. Tbh, I don't really understand how Bullet works under the hood, a project Gauss-Siedel solver sounds like alien technology from another dimension. :oops:

So it's a lot harder than I thought it would be. My current problem is getting the brakes smoothly applied. I'm using the rotational motor on the front tyre's connecting constraint (6dof) but I can only set the target velocity. Measuring the current velocity and then "taking a bit off" to set the target vel seems to just bring the tyre to a complete halt, causing a skid. Although some parameter fine tuning might solve this.

I have tried using the applyTorque() functions on the tyres but it was epic fail... :cry:
quzox
Posts: 7
Joined: Wed Aug 01, 2012 9:08 pm

Re: Constraints for wheels

Post by quzox »

Zoomulator wrote:Thanks a quzox!
With the slippy tires, maybe you've got too much torque compared to the weight of the "car"?
Very likely, although I've grown used to it now. It's kinda fun too. :D
Post Reply