Hello! To my knowlage, no one had gotten the v5 and the gyro sensor to work. Since my team went to worlds and one of my other teams tried to use the gyro sensor with v5 and failed. I figured I would take a shot at it, and I think I’ve got it working!
The first thing to note is that when your program starts up the gyro seems to take a second to “boot up”, at least from my testing. Any attempts to turn the robot in that time will result in the gyro sensor counting up forever in the value it went towards.
Second thing is that at least in VCS there is no way that I know of, or that is documented, to set the gyro value equal to zero. This led me to develop some interesting code to make sure that it was consistent in using the gyro to auto straightening and turn.
Here is the code I used to control turning using the gyro sensor in VCS
void gyroTurn (int x, bool turnRight) // This void statement controls the gyro turn, it is important to leave one second at the start of auton to allow
{ // the gyro to start up so that it will not count infinately.
int x10 = (x10); // ex of code gyroTurn(degrees you want to turn,true or false if you are turning right);
if(turnRight==true)
{
x10=x10(-1);
}
bool lineup = false;
int gyroValue = Gyro.value(rotationUnits::raw)+x10;
if(gyroValue > 3600)
{
gyroValue = gyroValue - 3600;
}
else if(gyroValue < -3600)
{
gyroValue = gyroValue + 3600;
}
while(lineup==false)
{
if(Gyro.value(rotationUnits::raw) > (gyroValue + 10) || (gyroValue - 10) > Gyro.value(rotationUnits::raw))
{
if(turnRight==true)
{
//turn right
leftDrive(25);
rightDrive(-25);
}
else
{
//turn left
leftDrive(-25);
rightDrive(25);
}
}
else
{
stopHold();
lineup = true;
}
}
}
Also, be sure to mount the Gyro in a spot where it is insolated from the rest of the electronics so that any static electricity would build on the gyro. Try not to use it in driver control since static tends to build up a ton. Make sure before every match to discharge any static electricity by touching the gyro, then touching the edge of the field.