Quote:
Originally Posted by Chris Hibner
You can use the encoders to emulate a gyro for driving straight. Here is some psuedo-code for how to do it:
Code:
heading = 57.3*(leftEncDist - rightEncDist) / trackWidth;
if (abs(driverTurnCmd) < turnDeadZone)
{
if (headingCaptured == FALSE)
{
desiredHeading = heading;
headingCaptured = TRUE;
}
turnCmdPID = PID(heading, desiredHeading);
arcadeDrive(driverThrottleCmd, turnCmdPID);
}
else
{
headingCaptured = FALSE;
arcadeDrive(driverThrottleCmd, driverTurnCmd);
}
When we've done this in the past, it makes it a little smoother if you lead your desired heading with your turn rate. So instead of "desiredHeading = heading" in the above code, we've done "desiredHeading = Heading + robotTurnSpeed * leadFactor", where "leadFactor" is a calibration that you tune to make the stopping of the turn smooth.
|
I really like this gyro idea i will have to give it a try.
I am only going to be using this outside of auto. During auto we use a gyro.
The method i am trying now is to use a velocity control PID for each side. however it would be nice to have a slave/master configuration but i am not sure hot to deal with turning