Help with GyroSensor and turning

Hi there,

We are having an issue turning the robot 90 degrees and need some help.

If you look at the pic below when we run the code the robot is supposed to stop when the gyro sensor reads 90 degrees and then raise the arm (line 6,7,8,9). However the robot is turning about 200 degrees.

When we take line number 9 out the program runs fine. Any reason why the robot is turning more than 90 degrees when we add line 9.

cf61d85039ca8676d6332f4364a37dde.jpg

I don’t know why line number 9 would make it not work, but I would caution to never use the ==. If it so happens that the gyro skips over the exact ‘90’ (which it will do), it won’t work. I advise my teams to always use >= or <= . Then, if it misses 90, but hits 90.2, it will still stop.

Im a bit stumped too. Thanks for the advice on the ==

I figured it out. You are turning on your motors in lines 6 and 7. You are then waiting until the turn is over… but you don’t turn off your motors. Then in line 11 you recall those specific motors, and tell them to do something different. So, without line 9, it waits until they have turned, and then it goes forward. With line 9, it waits until they have turned to start moving the arm, but the motors aren’t being turned off. So, while the arm is moving, it is still turning. Then at line 11, it stops the turn, because it sets the robot going forward. To make it work, you will need to tell it to stop the motors before lifting the arm.

Excellent! So by adding a stopMultipleMotor command after line 8 the robot should stop and then raise the arm. Ill give it a go tomorrow morning. Thanks for your help!

I would also slow down the turn, running at -50/50 is fast (depending upon your gearing. The gyro response is not super quick so take your time.

A couple other things on the gyro. Make sure it isn’t vibrating a lot, kind of depends on your physical setup. In VRC the kids shock mount them in IQ they haven’t.
Make sure the gyro is at the center of rotation for the motors you are using to turn, otherwise it will trace an arc and you will be off.
Keep the gyro as far away from motors as you can. The field generated by the motors can throw the gyro off.

Inertia kills the accuracy as well - the robot stops the motors at 90 degrees but the inertia of the turn carries it a couple of degrees past.
You could add in 3 more lines to your program so the first 60 degrees is done much faster, and the last 30 degrees at -20/20