Driving Exact Distance During Auton

Our problem is that our auton is inconsistent. We coded it so that it’s supposed to drive towards the first neutral goal, clamp it, turn, and drive towards the middle neutral goal. The problem is, sometimes our robot drives forward and turns the number of degrees it’s supposed to and works, but other times it misses the middle goal. I think the problem is that the robot is driving too far sometimes or too short sometimes so then when it turns, it misses the goal. Is there a way to drive an exact distance so we are aligned with the middle mogo consistently?

Code:

Gyro1 is an inertial sensor

What drive train is your robot? The issue would likely be different if it was an x drive compared to a tank drive or anything else.

Its a 4 motor drive train

Where in the code do you notice the issue occurring?

We drive forward, we turn, and then we drive backward and miss the goal so it is either a problem with the turning or with driving to the first goal. The motors are at 100% velocity at the very beginning when they are driving towards the first MOGO.

Lots of mechanical issues could cause it to be less consistent. There could also be issues with the gyro. And there are things that you could do to improve your code.

Mechanical issues will mostly be friction, but it could be a lopsided wheel, bent shaft, loose chain, or a poorly mounted motor.

For the gyro, make sure that it has been calibrated before running the auton, and that the robot is in the starting position when calibrated, and that you don’t touch the robot during calibration. If you are testing your auton with a competition switch, then your auton calibration needs to be performed each time you set up the robot. Don’t just reset the robot and enable auton again without restarting the program or somehow re-calibrating the gyro. Gyros can also experience drift, where the value gets more inaccurate over time. Vibrations can cause drift. So ramming into that first goal will make gyro reading less accurate.

In your code, the motors are only at 50% when turning. You are probably doing that because 100% turns were much less accurate. To make the turns more accurate, you could slow them down even more. Of course, the tradeoff there is that someone else beats you to that center goal, or you can’t get there in 15 seconds. So how slow do you need to get an accurate turn without too many other tradeoffs?

One programming technique is to start fast and then slow down as you get closer to your target (the angle you want to be at when your turn finishes). PID is a common way of implementing this technique. The P in PID is for “proportional”, and for your turn, the speed would be adjusted in proportion to the distance from the target angle. A simple way of doing this, without PID, would be to take your turn in two or three stages. So you might start at 80% until you get to within 20 degrees of your target angle, and then slow down to 20%. Get the idea?

5 Likes

Thanks, I’ll make sure to test some of that out tomorrow

The code looks fine, although it could use a few improvements. My guess is an inconsistency with the robot or a sensor. I agree with what jrp62 said. Most likely an issue with the inertial sensor or something like a loose wheel. I would recommend giving you’re robot a close inspection tomorrow to see if you find any issues. If everything seems to be fine you could tweak the code a bit to make the turn more accurate by following the steps jrp listed. Good luck!

2 Likes

I think that it could definitely be a mechanical issue, however, if after a thorough check you can not find a problem, there are some things you could do for the code. I always used to have a super similar problem to this with inconsistencies in the auton. A lot of it is just unavoidable because of the inconsistent nature of the vex motors. I would recommend writing a PID so that you can ensure that your robot is consistent. This is a challenge, but there are a ton of resources online that explain it. Basically, it continuously checks the position of the robot and makes changes to its speed accordingly. If you want to try this and have any questions I can give you the resources I used and help you start with the code.

2 Likes

We slowed down the speed while it was driving forward and now it works great. Thanks Everyone!

3 Likes