Gyroscope Initialization

Robot is running even it is suppose to stay put for initialization of gyroscope. Is there a way to initialize the gyroscope without spending precious time of 2 seconds in pre Auton? But the main problem really is that the robot is moving ahead even if it is suppose to wait until gyroscope is done calibrating.

void vexcodeInit( void ) {
Brain.Screen.print(“Device initialization…”);
Brain.Screen.setCursor(2, 1);
// calibrate the drivetrain gyro
wait(200, msec);
TurnGyroSmart.calibrate();
Brain.Screen.print(“Calibrating Gyro for Drivetrain”);
// wait for the gyro calibration process to finish
while (TurnGyroSmart.isCalibrating()) {
wait(25, msec);
}
// reset the screen now that the calibration is complete
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1,1);
wait(50, msec);
Brain.Screen.clearScreen();
}

void pre_auton(void) {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();

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

int main() {
// Run the pre-autonomous function.
pre_auton();
// Set up callbacks for autonomous and driver control periods.
Competition.autonomous(autonomous);
Competition.drivercontrol(usercontrol);

// Prevent main from exiting with an infinite loop.
while (true) {
wait(50, msec);
}
}

I don’t really see how waiting 2 seconds in preAuton would be a problem. You could try using a competition switch to allow for a longer preauton so it calibrates properly

2 Likes

Thanks, that might be the problem. I don’t have the competition switch. Will let you know later. Thanks again.

If you’re using the inertial sensor you don’t need to manually calibrate in the code. According to @jpearman the cortex already does the calibration when turned on. If you can calibrate you should but it’s not required.

Link for proof: https://www.vexforum.com/t/how-do-i-calibrate-inertial-sensor-in-pre-auton/74040/4

2 Likes

When not using a competition switch, the driver control task begins almost immediately after starting the code. This means that if you have longer waits in preAuton, then driver control will begin before preAuton has completed and both will run at the same time. You could either use a competition switch, like @thorstenl312 suggested, or use a flag to make sure that driver begins only after preAuton has completed.

2 Likes

I’m using Jpearman’s inertial sensor initialization. Catzilla exactly described my situation. In RobotC, we used to have a way to test autonomous without having to use a competition switch. I guess Vexcode V5 text don’t have that capability yet. My setup during autonomous testing is: my controller USB wired to computer then I run my autonomous wirelessly using the controller. I guess I should use a competition switch to simulate on field runs. I will test it as soon as I get the competition switch.