V5 and the Gyro sensor

Many people have managed to use the gyro sensor, there is nothing inherently difficult about it.
However, this is why I think gyro is not the best solution for V5:

Yes, when the code starts, the gyro goes through a calibration process that requires the sensor to be completely still. That should just happen on startup, and you should not have to worry about it in autonomous unless you create the sensor right before you start autonomous, which is bad structure.

When dealing with sensors, you should never have to reset them. Doing so is a blunt and inefficient way to deal with relative angles.
Instead, the solution is to take into account the current position of the gyro to convert your relative angle into an absolute angle.
For example:

//given wanted angle of 90 from current position
int wantedAngle = 90;
//instead of setting gyro to 0 and turning until gyro reads 90
//find angle that is 90 away from current angle
int target = Gyro.value(rotationUnits::degrees) + wantedAngle;
//now you can use that value as your target

Also, there is a way to simplify the logic in a code such as this. This is just a suggestion, but it helps with neatness.
Instead of providing logic that takes into account direction, if you use some simple math, you can reduce the complexity of the code. For this, you don’t need to specify the direction, just a negative angle.

void gyroTurn (int angle) {
 int target = Gyro.value(rotationUnits::degrees) + angle;

 int error = 0; //represents value between current angle and target angle
 //do-loops loop at least once, we are using it to calculate error
 do {
  error = Gyro.value(rotationUnits::degrees) - target;
  if(error < 0) {
   //turn right
   leftDrive(25);
   rightDrive(-25);
  } else {
   //turn left
   leftDrive(-25);
   rightDrive(25);
  }
 } while(abs(error) < 10) //exit when error < 10
 stopHold();
}

Anyway, just a suggestion to make things neater. If you wanted to do a P (proportional) loop to increase speed, you could just replace the if/else for the direction with

leftDrive(-error * constant);
rightDrive(error * constant);

which would go faster the further you are from the goal and slower the closer you are. You would tune the constant to provide the relation between distance from goal and motor power.

Small little nitpick, if(turnRight==true) is redundant :slightly_smiling_face:
It is cleaner to do if(turnRight), as before you are basically typing if(true==true), which is redundant. If you want it to return false when the output of the evaluation is true, you can do if(!turnRight) which translates to “if not turnRight”.

Finally, when you post code on the forum, please format and wrap your code in little

```cpp

//your code here

```

code tags, it helps with readability.

Hope this post was able to teach someone something.