Disabling momentum so that a body stops instantaneously

Official forum for the Chipmunk2D Physics Library.
Post Reply
confused_chipmunk
Posts: 2
Joined: Fri Jun 19, 2015 8:40 am
Contact:

Disabling momentum so that a body stops instantaneously

Post 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!
zhanqixuan
Posts: 2
Joined: Mon Jan 04, 2016 2:15 am
Contact:

Re: Disabling momentum so that a body stops instantaneously

Post by zhanqixuan »

hey,man, I want to know this too.do u fix it?
confused_chipmunk
Posts: 2
Joined: Fri Jun 19, 2015 8:40 am
Contact:

Re: Disabling momentum so that a body stops instantaneously

Post by confused_chipmunk »

No, sorry. I still have no idea whether this is even possible.
DrLeopoldStrabismus
Posts: 2
Joined: Wed Aug 10, 2016 12:20 pm
Contact:

Re: Disabling momentum so that a body stops instantaneously

Post 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.
DrLeopoldStrabismus
Posts: 2
Joined: Wed Aug 10, 2016 12:20 pm
Contact:

Re: Disabling momentum so that a body stops instantaneously

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests