View Single Post
  #3   Spotlight this post!  
Unread 24-01-2009, 17:44
ellisk ellisk is offline
Registered User
FRC #1540
 
Join Date: Dec 2008
Location: Vancouver, WA
Posts: 41
ellisk is on a distinguished road
Re: Using encoders for traction control help

Thanks for the tips. Here's examples of what I've been trying (none of which works):

Code:
float correctForSlip(float transVel, float omniVel, float realWheel, float desiredWheel)
{
	// make sure that there's enough of a difference
	const float slipThreshold = 15.0;
	if (fabs(transVel - omniVel) < slipThreshold)
		return desiredWheel;

// note for forums: code after here varies depending upon attempt

	const float adjustSlipK = -0.005; // tuned experimentally
	
	float delta = fabs(transVel - omniVel) * adjustSlipK;
	
	if (transVel < omniVel) // need to up the number
		return desiredWheel + delta;
	else
		return desiredWheel - delta;
}
That didn't work, so I tried instead:
Code:
	if (transVel != 0) {
		float decreaseMtrMultiplier = omniVel / transVel;
		return decreaseMtrMultiplier * desiredWheel;
	} else {
		const float seedSlipK = 0.001;
		return seedSlipK * omniVel;
	}
And then this fails too:
Code:
	// stupid method: increase wheel speed
	const float speedupK = 0.05;
	if (realWheel > 0)
		return realWheel + speedupK;
	else if (realWheel < 0)
		return realWheel - speedupK;
	else { // realWheel == 0
		if (omniVel > 0)
			return speedupK;
		else if (omniVel < 0)
			return speedupK;
		else // should never happen
			return desiredWheel;
	}
???? Perhaps I'm missing something here, but the "back off when a wheel is going too fast, increase when going too slow" seems to be difficult to implement correctly.

-Kevin