[SOLVED in pybullet 2.8.2] Simple two-link URDF applyExternalForce unexpected response

Official Python bindings with a focus on reinforcement learning and robotics.
Post Reply
avikde
Posts: 3
Joined: Thu Jun 18, 2020 5:44 pm

[SOLVED in pybullet 2.8.2] Simple two-link URDF applyExternalForce unexpected response

Post by avikde »

I have created the smallest MWE I could that shows this behavior. There are just two revolute links and the second joint deflects in an unexpected direction under applyExternalForce. In the MWE, the slider applies a force in the direction of the applied red line to the most distal link in the chain.

https://gist.github.com/avikde/89a85fcc ... 563b1a824c

This may be an error in my URDF or my usage of pybullet; any help would be appreciated!
Last edited by avikde on Fri Jun 19, 2020 5:21 pm, edited 1 time in total.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Simple two-link URDF applyExternalForce unexpected response

Post by Erwin Coumans »

Thanks Avik,

I had a look and found a few issues. One of them is in the applyExternalForce imlpementation, I fixed this now.
https://github.com/bulletphysics/bullet ... 396dd3718a

(it was a copy/paste bug, we never used applyExternalForce, since we always actuate our robots using actuators/motors)

In your code:
1) disable position/velocity motors before applying an external torque/force
2) use a reasonably timestep, 1 is not OK. Use 1./240 or at largest 1./60.
3) always provide collision shapes in the URDF, since PyBullet derives the inertia tensor from mass and collision volume by default

It is also easier to debug when the force is applied around the link world center-of-mass location.
See attached zip file for my updates.
Thanks for the report!
Attachments
avik_examples.zip
(1.4 KiB) Downloaded 484 times
avikde
Posts: 3
Joined: Thu Jun 18, 2020 5:44 pm

Re: Simple two-link URDF applyExternalForce unexpected response

Post by avikde »

Thank you Erwin! I can confirm that the behavior is different in pybullet 2.8.2.

I do have a few follow-up clarifications:

1) Trying to understand "disable position/velocity motors before applying an external torque/force": In the avik.py in your attachment, p.setJointMotorControlArray is called on joint 1, and in the main loop we call applyExternalForce on link 2 (joint 1 connects link 1 to link 2). Basically I wanted a passively springy joint and to apply a force to it. It seems to work as expected, so I just wanted to confirm that that's correct. Or do we have to "release" the joints by setting velocity control or torque control with 0 before applying the external force on link 2?

2) For simulating some micro-scale systems I use a mm,mg,ms system of units since I find more numerical issues (and just inconvenience) with m,kg,s. Obviously I set gravity as 10e-3, inertias, lengths etc. in the mm,mg units. Obviously still 1ms may be too large a timestep compared to the timescale of the dynamics (depending on the accelerations and inertias), but I just wanted to clarify that there shouldn't be any issue with this kind of unit scaling.

3) I also learned from your attachment that the inertial property also must have its origin set in the URDF (I had assumed that the inertial property is always assumed to be about the centroid). For a box primitive is it generally correct that the inertial property's origin should match the visual property's origin (assuming the inertias I am specifying are in the axis-aligned body COM frame of the link?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Simple two-link URDF applyExternalForce unexpected response

Post by Erwin Coumans »

Ah, I disabled the velocity/position motors by setting the force to zero. You can certainly leave the motors enabled, with a force of your choice to model joint friction or other effects such as springyness.

I was assuming metric units (meter, seconds etc). If you are using different units, you need to indeed change the time step.

It is best to keep the inertial, visual and collision elements consistent, they are all expressed in the same (link) frame in the URDF. So for a box, the local center of mass location is in the center, so it uses the same offset as visual/collision frame.
avikde
Posts: 3
Joined: Thu Jun 18, 2020 5:44 pm

Re: Simple two-link URDF applyExternalForce unexpected response

Post by avikde »

Thanks! I can confirm that pybullet 2.8.2 solved the original problem I had.
Post Reply