Inertial sensor runs on

When using the inertial sensor to turn, it works once, then when we use it a second time, it tends to continue to count up or be really off after the turn. Suggestions or help appreciated

Are you using the heading of the inertial sensor to do your turns? Could you post the code? If I’m interpreting this right, you should use the rotation of the inertial sensor to turn left or right. After each turn, you should reset the rotation of the inertial sensor because the previous turn would have changed the rotation.

Are you using a competition switch? If not, I would recommend calibrating the inertial sensor in the pre auton function and using a competition switch so it will calibrate it at the beginning.

1 Like

Yeah this what i do and my turns are almost always consistent, unless outside factors like bumping other robots during auton or getting caught on a game element happens

code*

#include “vex.h”

using namespace vex;
controller joystick;
// A global instance of competition
competition Competition;

// define your global instances of motors and other devices here

/---------------------------------------------------------------------------/
/* Pre-Autonomous Functions /
/
/
/
You may want to perform some actions before the competition starts. /
/
Do them in the following function. You must return from this function /
/
or the autonomous and usercontrol tasks will not be started. This /
/
function is only called once after the V5 has been powered on and /
/
not every time that the robot is disabled. /
/
---------------------------------------------------------------------------*/

void pre_auton(void) {
float point;

point=(Inertial19.heading(degrees));
// Initializing Robot Configuration
vexcodeInit();
//calibrate inertial sensor
Inertial19.calibrate();
// waits for the Inertial Sensor to calibrate
while (Inertial19.isCalibrating()) {
wait(500, msec);}

// All activities that occur before the competition starts
// Example: clearing encoders, setting servo positions, …
}

void autonomous(void) {
float howfar;
Inertial19.setHeading(0,degrees);
wait(300,msec);
// Turns the robot to the left
LeftMotor.spin(reverse);
RightMotor.spin(reverse);
waitUntil(Inertial19.heading(degrees)>90);
LeftMotor.stop(hold);
RightMotor.stop(hold);
wait(100,msec);

howfar=(Vision13.objectDistance(mm));
while(howfar>300)
{
LeftMotor.spin(forward);
RightMotor.spin(reverse);
howfar=(Vision13.objectDistance(mm));
}
LeftMotor.stop();
RightMotor.stop();
//AT FIRST BOX
//calibrate inertial sensor
Inertial19.calibrate();
// waits for the Inertial Sensor to calibrate
while (Inertial19.isCalibrating()) {
wait(100, msec);}
LeftMotor.spin(reverse);
RightMotor.spin(reverse);
Inertial19.setHeading(0,degrees);
wait(100,msec);
waitUntil(Inertial19.heading(degrees)<280);
LeftMotor.stop();
RightMotor.stop();
wait(100,msec);
howfar=(Vision13.objectDistance(mm));
while(howfar>250)
{
LeftMotor.spin(forward);
RightMotor.spin(reverse);
howfar=(Vision13.objectDistance(mm));
}
LeftMotor.stop();
RightMotor.stop();
//AT SECOND BOX
//calibrate inertial sensor
Inertial19.calibrate();
// waits for the Inertial Sensor to calibrate
while (Inertial19.isCalibrating()) {
wait(500, msec);}
LeftMotor.spin(reverse);
RightMotor.spin(reverse);
Inertial19.setHeading(0,degrees);
wait(200,msec);
waitUntil(Inertial19.heading(degrees)<280);
LeftMotor.stop();
RightMotor.stop();
wait(100,msec);
howfar=(Vision13.objectDistance(mm));
while(howfar>100)
{
LeftMotor.spin(forward);
RightMotor.spin(reverse);
howfar=(Vision13.objectDistance(mm));
}
LeftMotor.stop();
RightMotor.stop();
}


I have tried using both rotation and heading and neither works consistently. I will replace the heading with rotation and try it again

yes and yes to both items are currently done.

couple of comments.
There’s no need to keep recalibrating the IMU, do it once in pre-auton while the robot is not moving.
Asking to calibrate directly after sending stop to the motors may not work well as the momentum of the robot may mean it’s still moving.

4 Likes