How to control and limit btMultiBody Spherical joint

benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland

Re: How to control and limit btMultiBody Spherical joint

Post by benelot »

My creatures are moving at joint angle frequencies of 0.1 -10 Hz. So I should probably take a time step based on that. Is there a huge difference in performance between the speed of substeps and the speed of actual steps?
Have you considered using joint callbacks for the controller? Basically at the start of the substep you can call back to whatever piece of code you want (hopefully nothing that adds or subtracts bodies or joints) in each substep. Basically you can keep steps the same size but you can choose what the size of the external step is based on your needs (for data logging, display, etc).
I did not consider that yet, that sounds good. During the joint callbacks, I would only check the position and velocity of the joint, probably other sensors and then compute a new control output (apply impulse or similar). From what I read, the substeps are interpolations and therefore they are probably less precise than proper timesteps. The question really is if the substeps are interpolations, then the joint callbacks do not influence the movement if they apply impulses. Or do the interpolations consider that?

Where can I find the old DynamicControlDemo? From what I can see, there was no previous version (https://github.com/bulletphysics/bullet ... ontrolDemo).
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: How to control and limit btMultiBody Spherical joint

Post by Basroil »

benelot wrote:My creatures are moving at joint angle frequencies of 0.1 -10 Hz. So I should probably take a time step based on that. Is there a huge difference in performance between the speed of substeps and the speed of actual steps?
Sub-steps are not actually different than the regular step, it's just an automated way to synchronize display and simulation. Unless you have a lot of external code being called between steps (that you don't add to the pretick), then it shouldn't be any slower or faster.
benelot wrote: I did not consider that yet, that sounds good. During the joint callbacks, I would only check the position and velocity of the joint, probably other sensors and then compute a new control output (apply impulse or similar). From what I read, the substeps are interpolations and therefore they are probably less precise than proper timesteps. The question really is if the substeps are interpolations, then the joint callbacks do not influence the movement if they apply impulses. Or do the interpolations consider that?
I suggest re-reading the btdynamicsworld (or whichever world type you used/created), but I haven't seen anything that claims the substeps are interpolations. Everything ends up calling internalSingleStepSimulation(fixedTimeStep) unless substeps are set to zero and the elapsed time is zero. The only differences I know of is that gravity forces are set at the beginning but not updated until the next call to stepSimulation (so mario galaxy style physics will need modifications) and saveKinematicState is called just once at the beginning. I've used the callbacks for motor control, and it doesn't seem to have caused any issues with accuracy so far.

benelot wrote:Where can I find the old DynamicControlDemo? From what I can see, there was no previous version (https://github.com/bulletphysics/bullet ... ontrolDemo).
That version is fine too, UI is different, but control method the same.
benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland

Re: How to control and limit btMultiBody Spherical joint

Post by benelot »

Ok, so if I do five times stepWorld or stepWorld with 5 substeps it results in the same amount of time being stepped forward and the same calculation? I doubt that a bit because the substeps would be useless.

I read about the interpolation here in the "stepping the world" wiki article(last paragraph):
http://bulletphysics.org/mediawiki-1.5. ... _The_World

I just set my simulation to thedefault timestep of 1/60.0f and I get visible problems with my PID controller, because the sampling rate of the sensors is now (1/60f). I can not decouple it because it does not make sense to sample the same state multiple times. How did you achieve proper sampling rates for motor control with a higher timestep (I do not mean the substepping option, with your reasoning, that is the same as taking multiple small steps)?
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: How to control and limit btMultiBody Spherical joint

Post by Basroil »

benelot wrote:Ok, so if I do five times stepWorld or stepWorld with 5 substeps it results in the same amount of time being stepped forward and the same calculation? I doubt that a bit because the substeps would be useless.
Depends on your controllers and how you set it up. For example, if you update the controller reference point only before the stepSimulation part, the next five steps will use that same reference point (but you will likely have it reference current joint status in between). For the most part it shouldn't actually change anything other than display and other externally used values.
benelot wrote: I read about the interpolation here in the "stepping the world" wiki article(last paragraph):
http://bulletphysics.org/mediawiki-1.5. ... _The_World
Yes, that thing is confusing as hell. I think the interpolation is only applied to the externally visible motion states, but we'll need confirmation on what exactly happens there from Erwin or drleviathan (and the actual list is much longer, don't be upset if I missed your name :wink: ).
benelot wrote: I just set my simulation to thedefault timestep of 1/60.0f and I get visible problems with my PID controller, because the sampling rate of the sensors is now (1/60f). I can not decouple it because it does not make sense to sample the same state multiple times. How did you achieve proper sampling rates for motor control with a higher timestep (I do not mean the substepping option, with your reasoning, that is the same as taking multiple small steps)?
For my projects, 1/60 is far too large of a step, and it seems that the same is true for you .In my case, I'm modeling MX28 based robots at 1/200 or 1/240 with PID using the pre-tick callback, and it's about as stable as you can get. If i tried it at 120Hz I get reasonable results, but a bit of instability at lower inertias, and 60Hz is just a hot mess. You can try to fudge the numbers using extrapolation from prior system states and simplified joint dynamics approximations, but nothing beats smaller steps (though the others might be good enough and will certainly be faster).
benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland

