Stabilizing floating body

General discussion about Box2D tutorials
Post Reply
kazeno
Posts: 8
Joined: Sat Feb 21, 2015 1:46 am

Stabilizing floating body

Post by kazeno » Sat Feb 21, 2015 2:00 am

I can not figure out how to stabilize a floating body like a helicopter or a hover skate with thrusts in the front and rear ends.
I has trying to make the thrust equal to the distance to the target but it only work for bodies with fixed rotation and bounce too much when reach the target.
For acceleration instead of targeting a position should I apply an horizontal force or rotate the body?

Can someone help me with that?
Thanks in advance.

iforce2d
Site Admin
Posts: 860
Joined: Sat Dec 22, 2012 7:20 pm

Re: Stabilizing floating body

Post by iforce2d » Sat Feb 21, 2015 7:23 am

If you apply the force at the center of mass it should cause no rotation, so non-fixed-rotation bodies will behave the same as fixed-rotation bodies:
body->ApplyForce( force, body->GetWorldCenter() );

Making the thrust equal to the distance to the target is called "proportional" control, and will almost always cause the bouncing result that you mention. You also need to take into account the current speed of the body, because if it's already heading in the right direction then you don't need to add so much thrust right?

One simple way you can do this is to "look ahead" and instead of using the current position of the body to calculate the thrust, use the position where the body will be a short time in the future, eg. half a second, one second etc. Examples here:
https://www.iforce2d.net/b2dtut/rotate-to-angle
https://www.iforce2d.net/b2dtut/suspension

A better way to do it might be to use a PID controller. There is a lot of info on the net about those, you can use the psuedo code from the wikipedia page to make a simple one. Example here: https://www.iforce2d.net/blog/2014-04-22

kazeno
Posts: 8
Joined: Sat Feb 21, 2015 1:46 am

Re: Stabilizing floating body

Post by kazeno » Sun Feb 22, 2015 4:50 pm

But do the shape of the fixture make it rotate?
When it's asymmetric or the force is diagonal.
Helicopter is pretty asymmetric and can have extra load.
How they do all that with a single helix and a small one for yaw.

I'm studying the PID controller and it to works really great!
On the other hand the constants are hard to figure out.
I trying to move a motorcycle with it but the motor speed is fast close to the target and overshot too much.
I think I should consider the wheels friction and ground properties...

iforce2d
Site Admin
Posts: 860
Joined: Sat Dec 22, 2012 7:20 pm

Re: Stabilizing floating body

Post by iforce2d » Sun Feb 22, 2015 6:46 pm

In real life the shape of things affect how they rotate because we have wind, but Box2D doesn't so it should not.

Yes, figuring out good values for PID constants is something that people write entire university theses about :)

Post Reply