I’m using an inertial sensor to do turns in my autonomous program, but after the very first turn, the reading for the sensor at the yaw keeps going up by about two degrees per second, and it won’t stop. any ideas on how to tix this issue? it’s not near any motors or surrounded by metal, and my auton line is as follows:
TurnRt(115, 0.5);
MWait(100);
// optional code to re-calibrate inertial sensor (see quote above)
void ReCalibrateGyro()
{
Inert.calibrate();
while( Inert.isCalibrating() )
{ wait(10,msec); }
}
void TurnRt(int degTurn, double PctSpd) //robot turns right
{
double Kp = 0.3; // tune for least error and best performance
while( Inert.isCalibrating() ) // make sure robot doesn't move
{ wait(10,msec); }
Inert.resetRotation(); // tare rotation counter
while(true)
{
double gError = degTurn - Inertial.rotation(deg);
if( abs(gError) < 3) // we will stop within 3 deg from target
{
break;
}
double speed = gError * Kp;
// clamp max turning speed to -PctSpeed...+PctSpeed
if( speed > +PctSpeed ) speed = +PctSpeed;
if( speed < -PctSpeed ) speed = -PctSpeed;
LTC.spin(DirFwd, speed, VelPct);
RTC.spin(DirRev, speed, VelPct);
LBC.spin(DirFwd, speed, VelPct);
RBC.spin(DirRev, speed, VelPct);
wait(10,msec);
}
LTC.stop();
RTC.stop();
LBC.stop();
RBC.stop();
}
If you still have problems running this code, please, take a look at this topic and examples I linked earlier and, if it still doesn’t help, post your updated code back in this topic enclosed in the [code]...[/code] tags. Please, don’t create a new topic again.
I calibrate at pre-auton, but not anywhere after that. it looks like this:
void pre_auton(void)
{
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
Inert.calibrate();
// waits for the Inertial Sensor to calibrate
while (Inert.isCalibrating())
{
wait(100, msec);
}
// All activities that occur before the competition starts
// Example: clearing encoders, setting servo positions, …
}
how did you start your program? I think if you started it with the competition or programming skills mode on your controller, your functions in pre auton won’t run
I fixed the problem. it turns out that because I placed the sensor at the edge of my robot, it got confused. I put it back more towards the center of the bot, and it stopped drifting.
a few minutes is a very long time for this gyro. It tends to accumulate error over time and a few minutes(more than 2 I would think) it will become significantly off
Either the IMU is moving while being calibrated, or it has some internal fault.
Check the IMU using the dashboard. Open the dashboard, there’s no need to run your program. Make sure the robot/imu is stationary and gently touch the calibrate button in the dashboard. After a couple of seconds, the imu will finish calibration and the roll, pitch and heading values will adjust to show the absolute orientation of the imu. Check the heading value remains stable with only a few tenths of a degree drift per minute. Check that the values for the gyro are close to 0. Rotate the robot/imu, check the heading changes accordingly, see if there is any significant drift after doing this. Let us know the results.