Hello, we have been unable to reset gyros mid match. While do auton, between steps we reset our gyro position so that we don’t have to keep a consistent gyro reading, we can just turn to an angle from zero. We have tried the NavX, Pigeon, and the ADX one from the kit of parts and have never been able to make it work. Normally it’s fine due to power cycling between matches. All we do is use the built in reset function of the gyros and it seems to do nothing.
You’ll need to post your code for us to help. But, if you didn’t mis-speak saying “reset function of the encoders”, that’s your issue (encoders are not the same thing as a gyro).
Fixed and here is the code
public boolean turnTo( double angle, double slowDown ) {
double error = 0.0;
if (!autonActive) {
setBrakeMode();
gyro.reset();
autonActive = true;
}
if(angle > 0){
error = angle - gyro.getAngle();
if(error > 0){
if((error-slowDown) > 0){
arcadeDrive(0, .65);
}else{
arcadeDrive(0, .15);
}
}else{
stopDrive();
autonActive = false;
}
}else if(angle < 0){
error = angle + -gyro.getAngle();
if(error < 0){
if((error+slowDown) < 0){
arcadeDrive(0, -.65);
}else{
arcadeDrive(0, -.15);
}
}else{
stopDrive();
autonActive = false;
}
}
return autonActive;
}
Have you verified that autonActive is false at some point?
Note that both the NavX and Pigeon have onboard processors. It takes time for the reset command to be sent and the reset to be reflected in the angle. The ADXRS450 should be faster, as the accumulation is done in the FPGA, though.
The NavX docs state that “software-based yaw resets occur instantaneously.” Shouldn’t the delay only occur if gyro.enableBoardlevelYawReset()
is set to true
?
Yes, this is correct. Board-level yaw reset is more comprehensive, because it also resets the underlying world-frame rotation component of the quaternion, however as Joe mentioned there is a delay until board-level yaw reset fully takes effect.
Most teams don’t need board-level yaw reset. And board-level yaw reset is disabled by default.
This is because most teams only use the yaw angle (e.g., getYaw()) and not quaternions. So for most teams therefore, the software-based reset is preferable - because it does not exhibit the inherent delay that the board-level yaw reset does.
This is a really good question. Within the code snippet shown in this post, if error never reaches 0, autonActive wouldn’t become false, and thus gyro.reset() would never be invoked. Consider a tolerance (setting autonActive == false when the angle is within a threshold of, say, 1 degree of the target angle). It’s highly unlikely that without a well-tuned control algorithm, the exact target angle will be exactly reached.
I updated it here:
public boolean turnToTwo(double angle, Timer resetTimer){
double angleTolerance = .5;
final double TURN_K = 0.0005;
final double RIGHT_MAX = .65;
final double LEFT_MAX = -.65;
final double RIGHT_MIN = 0.25;
final double LEFT_MIN = -0.25;
if(resetTimer.hasElapsed(.5)){
double error = angle - gyro.getAngle();
if (Math.abs(error)< angleTolerance)
{
return false;
}
// Start with proportional steering
double turn_cmd = error * TURN_K;
if (turn_cmd > RIGHT_MAX)
{
turn_cmd = RIGHT_MAX;
}else if(turn_cmd > 0 && turn_cmd < RIGHT_MIN){
turn_cmd = RIGHT_MIN;
}else if(turn_cmd < 0 && turn_cmd > LEFT_MIN){
turn_cmd = LEFT_MIN;
} else if (turn_cmd < LEFT_MAX){
turn_cmd = LEFT_MAX;
}
arcadeDrive(0, turn_cmd );
}
return true;
}
We are going to reset the gyro prior to this method being called then check with the timer to make sure enough time has elapsed.
Here is our full repo: GitHub
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.