[ODE] Yet another question about servo emulation

Nate W coding at natew.com
Sat May 24 12:51:02 2003


On Sat, 24 May 2003, Shamyl Zakariya wrote:

> In my project, I need to model servo behavior, such that I can say in 
> my code, more or less something like this:
> 	someServo->setPosition( angle )
> 
> I gather several people have need for similar functionality. 

Juice certainly has that sort of thing.  But, I use the motor built into
the hinge joint itself, rather than an AMotor.  This probably doesn't make
much difference at run time, but it makes for slightly simpler code.

As for the odd behavior you're seeing, my guess is that it stems from your
use of dInifinty for FMax.  Try this:

void ServoMotor::step( void )
{
 	dReal da = _desired - getCurrentPosition(); //magnitude and direction 
 
	dReal velocity = da * _speed;

	if (_verbose)
	{
		printf("ServoMotor::step()\tda: %.2f, velocity: %.2f\n", da, velocity);
		dumpState();
	}
		
	dJointSetAMotorParam( _motor, dParamFMax, _force );
	dJointSetAMotorParam( _motor, dParamVel, velocity );
}

I don't think there's anything to be gained from the code you're using to
treat holding center as a special case.  It might even be the cause of the
instability you're seeing.

> I'd really appreciate it if somebody here can point out what's wrong 
> with my code. Perhaps there's a logical error in the feedback loop? 
> perhaps I'm not fully understanding the dynamics of the way motors 
> work, or how to use ERP or CFM adjustments. 

I generally start by setting ERP to 1.0, and CFM to 0.0001.  If I get a
lot of explosions, CFM = CFM * 10.  If I get no explosions, CFM = CFM /
10.  A value of 0.1 will be very stable, but also quite squishy, like the
bodies are made of rubber.  A value of 0.0000001 will be very rigid, but
prone to oscillations or explosions.  In between those extremes it's
usually easy to find a setting that's reasonably stiff and reasonably
stable; I just tweak CFM using those rules and usually get something good
after just a few iterations.

> Also, one more thing -- if anybody can give me some notion of how to 
> get the torque force a joint/motor is experiencing while holding 
> position I'd also appreciate it. I gather the function 
> dJointGetFeedback() is the way to go, but I haven't tried it yet. And 
> I'm sufficiently new to this API that I'm uncertain about how to go 
> about doing this correctly.

I think you're probably right, but I haven't messed with it either. :-)

-- 

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