Gears simulation with Bullet

Tantor
Posts: 11
Joined: Wed Jun 09, 2010 12:24 am

Gears simulation with Bullet

Post by Tantor »

Hi! I have done a search, but could not find infos about how to compute gears with bullet (though the api or the blender interface...). I wonder even if it is possible. Any help is welcome! I'd like to simulate a car differential. Thanx in advance
NaN
Posts: 9
Joined: Thu Mar 04, 2010 6:55 pm

Re: Gears simulation with Bullet

Post by NaN »

Hi, you will have to write your own code. Bullet has a simple demo vehicle, but it is not a vehicle dynamics simulation library.
Tantor
Posts: 11
Joined: Wed Jun 09, 2010 12:24 am

Re: Gears simulation with Bullet

Post by Tantor »

thank you very much. I'll see what I can do. It sure will be great when Bullet can deal with gears. I think it can be done by computing constraints on rotation angles of links joined by a gear (the two angles would have a constant ratio...). I will keep you informed
bone
Posts: 231
Joined: Tue Feb 20, 2007 4:56 pm

Re: Gears simulation with Bullet

Post by bone »

A couple of words of advice ...

Simulating a differential is a bit difficult. Doing it with only bilateral constraints (meaning constraints that act on only 2 bodies) is even more difficult, as you'll have to simulate the internals like the planet and ring gears. And presuming some amount of accuracy is desired, there are going to be significant mass ratios so an iterative solver might not be good enough.
Tantor
Posts: 11
Joined: Wed Jun 09, 2010 12:24 am

Re: Gears simulation with Bullet

Post by Tantor »

yes I've figured out it would not be easy... but at least, I'd like to succeed in simulating just a simple gear... more complex stuff later... my dynamics formulation does not use generalized coordinates (i.e. joint coordinates), but cartesian coordinates (translation vectors and rotations matrices) for body spacial configuration mapping. I am having trouble to compute the gear constraint, which is expressed as a function of the angles of the 2 bodies that make the gear (the formulation I use does not use such angles)... and the arcos(x) function is nasty, not differentiable at x = 1... maybe the gear constraint should be compited in terms of the angular velocity vectors...
bone
Posts: 231
Joined: Tue Feb 20, 2007 4:56 pm

Re: Gears simulation with Bullet

Post by bone »

Tantor wrote:... maybe the gear constraint should be computed in terms of the angular velocity vectors...
Yup.
Tantor
Posts: 11
Joined: Wed Jun 09, 2010 12:24 am

Re: Gears simulation with Bullet

Post by Tantor »

Thanx for the tip! I am now trying to code the gear constraint, which seems to be nonholonomic. The constraint is simple, it's just the proportionnality between the angular velocity vectors of the two bodies linked by the gear. These vectors are simply the product of the derivate of the rotation matrix and the transposed of the rotation matrix. So far, it's ok for me. My dynamics simulation program deals with only holonomic constraints so far, I wonder if the implemented constaint-solver algorithm is able to deal with nonholonomic constraints without modifications... it's quite worrysome... any hints are welcome, thanx!
Tantor
Posts: 11
Joined: Wed Jun 09, 2010 12:24 am

Re: Gears simulation with Bullet

Post by Tantor »

YES! I got it! It works! I have the nonholonomic constraint for a gear made up of two wheels, and my algorithms can take care of it. I must compute another kind of gear: one part is a wheel, the other is flat, thus transforming a rotation motion in a translation, and vice versa... I can try to compute the car differential too. thereafter I'll see how to get all this in Bullet code. :D
bone
Posts: 231
Joined: Tue Feb 20, 2007 4:56 pm

Re: Gears simulation with Bullet

Post by bone »

