Hi,
I'd like to model a simple gyroscope in Bullet, and observe precession. I've whipped up some code, but am having difficulties observing the correct behavior. (I've been looking at the gyroscope example in the SDK, but haven't identified the problem).
My current code creates a btCylinderShapeZ with a mass of 10, translates it along the z axis by +1 unit, and attaches a ball-joint hinge at the origin to it. I then call setAngularVelocity(0,0, 100) on the cylinder to induce rotation on the z-axis.
Gravity is set to -10 along the y axis. I used calculateLocalIntertia to generate and set the representation of the moment of interia for the cylinder.
When I run the program, I would expect to observe precession around the x and z axis. However, I observe the cylinder falling along the y-axis.
Can someone who is familiar with how to correctly code gyroscopes in bullet advise?
Thanks,
Will
Modelling a gyroscope in Bullet
Re: Modelling a gyroscope in Bullet
By falling do you mean rotating "down" so that +z oriented object is now oriented -y? If so, that sounds correct for "low" angular velocity, with the object precession occurring about -y. Simply making gravity be on the -z axis should make it work as you want.
Re: Modelling a gyroscope in Bullet
Thanks for your reply Basroil:
Instead, it tends to fall down (-y). I do observe some precession in the -z, +x direction, but I must be doing something wrong. Here is the relevant code:
Not quite - I was hoping that the cylinder would just precess around the y axis, without much rotatation around the other two axis (similar to the diagram below, assuming "up" is +y, and the gyroscope is currently aligned along the +z axis):Basroil wrote:By falling do you mean rotating "down" so that +z oriented object is now oriented -y? If so, that sounds correct for "low" angular velocity, with the object precession occurring about -y. Simply making gravity be on the -z axis should make it work as you want.
Instead, it tends to fall down (-y). I do observe some precession in the -z, +x direction, but I must be doing something wrong. Here is the relevant code:
Code: Select all
btCollisionShape* colShape = new btCylinderShapeZ(btVector3(1, 1, 1));
int gyro_length = 100;
btTransform startTransform;
startTransform.setIdentity();
startTransform.setOrigin(btVector3(0,0,gyro_length));
btScalar mass(10.f);
btVector3 localInertia(0,0,0);
colShape->calculateLocalInertia(mass,localInertia);
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,colShape,localInertia);
btRigidBody* body = new btRigidBody(rbInfo);
body->setFlags(BT_ENABLE_GYROSCOPIC_FORCE_EXPLICIT);
body->setAngularVelocity(btVector3(0, 0, 2000));
//pivot point
btVector3 pivot(0,0, gyro_length);
btTypedConstraint* p2p = new btPoint2PointConstraint(*body, pivot);
dynamicsWorld->addRigidBody(body);
dynamicsWorld->addConstraint(p2p);
Re: Modelling a gyroscope in Bullet
I think i might know what is going on...
It looks like perhaps the simulation is almost working correctly - The initial drop in Y induces nutation into the precession of the gyroscope, and so the cylinder precesses (slowly), while oscillating along the Y.
The only issue now is that as the gyro precesses, it it is climbing the y-axis, which is violating cons. of energy. I imagine if I can introduce some kind of friction to the btPoint2PointConstraint, it will behave appropriately.
My code is pretty dirty...but if anyone is interested is seeing the gyroscopic precession and nutation, I've attached the modified GyroscopicSetup.cpp to this post. Just substitute it for the matching file in the SDK and run the Gyroscope demo from the example browser. If there is enough interest I can tidy it up for use in the examples.
It looks like perhaps the simulation is almost working correctly - The initial drop in Y induces nutation into the precession of the gyroscope, and so the cylinder precesses (slowly), while oscillating along the Y.
The only issue now is that as the gyro precesses, it it is climbing the y-axis, which is violating cons. of energy. I imagine if I can introduce some kind of friction to the btPoint2PointConstraint, it will behave appropriately.
My code is pretty dirty...but if anyone is interested is seeing the gyroscopic precession and nutation, I've attached the modified GyroscopicSetup.cpp to this post. Just substitute it for the matching file in the SDK and run the Gyroscope demo from the example browser. If there is enough interest I can tidy it up for use in the examples.
- Attachments
-
- GyroscopicSetup.cpp
- Modified gyroscope demo code to show a gyroscope precession and nutation.
- (3.92 KiB) Downloaded 422 times
Re: Modelling a gyroscope in Bullet
Are you simulating it with time steps on the order of 1000Hz or better? 20000RPM certainly isn't in the "low" angular velocity category (so it won't fall down except in very special cases), but it's also well above what bullet can handle in it's default parameters. I can certainly see the climb happening as a side effect of the joint correction. Perhaps using a different solver might help too.
-
- Posts: 84
- Joined: Sun Jan 07, 2007 4:29 pm
- Location: Oxford, England
- Contact:
Re: Modelling a gyroscope in Bullet
I don't have the SDK here to check the details, but don't use BT_ENABLE_GYROSCOPIC_FORCE_EXPLICIT as this will require a very small timestep to be accurate - use one of the implicit options.
Re: Modelling a gyroscope in Bullet
Implicit gyroscopic is actually new to the 2.84 builds, I didn't even realize the system had changed until a few days ago when I was looking though the change logs It's certainly possible wmacaluso had an older build too.DannyChapman wrote:I don't have the SDK here to check the details, but don't use BT_ENABLE_GYROSCOPIC_FORCE_EXPLICIT as this will require a very small timestep to be accurate - use one of the implicit options.
Re: Modelling a gyroscope in Bullet
Thanks DannyChapman, I will try the implicit flags instead.