Page 1 of 1

Disabling momentum so that a body stops instantaneously

Posted: Fri Jun 19, 2015 8:57 am
by confused_chipmunk
Hi everyone,

I'm working with a robot simulator called ARGoS https://github.com/ilpincy/argos3, which uses Chipmunk2D Physics. Given a two-wheeled robot, I can set the velocities of each wheel, and the simulator will calculate the linear and angular velocities of the body that represents the robot.

If a robot is moving in a straight line at a constant speed, and I suddenly set the wheel speeds to zero, the robot does not come to an immediate stop. It takes one or two updates of the physics engine for the robot to come to a complete stop, because the body has inertia.

Is there any way to disable the momentum of a body, such that it has no inertia and therefore stops instantaneously?

Thanks!

Re: Disabling momentum so that a body stops instantaneously

Posted: Mon Jan 04, 2016 2:29 am
by zhanqixuan
hey,man, I want to know this too.do u fix it?

Re: Disabling momentum so that a body stops instantaneously

Posted: Fri May 06, 2016 5:27 pm
by confused_chipmunk
No, sorry. I still have no idea whether this is even possible.

Re: Disabling momentum so that a body stops instantaneously

Posted: Wed Aug 10, 2016 12:23 pm
by DrLeopoldStrabismus
I'm also working on Argos :)

What happens if you make a custom dynamics2d_footbot_model, but modify this line in the constructor:

m_fMass(1.6f)

to

m_fMass(0.0f)

Curious if this will give you any divide-by-0 errors.

Re: Disabling momentum so that a body stops instantaneously

Posted: Wed Aug 10, 2016 2:25 pm
by DrLeopoldStrabismus
Okay, disregard my previous post. Setting the mass to 0.0f will cause a divide-by-zero when you initialize the body (cpBodyInit) since it calls cpBodySetMass:

Code: Select all

cpBodySetMass(cpBody *body, cpFloat mass)
{
  cpBodyActivate(body);
  body->m = mass;
  body->m_inv = 1.0f/mass;
}
The ARGoS simulation I'm dealing with just uses the default foot-bot and the 2d physics engine (dynamics2d_velocity_control.cpp) which directly modifies the cpBody velocity (CDynamics2DVelocityControll::SetLinearVelocity). It appears that I don't have to deal with inertia. Can you modify your simulation to use the dynamics2d engine?

Alternatively, if you're using a physics engine that applies a force to the body, you can set a CUSTOM velocity update function using:

cpBody->velocity_func = <your function here>;

The default velocity_func is cpBodyUpdateVelocity. If you take a look in the source code, you'll see it calculates an acceleration from applied force and m_inv.