[ODE] Rotation troubles
SJS
ode at pulsecode.net
Sun Jan 4 00:49:53 MST 2004
Here's an explanation of how to make a second-order (PID) controller:
(or with C=0 you get a simpler PD controller)
f = A*s - B*v + C*w
where f is the force to apply--
s is the error term (desired position - current position),
v is the velocity ([current position - previous position]/timestep)
w is the "integral" term-- the sum of all previous s*timestep
A, B, and C are constants that you choose to control the response curve.
They should all be positive for stable results. Their actual values
will depend somewhat on the timestep (timestep should remain roughly the
same throughout your simulation or should be stabilized by updating the
PID multiple times per ODE update).
you'll be doing something like this (all variables here are floats):
A = 0.1f;
B = 0.4f;
C = 0.0001f;
w = 0.0f;
xPrevious = <position of object being controlled>
frame loop (timestep=h):
{
xCurrent = <position of object being controlled>
s = xDesired - xCurrent;
v = (xCurrent - xPrevious)/h; // can use true velocity if available
w += s*h;
xPrevious = xCurrent;
f = A*s - B*v + C*w;
<apply force 'f' to joint>
}
NOTES--
higher values of 'A' (the "proportional" term) will give a quicker response,
but values too high will produce oscillation or instability.
higher values of 'B' (the "differential" term, or damping coefficient) will
slow the response but make things more stable.
The 'C' coefficient (the "integral" term) will reduce steady-state error,
but may be set to 0 in many cases (resulting in a pure
proportional-differential controller).
In many cases you may wish to clamp the value of f to prohibit extremely
large forces.
If you're controlling an angle (and thus f is actually a torque on a
rotational joint) you'll need to 'mod 2pi' the position differences as
follows:
s = fmodf( xDesired - xCurrent, 2*PI );
if (s < -PI) s += 2*PI;
else if (s > PI) s -= 2*PI;
v = fmodf( xCurrent - xPrevious, 2*PI );
if (v < -PI) v += 2*PI;
else if (v > PI) v -= 2*PI;
v /= h;
To adjust the coefficients, start with B=C=0 and try to find an 'A' term
that produces a reasonable force (you'll probably see oscillation). Then
increase B. Finally increase C to reduce the steady state error if it
matters.
Yet another note: when you make a large change to the desired position you
may wish to reset the integrator (set w=0.0f), but this is not always
necessary (and never necessary if C=0).
Good luck
Stephen Schlueter
-----Original Message-----
From: ode-bounces at q12.org [mailto:ode-bounces at q12.org]On Behalf Of
Ignacio García Fernández
Sent: Monday, December 29, 2003 12:34 AM
To: ode at q12.org
Subject: Re: [ODE] Rotation troubles
On Sat, Dec 27, 2003 at 04:41:35PM +0100, Nicholas Francis wrote:
> Thanks for the tip. I played around with spring/damping, and they work
> quite nice, except for:
>
> * Du to the low force applied when the target is 'close' to being
> right, it takes a very long time to get the last 2-3 degrees of
> rotation right
> * On the flip side of the above, the rotations get very fast if the
> target direction is far away (as the spring gets very strong).
>
> Correcting the spring/damper constants to fix one of the above problems
> naturally made the other one worse. I tried adding a falloff to the 1-d
> (by raising it to, say, 0.5) in order to compensate, but it did not
> solve the problem.
>
> We're already using sping/dampers for the camera control, and for that
> it works great. However, here the varying strength of the spring makes
> the object being rotated look either too heavy or too light. I think
> the reason it works for cameras, but not helicopters is that
> helicopters have a certain mass (to say the least), hence when they
> turn too fast it feels wrong in a way a camera never will. At the same
> time, an experienced pilot will certainly 'drive' the helicopter just
> as hard when 10 degrees away from a correct shot as when 90 degrees
> away.
What you intend to do is to «control» the direction of the
helicopter. An here I mean control in the Control Theory sense.
The problem is that you're using a low order control system. You
should consider a higher order control system that involves, not only
the direction, but also de velocity or even the acceleration of the
direction.
>
> Any other suggestions, or do I need to get up to speed on my math
> skills?
Use a higher order control... which involves some new math skills,
indeed :-)
Or, probably better, try with a controller that acts on the
constants. This is the idea you have already tried, but there exist
methods that tune them dynamically very fine.
Look for 'second order control' and for the string "P+D"
I don't know too much these systems, but I'll help with whtever I can.
Regards
--
May the source be with you
--------------------------------------------------------------------
Ignacio García Fernández Instituto de Robótica
ignacio.garcia_at_uv.es Universidad de Valencia
http://robotica.uv.es/~ignacio/ Tlf. 96 354 3564
_______________________________________________
ODE mailing list
ODE at q12.org
http://q12.org/mailman/listinfo/ode
More information about the ODE
mailing list