|
Re: How do you make the robot turn a perfect 90
Get the gyro working (outputting values using printf, which change as the gyro is rotated manually) first. Observe the difference in value as the gyro is rotated 90 degrees.
Now mount the gyro at the centre of your robot ... if the gyro isn't on-centre, you might get drift errors that affect your value.
Rotate the robot in-place manually, watching again that your gyro output values and reconfirming the DIFFERENCE in value at the 90 degrees rotation point.
Add some code that subtracts the original (stationary) gyro value from the current gyro value. When this difference equals the 90-degree value you observed, that's when you want to stop the robot spin.
Now things get a little harder because you have to accelerate and stop the motors precisely before you overshoot the 90-degree turn.
This should get you started:
To spin the robot set the left and right motor PWM outputs to opposite values - so that the robot spins in place. Use low values, for low spin rate. For example 127 - 20 for the left PWM, and 127 + 20 for the right. Depending on motor factors, one motor may actually run faster than the other and you won't get a precise on-axis spin - but it will be good enough for now.
When your gyro-checking code sees that the difference value is approaching the 90-degree value, send 127 to both motors to stop them. If the BRAKE jumper is installed in the motor Victors, the robot should stop smartly.
Cautions - your code may cause the robot to spin in an unexpected direction, at an unexpectedly-fast speed, or out of control. You probably will have the programming cable attached to your laptop - be careful the spinning robot doesn't pull it out or catch the cable! Be ready to emergency-abort the run (removing power from the Operator Interface should do it, if you don't have a Competition Dongle).
Good luck!
|