Log in

View Full Version : How do you make the robot turn a perfect 90


eccmaster
12-01-2008, 17:56
Hello

How do you use the gyro and easy C to make a 90 degree left?

mluckham
12-01-2008, 23:12
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!

gnormhurst
16-01-2008, 20:54
During the initial debugging of the code I would start by only printf-ing the values that I would send to the motors, but keep the motors stopped by sending them 127's instead. That way I could be sure the code was doing something reasonable. You could manually rotate the robot and watch how the code reacts.

When the printf-ed values look reasonable, change the code to send the values to the motors and PUT THE ROBOT UP ON BLOCKS so the wheels can't touch the floor. Then you can see which way the wheels are spinning (it's easy to get things backwards!) Again, you can manually rotate the robot and see what happens.

Only when everything looked reasonable after those tests would I let the robot spin for real.

Here's another important tip: don't screw the serial cable into your computer -- just push it in and leave it loose. That way, if the robot yanks on it, the computer won't go flying. The same goes for the serial connection to the robot -- don't screw it in, or it may yank the RC hard and do some damage.

Consider looping the serial cable around something solid on the robot so the force of a "yank" doesn't make it all the way to the RC. And likewise on the computer end: strain-relieve the cable to something solid so your computer won't feel the yank.

We've ordered a $99 wireless interface kit (http://store.digi.com/index.cfm?fuseaction=product.display&Product_ID=622) from Digi (was MaxStream). If it works it will get rid of that cable altogether!