I have to say that I’m a noob at C++ and have never used a gyro. Suppose I have a gyro in the middle of the bot and I want to use it to perfect the turns in the autonomous. What would be the steps to approach that? I’m guessing before anything else, I have to clear the gyro every time before a new turn of its previous values. Also, I’m guessing I have to calibrate it too. I’m looking to make a function that I would pass the degree of the turn to and the robot would do it at 50% power to not overshoot. Also, do I need to use positive and negative degrees for different side turns?
This is my view of how it should be layed out:
void turn (double degrees_to_rotate){
double current_deg = Gyro.value(vex::rotationUnits::deg);
while (current_deg < degrees_to_rotate){
current_deg = Gyro.value(vex::rotationUnits::deg);
FrontRight.setVelocity(50,vex::percentUnits::pct);
FrontLeft.setVelocity(50,vex::percentUnits::pct);
RearRight.setVelocity(50,vex::percentUnits::pct);
RearLeft.setVelocity(50,vex::percentUnits::pct);
if (degrees_to_rotate > 0){
FrontRight.spin(vex::directionType::rev);
FrontLeft.spin(vex::directionType::fwd);
RearRight.spin(vex::directionType::rev);
RearLeft.spin(vex::directionType::fwd);
}else if( degrees_to_rotate < 0){
FrontRight.spin(vex::directionType::fwd);
FrontLeft.spin(vex::directionType::rev);
RearRight.spin(vex::directionType::fwd);
RearLeft.spin(vex::directionType::rev);
}else{
FrontRight.stop();
FrontLeft.stop();
RearRight.stop();
RearLeft.stop();
}
}
}
And when i need to call the void:
turn(90);
If there are any errors to be corrected or any way to improve this bit of code, plz comment.
Thank you.