Inertial sensor problems

my inertial sensor is acting up again
the first turn in my auton works fine (using inertial)
but the second inertial turn spins indefinetely (doesnt stop)

heres the code:

    Chassis.spinFor(reverse, 100, deg);
    IR.spinFor(reverse, 200, deg);
    Chassis.spinFor(forward, 100, deg);
    IR.spin(reverse, 100, pct);
    Chassis.spinFor(forward, 200, deg);
    wait(0.7, sec);
    Chassis.spinFor(reverse, 200, deg);
    Chassis.stop();
    // Turns the robot to the right
    Chassis.setStopping(brake);
    LDrive.spin(forward, 30, pct);
    RDrive.spin(reverse, 30, pct);
    // Waits until the motor reaches a 90 degree turn and stops the Left and
    // Right Motors.
    waitUntil((IS.rotation(degrees) >= 200.0));
    LDrive.stop();
    RDrive.stop();

    while (stopCata == false){
      C.spin(forward);
    }
    C.stop();
    stopCata = false;
    Chassis.stop();
    // Turns the robot to the right
    Chassis.setStopping(brake);
    IS.resetRotation();
    LDrive.spin(reverse, 30, pct);
    RDrive.spin(forward, 30, pct);
    // Waits until the motor reaches a 90 degree turn and stops the Left and
    // Right Motors.
    waitUntil((IS.rotation(degrees) >= 180.0));
    LDrive.stop();
    RDrive.stop();

    IL.set(false);
    Chassis.spinFor(forward, 300, deg);
    IL.set(true);
    IR.spin(reverse, 100, pct);
    wait(1, sec);

This appears to be a problem with the ‘waitUntil’ condition of the second turn.

The first turn has the robot turn to the right, while the second turn has the robot turn to the left. This produces a positive and negative change in the imu sensor, respectively.

However, the ‘waitUntil’ command waits for a positive value for both turns. So, although the robot turns 180 degrees in the second turn, it’s actual sensor reading is -180 degrees.

This problem can be fixed with a few alterations to the ‘waitUntil’ condition:

waitUntil((IS.rotation(degrees) <= -180.0));

This implementation can be applied to all future left turns, and your original first turn format can be utilized for all future right turns in the autonomous.

1 Like