How to make a spiral spring

sebateau22
Posts: 5
Joined: Sun May 22, 2011 6:09 pm

How to make a spiral spring

Post by sebateau22 »

Hi, I'm new in Bullet and I have to make a robot arm. For the elbow, we need to use a spring. Thus I guess that between the two parts of the arm I should use a spiral spring but how can i do that?

Regards
Sebastien

*EDIT*
When i say spiral spring, it could also be a torsion spring i guess
pwagner
Posts: 8
Joined: Tue Mar 29, 2011 11:31 am

Re: How to make a spiral spring

Post by pwagner »

Hey.

I'm also interested in a similar question and it's a pity no one can answer this. For me a simple spring would be enough and I already tried to implement it which you can see in the following code snippet:

Code: Select all

// Ball1 shape and body
ball1Shape = new btSphereShape(0.1);
ball1MotionState = new btDefaultMotionState(btTransform(btQuaternion(0., 0., 0., 1.), btVector3(0., 0., 0.)));
btScalar mass = 1;
btVector3 ball1Inertia(0., 0., 0.);
ball1Shape->calculateLocalInertia(mass, ball1Inertia);

btRigidBody::btRigidBodyConstructionInfo ball1ConstructionInfo(mass, ball1MotionState, ball1Shape, ball1Inertia);
ball1Body = new btRigidBody(ball1ConstructionInfo);
world->addRigidBody(ball1Body);
sensors.push_back(ball1Body);

// Ball2 shape and body
btScalar staticMass = 0.;
ball2Shape = new btSphereShape(0.1);
ball2MotionState = new btDefaultMotionState(btTransform(btQuaternion(0., 0., 0., 1.), btVector3(0., 2., 0.)));
btVector3 ball2Inertia(0., 0., 0.);
ball2Shape->calculateLocalInertia(staticMass, ball2Inertia);

btRigidBody::btRigidBodyConstructionInfo ball2ConstructionInfo(staticMass, ball2MotionState, ball2Shape, ball2Inertia);
ball2Body = new btRigidBody(ball2ConstructionInfo);
world->addRigidBody(ball2Body);

btTransform frameInA = btTransform::getIdentity();
frameInA.setOrigin(btVector3(0., 0., 0.));
btTransform frameInB = btTransform::getIdentity();
frameInB.setOrigin(btVector3(0., 0., 0.));
btScalar lo = 0.;
btScalar hi = 0.;
btScalar cfm = 1. / (1./500. * 500. + 0.5);
btScalar erp = (1./500. * 500.) / (1./500. * 500. + 0.5);

//cout << frameina.getorigin().x() << ", " << frameina.getorigin().y() << ", "<< frameina.getorigin().z() << endl;
//cout << frameinb.getorigin().x() << ", " << frameinb.getorigin().y() << ", "<< frameinb.getorigin().z() << endl;
//cout << "press enter to continue ...";
//cin.get();

//Spring
spring = new btGeneric6DofSpringConstraint(*ball1Body, *ball2Body, frameInA, frameInB, false);
size_t axis = 1; // Spring along y-axis
spring->enableSpring(axis, true);
spring->setStiffness(axis, 500);
spring->setDamping(axis, 0.1);
spring->setLinearLowerLimit(btVector3(0., lo, 3.));
spring->setLinearUpperLimit(btVector3(0., hi, 3.));
//spring->setParam(BT_6DOF_FLAGS_CFM_STOP, cfm, axis);
//spring->setParam(BT_6DOF_FLAGS_ERP_STOP, erp, axis);
spring->setEquilibriumPoint();
world->addConstraint(spring, true);
The code you see writes an output of position and velocity which I'm matching to the analytical solution. But both, velocity and position, behave very strange: The velocity has a spike of nearly 200 m/s with the first timestep and decreases rapidly to zero. The position of the first ball starts at (0, -2.5, 0) and increases rapidly to (0, -0.5, 0). The last position would be right if the spring realy expands to a length of 3 units but the starting position is completely wrong and there is no "spongyness" at all.

Maybe the code and description can help someone to come up with an answer to the question "How to make a (spiral) spring".

Thanks in advance.