Connection issues with the Gyroscope on v5?


#1

I have been using the gyroscope to turn for a while now. In RobotC, I could get it working mostly consistently. The only issue would be some 1-2 degree error.

We updated to V5, and everything is almost working perfectly. The turning seems just as accurate as before. There’s only about a 1-2 degree error. However, at frequent random times, the robot will turn over 300 degrees too much before stopping. In addition, sometimes it won’t stop at all.

My first assumption was that it was a faulty gyroscope. I replaced it. The problem persists.
I then thought it was disconnecting sometimes, so I replaced the 3-wire cord. The problem persists.

I am completely out of ideas. My autonomous either works perfectly or decides to stop in the middle and do donuts. Any help would be appreciated.


#2

just did gyro stuff today and its working for me, might be your code. Send a snippet of your gyro turns or something here or through hastebin or github


#3

Capture

This is my code for turning. Again, It works just find about 40% of the time. It just randomly will go completely haywire


#4

code seems fine, but I would suggest printing out CV or something to debug. If your drive base overshoots the angle, it won’t try to correct itself by turning back. That could be the issue. Since you set your motors one direction at a constant speed so if you overshoot you have 0 chance of correcting, but im not sure. Your while condition should prevent that.


#5

I’m fine with being off by a couple degrees when we overshoot. My issue is that when we overshoot, it is by over 300 degrees. Based on the code, even if it overshot, it wouldn’t be by that much. The value in the while loop would be false and the robot would stop.


#6

Yeah that’s what I was thinking. Print out CV to check if it is updating properly and make sure the gyro is plugged in all the way


#7

I was having the same problem with our skills. It would work fine for the first 45 seconds but then when we got into the last 15 the gyro would either just go over or drift over by at least 100 degrees. Our codes are different but I talked to a programmer from my school and he said to turn relevant to your last point. Not too sure if this will help you in any way.


#8

Gyro on V5 doesnt continue counting past 360 degrees which could be your issue. Try not to turn in full circles in autonomous.


#9

You can turn in full circles. You just need to handle the overflow. And be able to handle it crossing from the positive regime (0 to 360 when to one side of its starting point) and the negative regime (-360 to 0 when to the other side of start).

So if you were currently reading, say, +270 and wanted to turn +120, you would be looking to turn to (270 + 120) % 360, which gives 30. So you would have to wait for it to rollover (less than starting point) then wait for it to pass the rolled-over target of 30.

The most complicated case is passing over 0, as the gyro can sometimes switch signs when passing 0, but if you’ve gone more than one full rotation since startup its sign will stay the same and wraparound from +/- 360. So when going from, say, +30 and turning by -120, you would either be looking for <-90, or you would be looking for >+30 then <+270.