So I’ve been trying to program the gyro sensor looking at other peoples code and stuff to see what I did wrong and I cant find out what I did wrong, it just continuously spins and never stops. Please help
//Gyro Turning Clockwise
void GyroTurnCW (float DegreeAmount, int veloc)
{
//Set speeds of both Drive motors
LeftDrive.setVelocity(veloc,velocityUnits::pct);
RightDrive.setVelocity(veloc,velocityUnits::pct);
//Switches between degrees and hundreths of degrees
float GyroDegrees;
(GyroDegrees) = (DegreeAmount * 100);
//While loop to do the spin
while (Gyroo.value(rotationUnits::deg) <= GyroDegrees)
{
LeftDrive.spin(directionType::rev); // Assuming this is the polarity needed for a clockwise turn
RightDrive.spin(directionType::rev);
}
//Stop motors after reached degree turn
LeftDrive.stop();
RightDrive.stop();
}
Even with the vex::task::sleep(1000); it still just continuously spins. Is the function solid like should it work because at the moment it just continuously spins.
@jpearman So I was not able to test it, but I’m assuming this should work and turn 90 degrees correct?
//Gyro Turning Clockwise
void GyroTurnCW (double DegreeAmount, int veloc)
{
//Set speeds of both Drive motors
LeftDrive.setVelocity(veloc,velocityUnits::pct);
RightDrive.setVelocity(veloc,velocityUnits::pct);
//Prints the DegreeAmount for debugging puroses to ensure that it is going for the right degree amount
Controller1.Screen.clearScreen();
Controller1.Screen.print(DegreeAmount);
//While loop to do the spin
while (Gyroo.value(rotationUnits::deg) <= DegreeAmount)
{
LeftDrive.spin(directionType::fwd); // Assuming this is the polarity needed for a clockwise turn
RightDrive.spin(directionType::rev);
this_thread::sleep_for(10);
}
//Stop motors after reached degree turn
LeftDrive.stop();
RightDrive.stop();
Controller1.Screen.clearScreen();
Controller1.Screen.print("Gyro Turn Finished");
}
void autonomous( void ) {
// ..........................................................................
// Insert autonomous user code here.
// ..........................................................................
int FullSpeed = 100;
int ThreeFourthsSpeed = 75;
int HalfSpeed = 50;
int FourthSpeed = 25;
while (Gyroo.isCalibrating())
{
task::sleep(100);
}
vex::task::sleep(1500);
//Test of GyroTurnCW
GyroTurnCW (90,FourthSpeed); //Should rotate counter clockwise for 90 degrees at 25%
may I ask you question? Is there a way to clear the gyro like in robotic? Somrthing like setting gyro to 0.I have been looking through the help page and can’t seem to find any function other than getting the current value and seems like the value range of the gyro is from -180 to 180 so when I add value to it it will overfill after for say two turns.
So I was looking at other threads mainly this one Encoder Ticks for V5 which showed how you clear the motor encoder. I looked through the command reference and found vex::gyro.startCalibration . Although this is in C++ Pro would it not still work for the Vex C++? (I haven’t had a chance to test it yet)
Gyro.startCalibration() starts the calibration of the the gyro, and requires the robot to be perfectly still for ~1 or 2 seconds, so it’s not a realistic option for resetting the gyro in the competition. In practice the best method seems to be taking the current reading, and then adding a new target value and waiting until the gyro reaches that value, or something along the lines of that.
That’s what we’ve been doing but it’s been finicky and for whatever reason after we reach 360 it won’t turn anymore. So I was hoping there would be a true reset command without requiring 2 to 3 seconds of stillness.
There’s no way to clear the gyro (IIRC). The gyro returns values in the range +/- 3600. When it reaches either end it will roll over, for example, it would roll over from 3599 to 0. You can write code to allow absolute gyro values and perform reset, but that code would be written on top of the provided API, I believe this was true for ROBOTC also (this gyro class was written to more or less mimic ROBOTC).
edit: you can recalibrate the gyro, but as others have said, the robot needs to be stationary during that time.
Back in robotc because I don’t need it to be cumulative I would just give the gyro value of 0 before my turn and start from there. The problem in c++ is there doesn’t seem to be a function to set the value for gyro
I have tried the routine and when asked to do a 90 degree turn the robot consistently overturns 16 degrees. gyro reading on screen is 106 degrees. Can you help