Multibody strange behaviour when apply force

Post Reply
Todor
Posts: 1
Joined: Thu Dec 24, 2015 10:42 am

Multibody strange behaviour when apply force

Post by Todor »

I've implemented successfully quadcopter simulation using rigid body and constraints, it works perfect.

Now I'm trying to implement same but using multibody and I'm facing problems. When I apply ( add ) force to multibody base it starts to behave very strange. For simplicity multibody is constructed only from base without links and it is square with mass 1.

Below is code from InitPhysics function:

Code: Select all

btBoxShape *quadcopter_body_shape = new btBoxShape(btVector3(0.15, 0.15, 0.15));
btScalar quadcopter_base_mass(1); 
btVector3 quadcopter_local_inertia;
quadcopter_body_shape->calculateLocalInertia(quadcopter_base_mass, quadcopter_local_inertia);

bool fixed_base = false;
bool can_sleep = false;
bool multi_dof = true;
int base_body_link_index = -1;
m_quadcopter_body = new btMultiBody(0, quadcopter_base_mass, quadcopter_local_inertia, fixed_base, can_sleep, multi_dof);

m_quadcopter_body->finalizeMultiDof();
m_quadcopter_body->setLinearDamping(0.f);
m_quadcopter_body->setAngularDamping(0.f);

m_dynamicsWorld->addMultiBody(m_quadcopter_body);

btMultiBodyLinkCollider *base_colider = new btMultiBodyLinkCollider(m_quadcopter_body, -1);
base_colider->setCollisionShape(quadcopter_body_shape);
btTransform tmp_transform;
tmp_transform.setIdentity();
tmp_transform.setOrigin(btVector3(0, 0, 0));
base_colider->setWorldTransform(tmp_body_transform);
short filter_group = btBroadphaseProxy::AllFilter;
short filter_mask = btBroadphaseProxy::AllFilter;
m_dynamicsWorld->addCollisionObject(base_colider, filter_group, filter_mask);	
m_quadcopter_body->setBaseCollider(base_colider);
m_guiHelper->createCollisionObjectGraphicsObject(base_colider, btVector3(0.5, 0.5, 0.5));
And code from StepSimulation function

Code: Select all

m_quadcopter_body->addBaseForce(btVector3(0, 0, 7));
btQuaternion to_world_rot = m_quadcopter_body->getWorldToBaseRot();

if (m_dynamicsWorld)
{
	m_dynamicsWorld->stepSimulation(deltaTime);
}
As it is noticeable from the code above, I'm applying force with magnitude of 7, which is not enough for moving the body upward but somehow body reacts like I implement impulse on it, moves upward some distance rotating in same time and later it falls down. If I implement a force with magnitude greater than 9.81 body continue moving upward but with rotation and it looks like force is not applied in the center of mass.

I'm not sure am I doing something wrong or that happens because multibody is still in early phase and is working not stable. If someone is facing same problem or have idea how I can solve this will be great to hear.
zogokovo
Posts: 2
Joined: Tue Feb 02, 2016 1:30 pm

Re: Multibody strange behaviour when apply force

Post by zogokovo »

Post Reply