bulletphysics / bullet3

Bullet Physics SDK: real-time collision detection and multi-physics simulation for VR, games, visual effects, robotics, machine learning etc.
http://bulletphysics.org
Other
12.44k stars 2.86k forks source link

Get body acceleration info #4043

Closed raincold23 closed 2 years ago

raincold23 commented 2 years ago

For the development of legged robots, it will be greatly helpful if the controller could get acceleration info the floating base from simulator. Is it possible for users to get a function like getBodyAcc(bodyID) to retrieve body acc info from simulation?

bttner commented 2 years ago

To my best knowledge, this is not possible. You need to keep track of the velocities and calculate the accelerations yourself, e.g., a(t) = (v(t) - v(t-1)) / dt, where v is the velocity and dt the sampling time (time step). The smaller your time step, the better the approximation. Note, however, that this is not the instantaneous acceleration and therefore not necessarily usable in controllers.

The instantaneous acceleration could be calculated via f = m * a, where f is the acting force, m the mass and a the acceleration. This formula is used in Gazebo (search for Link::WorldLinearAccel in linki). So, you would need to find out all acting forces on the desired link. But this information is only available for RigidBodies, i.e., https://github.com/bulletphysics/bullet3/blob/master/src/BulletDynamics/Dynamics/btRigidBody.h provides getTotalForce(). Featherstone Bodies do not have this option for some reason, at least I can not find it. Thus, at the moment you need to find out all acting forces yourself if you want the instantaneous acceleration.

raincold23 commented 2 years ago

Thanks so much for your reply.

I cannot find the getTotalForce() method in pybullet document. Is that only for c++?