Tantor wrote:YES! I got it! It works! I have the nonholonomic constraint for a gear made up of two wheels, and my algorithms can take care of it. I must compute another kind of gear: one part is a wheel, the other is flat, thus transforming a rotation motion in a translation, and vice versa... I can try to compute the car differential too. thereafter I'll see how to get all this in Bullet code. :D
Like a rack and pinion? I haven't successfully done this one. Conceptually it seems straightforward, but defining where the contact is in relation to the two bodies isn't really that easy. Or it's not easy to keep it consistent in 3-D, IIRC (the radius of the wheel vs. the offset of the flat part). Good luck!
Tantor
Posts: 11
Joined: Wed Jun 09, 2010 12:24 am

Re: Gears simulation with Bullet

Post by Tantor »

it's getting interesting! yes, that's a rack and pinion I want to code also. what about having the rack slider-joined to a frame, and the pinion revolute-joined to the frame? both thus have one dof with respect to the frame. The gear constraint just computes the proportionnality of the relative velocity of the rack, with respect to the frame, and of the relative rotation velocity vector, with respect to the frame

about coding the pinion-pinion gear constraint, I realize that the rotation velocity vectors of the 2 pinions bodies must be expressed relative to a frame body... does it mean the constraint depends on 3 bodies?? that's funny, assuming that joint constraints usually depend on 1 or 2 bodies... It needs some more thinking
bone
Posts: 231
Joined: Tue Feb 20, 2007 4:56 pm

Re: Gears simulation with Bullet

Post by bone »

Tantor wrote:about coding the pinion-pinion gear constraint, I realize that the rotation velocity vectors of the 2 pinions bodies must be expressed relative to a frame body... does it mean the constraint depends on 3 bodies?? that's funny, assuming that joint constraints usually depend on 1 or 2 bodies... It needs some more thinking
Possibly, maybe that was my difficulty with the rack&pinion. I have a differential that is a quadrilateral constraint - 1 input shaft, 2 output shafts, but then you also need some sort of differential casing or something because there's an angular reaction that is otherwise unaccounted for.
Tantor
Posts: 11
Joined: Wed Jun 09, 2010 12:24 am

Re: Gears simulation with Bullet

Post by Tantor »

ouch! still stucked with problems about the pinion gear constraint, with the pinions joined to a free frame. The case where the frame is the ground is easy and works, but it's not enough! I'm going to express the constraint I use. W1, W2 are the instantaneous rotation vectors of the 2 pinion bodies and Wf is the one for the frame body. these vectors can be computed in terms of rotation matix as : W=j(dR/dt * trans(R))

my constraint equation is, in the case that the pinion axis are parallel, and pinion ration of k :

W2-Wf = k(W1-Wf)

The constraint is computable easily using my c++ classes. but it must be a wrong constraint, because the test simulation does not work!!
in this simulation, the frame is mounted to the ground with a simple ball joint, allowing the frame to rotate but not to fall.
the pinions are mounted to the frame with revolute joints.
at the begining of the simulation, the frame should be revolving downward, carrying the pinions, because of the weight
but on the simulation, the frame stands still!!! it seems that my gear constraint, which takes the frame body into account, simply does not allow the frame to rotate

arrrggg! it is still not clear why it is so... and I have no idea how to express the gear constraint differently...
Tantor
Posts: 11
Joined: Wed Jun 09, 2010 12:24 am

Re: Gears simulation with Bullet

Post by Tantor »

false alarm! the constraint equation detailled above is indeed correct. The problem came from a programming bug. Now let's simulate a car differential
Tantor
Posts: 11
Joined: Wed Jun 09, 2010 12:24 am

Re: Gears simulation with Bullet

Post by Tantor »

Hi bone

I have just computed the rack-pinion constraint (depending on a frame, not the ground), and it works fine. My differential works fine. with the rack-pinion we can simulate all the links making up a car steering... a whole vehicule simulation is on the way!
bone
Posts: 231
Joined: Tue Feb 20, 2007 4:56 pm

Re: Gears simulation with Bullet

Post by bone »

Sounds good, keep up the hard work!