[ODE] simulation of a servo

Nate W coding at natew.com
Tue Aug 26 09:35:02 2003


On Tue, 26 Aug 2003, Stefan Castille wrote:

> I made a very simple model of a servo, basically it has a target angle and
> will go full speed until that angle has been met up to a certain accuracy.

It's much better to vary the target speed:

> for (int a = 0; a < nrJoints; a++)
> {
	dReal Gain = 0.1;

	dReal TruePosition = dJointGetHingeAngle(joint[a]);
	dReal DesiredPosition = servopos[a];
	dReal Error = TruePosition - DesiredPosition;

	dReal DesiredVelocity = Error * Gain;

	dJointSetHingeParam(joint[a], dParamFMax, 0.5);
	dJointSetHingeParam(joint[a], dParamVel, DesiredVelocity);
> }

"Gain" can be tuned by hand for different "stiffness," for example lower
values like will make servos soft, high values will make them more
rigid.  I've found that 0.1 works most of the time, but you might want to
make it larger for joints that carry a lot of load, like knees for
example.  Maybe "dReal Gain = servogain[a]" would be more appropriate.

-- 

Nate Waddoups
Redmond WA USA
http://www.natew.com