Table Robot Legs Positions

Post Reply
ramroooma
Posts: 3
Joined: Thu Sep 01, 2016 8:30 pm

Table Robot Legs Positions

Post by ramroooma » Thu Sep 01, 2016 8:46 pm

Dear All,

Adding motors to my table shaped robot made me question the hinges functionality and the cylinders positions. So, I recorded the below 2 videos to share with you and get your feedback if we can attach the legs to the box to get a better looking and functioning table robot, because I think create cylinder function has some errors and I need your kind help to find these errors.


CreateBox function:

Code: Select all

void RagdollDemo::CreateBox(int index, double x, double y, double z, double length, double width, double height)
{
    geom[index] = new btBoxShape(btVector3(width, height, length));
    
    //btDefaultMotionState* motionstate = new btDefaultMotionState();
    btDefaultMotionState* motionstate = new btDefaultMotionState(btTransform(
                                                                             btQuaternion(0, 0, 0, 1),
                                                                             btVector3(x, y, z)
                                                                             ));
    
    btRigidBody::btRigidBodyConstructionInfo rigidBodyCI(
                                                         1.0,                  // mass, in kg. 0 -> Static object, will never move.
                                                         motionstate,
                                                         geom[index],  // collision shape of body
                                                         btVector3(0,0,0)    // local inertia
                                                         );
    
    body[index] = new btRigidBody(rigidBodyCI);
    
    m_dynamicsWorld->addRigidBody(body[index]);
    
}
CreateLegs function:

Code: Select all

void RagdollDemo::CreateCylinder(int index, double x, double y, double z, double diameter, double sideLength, double angle)
{
    geom[index] = new btCylinderShape(btVector3(diameter, sideLength, diameter));
    
    //btDefaultMotionState* motionstate = new btDefaultMotionState();
    btDefaultMotionState* motionstate = new btDefaultMotionState(btTransform(
                                                                             btQuaternion(btVector3(0, 0, 1), angle),
                                                                             btVector3(x, y, z)
                                                                             ));
    
    btRigidBody::btRigidBodyConstructionInfo rigidBodyCI(
                                                         1.0,                  // mass, in kg. 0 -> Static object, will never move.
                                                         motionstate,
                                                         geom[index],  // collision shape of body
                                                         btVector3(0,0,0.5)    // local inertia
                                                         );
    
//    glRotatef(90, 1, 0, 0);
    
    body[index] = new btRigidBody(rigidBodyCI);
    
    m_dynamicsWorld->addRigidBody(body[index]);
}


void RagdollDemo::CreateCylinder2(int index, double x, double y, double z, double diameter, double sideLength, double angle)
{
    geom[index] = new btCylinderShape(btVector3(diameter, sideLength, diameter));
    
    //btDefaultMotionState* motionstate = new btDefaultMotionState();
    btDefaultMotionState* motionstate = new btDefaultMotionState(btTransform(
                                                                             btQuaternion(btVector3(1, 0, 0), angle),
                                                                             btVector3(x, y, z)
                                                                             ));
    
    btRigidBody::btRigidBodyConstructionInfo rigidBodyCI(
                                                         1.0,                  // mass, in kg. 0 -> Static object, will never move.
                                                         motionstate,
                                                         geom[index],  // collision shape of body
                                                         btVector3(0.5,0,0)    // local inertia
                                                         );
    
    //glRotatef(90, 1, 0, 0);
    
    body[index] = new btRigidBody(rigidBodyCI);
    
    m_dynamicsWorld->addRigidBody(body[index]);
}

CreateHinge function:

Code: Select all