Re: How to control and limit btMultiBody Spherical joint

Post by benelot »

Thanks for all your help and information! I think I definitely have something to optimize again :) Do you know how overall ERP/CFM and the joint specific ERP/CFMs are combined? Is the general value replaced by the specific if it is set? I also tried to find the default values, but could not find them.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: How to control and limit btMultiBody Spherical joint

Post by Erwin Coumans »

Basroil wrote: Sub-steps are not actually different than the regular step,
The number of sub-steps can be different from the regular step (first argument to 'stepSimulation').

Say the internal sub-step size is 100 Hertz, or 0.01 seconds and the regular step is 1 second.
If you call world->stepSimulation(1.0 , 1000, 0.01); the physics engine will perform 100 internal sub step steps.

Now if you call world->stepSimulation(0.001, 1000, 0.01); the physics engine will perform 1 sub step, once every 10 calls.
The other 9 calls, the engine will not run any physics simulation, but update the motion state (if it exists), so you can update the render engine for smoother visuals for example.
Where can I find the old DynamicControlDemo? From what I can see, there was no previous version (https://github.com/bulletphysics/bullet ... ontrolDemo).
Not all old demos are converted to the new Bullet Example Browser yet. Feel free to convert it and contribute a patch/pull request.
Basroil wrote:
benelot wrote: I read about the interpolation here in the "stepping the world" wiki article(last paragraph):
http://bulletphysics.org/mediawiki-1.5. ... _The_World
Yes, that thing is confusing as hell. I think the interpolation is only applied to the externally visible motion states, but we'll need confirmation on what exactly happens there from Erwin or drleviathan (and the actual list is much longer, don't be upset if I missed your name :wink: ).
The idea of inter/extrapolation is to decouple the internal physics time step from the user time step, and to compute inter/extrapolated world transforms that can be used for the graphics render engine. If that is confusing, just ignore it and don't use the motion state.

For robotics, it can be worthwhile using the btMultiBody instead of using btRigidBody+btTypedConstraints. You can create a URDF file and load it.

Unfortunately I'm often busy with actual Bullet development and use of Bullet in robotics, and don't have time to regularly visit those forums.
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: How to control and limit btMultiBody Spherical joint

Post by Basroil »

Erwin Coumans wrote: The number of sub-steps can be different from the regular step (first argument to 'stepSimulation').

Say the internal sub-step size is 100 Hertz, or 0.01 seconds and the regular step is 1 second.
If you call world->stepSimulation(1.0 , 1000, 0.01); the physics engine will perform 100 internal sub step steps.

Now if you call world->stepSimulation(0.001, 1000, 0.01); the physics engine will perform 1 sub step, once every 10 calls.
The other 9 calls, the engine will not run any physics simulation, but update the motion state (if it exists), so you can update the render engine for smoother visuals for example.
Good to know, but the question was about the qualitative difference between a substep in the first case you used and simply using world->stepSimulation(0.01 , 0, 0.01) a hundred times. Would each of the substeps in your first case be any different than calling the full stepSimulation code if external code does not affect the simulation? For all intents and purposes it seems like they would be the same and return the same result.
benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland

Re: How to control and limit btMultiBody Spherical joint

Post by benelot »

@Basroil:
I have a follow-up question you might probably be able to help me, but regarding the fact that it is not related directly to the original question, I opened a new one here (It is related to the ERP/CFM calculation we discussed a bit above):
http://bulletphysics.org/Bullet/phpBB3/ ... =9&t=10873