Disabling momentum so that a body stops instantaneously

Official forum for the Chipmunk2D Physics Library.

Disabling momentum so that a body stops instantaneously

Postby confused_chipmunk » Fri Jun 19, 2015 8:57 am

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!
confused_chipmunk
 
Posts: 2
Joined: Fri Jun 19, 2015 8:40 am

Re: Disabling momentum so that a body stops instantaneously

Postby zhanqixuan » Mon Jan 04, 2016 2:29 am

hey,man, I want to know this too.do u fix it?
zhanqixuan
 
Posts: 2
Joined: Mon Jan 04, 2016 2:15 am

Re: Disabling momentum so that a body stops instantaneously

Postby confused_chipmunk » Fri May 06, 2016 5:27 pm

No, sorry. I still have no idea whether this is even possible.
confused_chipmunk
 
Posts: 2
Joined: Fri Jun 19, 2015 8:40 am

Re: Disabling momentum so that a body stops instantaneously

Postby DrLeopoldStrabismus » Wed Aug 10, 2016 12:23 pm

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

Re: Disabling momentum so that a body stops instantaneously

Postby DrLeopoldStrabismus » Wed Aug 10, 2016 2:25 pm

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


Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 2 guests