void RagdollDemo::CreateHinge(int index, int body1, int body2, double x, double y, double z, double ax, double ay, double az)
{
    btVector3 p(x, y, z);
    btVector3 a(ax, ay, az);
    
    btVector3 p1 = PointWorldToLocal(body1, p);
    btVector3 p2 = PointWorldToLocal(body2, p);
    
    btVector3 a1 = AxisWorldToLocal(body1, a);
    btVector3 a2 = AxisWorldToLocal(body2, a);
    
    // create
    joints[index] = new btHingeConstraint(*body[body1], *body[body2],
                                          p1, p2,
                                          a1, a2, false);
    
    // set limits
    joints[index]->setLimit( (-120. + 0.)*3.14159/180., (120. + 0.)*3.14159/180.);
    
    // Add to simulation
    m_dynamicsWorld->addConstraint( joints[index] , true );
    
Here are the calls to create the body parts (box and cylinders) and the hinges to connect them.

Code: Select all

CreateBox(0, 0., 2., 0., 1., 1., 0.2); // Create the box
    // Create the top legs
    CreateCylinder(1, 2., 1., 0., 0.2, 1., -0.6981317008); // Create Leg 1
    CreateCylinder(2, -2., 1., 0., 0.2, 1., 0.6981317008); // Create Leg 2
    CreateCylinder2(3, 0., 1., 2., 0.2, 1., 0.6981317008); // Create Leg 3
    CreateCylinder2(4, 0., 1., -2., 0.2, 1., -0.6981317008); // Create Leg 4
    // Create the bottom legs
    CreateCylinder(5, 3.5, 1., 0., 0.2, 1., 0.6981317008); // Create Leg 5
    CreateCylinder(6, -3.5, 1., 0., 0.2, 1., -0.6981317008); // Create Leg 6
    CreateCylinder2(7, 0., 1., 3.5, 0.2, 1., -0.6981317008); // Create Leg 7
    CreateCylinder2(8, 0., 1., -3.5, 0.2, 1., 0.6981317008); // Create Leg 8
    
    CreateHinge(0, 1,5, 2.7,1.8,0, 0,0,1);
    CreateHinge(1, 2,6, -2.7,1.8,0, 0,0,1);
    CreateHinge(2, 3,7, 0,1.8,2.7, 1,0,0);
    CreateHinge(3, 4,8, 0,1.8,-2.7, 1,0,0);
    
    CreateHinge(4, 0,1, 1.2,2,0, 0,0,1);
    CreateHinge(5, 0,2, -1.2,2,0, 0,0,1);
    CreateHinge(6, 0,3, 0,2,1.2, 1,0,0);
    CreateHinge(7, 0,4, 0,2,-1.2, 1,0,0);
Last edited by ramroooma on Sat Sep 03, 2016 7:57 pm, edited 1 time in total.

ramroooma
Posts: 3
Joined: Thu Sep 01, 2016 8:30 pm

Re: Table Robot Legs Positions

Post by ramroooma » Fri Sep 02, 2016 4:50 pm

Any help!!! Please!!!

benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland
Contact:

Re: Table Robot Legs Positions

Post by benelot » Sat Sep 03, 2016 1:52 pm

Hello ramrooma,

First of all, do not push your issue on the forum one day after you post it, give people som time to look at it and answer your question. That might take some days on average.

Regarding your issue, can you post your CreateHinge method? I believe that the issue is there and not in the creation of rigidbodies. It is easy to make mistakes in the setup of constraints which cause all sorts of "misbehavior".

ramroooma
Posts: 3
Joined: Thu Sep 01, 2016 8:30 pm

Re: Table Robot Legs Positions

Post by ramroooma » Tue Sep 20, 2016 4:35 pm

Sorry for being pushy!!! I will add CreateHinge code to the main post. Thanks!

DannyChapman
Posts: 85
Joined: Sun Jan 07, 2007 4:29 pm
Location: Oxford, England
Contact:

Re: Table Robot Legs Positions

Post by DannyChapman » Wed Sep 21, 2016 3:43 pm

Bullet uses an iterative solver, so the degree to which it converges depends on the timestep and the number of solver iterations. Decreasing the former and increasing the latter normally helps.

You could also look at the btMultiBody object, which implements a Featherstone solver. I'm not sure if that supports joint motors in Bullet 2.8x though - see here: http://bulletphysics.org/Bullet/phpBB3/ ... hp?t=10130

User avatar
Erwin Coumans
Site Admin
Posts: 4189
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Table Robot Legs Positions

Post by Erwin Coumans » Thu Oct 13, 2016 3:46 pm

Thanks Danny, it is indeed recommended to try using btMultiBody, it has joint limits and joint motors.

Also, make sure to update to most recent trunk or release version of Bullet (2.85 at this momemt), it has many improvements to btMultiBody.
See https://github.com/bulletphysics/bullet3/releases

There is pybullet and URDF/SDF file loading, which makes it much easier to prototype a btMultiBody, with Featherstone joints, limit and also motors.
The Example Browser can import URDF files as well, and so does the VR physics server.

Post Reply