How do I work with more complex auton tech like inertial sensors, odometry, and PID?

This is my 2nd year as a programmer for my team, and I just recently found out about the magic of the various sensors for auton. I’ve only ever worked with giving specific drivetrain commands through driveTrain.drive_for() an driveTrain.turn_for()

I’ve been hearing about Inertial Sensors, Rotational Sensors, Odometry, and PID but I don’t know what any of it does or how to use it. How would I use these to keep auton on track and program it faster? What things do I need to know to start working with this stuff?

Any help is appreciated, thanks!

I’m going to explain things more from the software side because that’s what I do. You can find other tracking wheel tutorials on the internet.

You can always use VEXCode’s built in drive_for and turn_for functions when using VEXCode for simple driving based on dead reckoning. That means that your robot has no idea where it is (V5 motors have integrated encoders, but I’m going to ignore that for now) and it’s just going wherever you tell it relative to its last position. However, because of things like wheel slip and running into game objects, there will always be a degree of randomness preventing you from knowing your exact position.

In comes the inertial sensor, which has a 3-axis gyroscope built in. (You can also use the old 3-wire cortex one too.) It helps your robot be able to make precise turns, because you can feed in the absolute heading* given by the sensor into a feedback algorithm like PID. That allows you to have an absolute frame of reference for rotation.

However, you may also want to know where you are on the field at any given moment, and as I mentioned earlier, the integrated encoders aren’t the best. Therefore, many teams use a dedicated tracking wheel to track forward and/or strafing/horizontal movement. With a bit of math, you can know where you are on the field all the time, allowing you to build faster and more precise autonomous routes that don’t get “messed up” by a stray game element. Motion profiling and path following is another topic that stems from this.

Many teams use things like EZ Template or LemLib to do the math for them and use a website to generate paths for their routes (those are PROS templates), but in my humble opinion, it’s a good learning experience to derive everything yourself.

* I understand that the sensor itself is just integrating the turn rate, so it’s not exactly absolute.

4 Likes

Thanks, that explains A LOT.

Do you know of any resources I can use to learn more about how to implement these sensors and algorithms to make self correcting / more accurate and quicker auton?

I don’t know much about Odometry and Rotational sensors, but my team does have a PID. Search up PID Controllers and watch a few videos. Also, check out this link and scroll down until you see “An introduction to PID Controllers” from the VEX Forum. It will help you download a really useful document that explains PID.
Finally, there is a vex forum that explains exactly how you can code a PID by @Connor. The link for the tutorial is here.
The only way I use the inertial sensor is to track how many degrees I turn using the following commands.
image
image
image

I do not use the inertial sensor for lateral PID. Instead, I just use the position of the motors.
Ex.

Hopefully this helped, and if you have any questions, I might be able to answer them. I am not in high school, so I may not be able to answer questions I don’t know the answer to.

I found that video by Connor yesterday, it was SUPER helpful. I’m reading that doc now.

So when you use the inertial sensor to determine how many degrees you have turned, what do you use that info for? Like how does knowing how many degrees you have turned help you?

Suppose you want your robot to turn to an angle of 90 degrees. The inertial sensor can tell you if you’ve turned to an angle of 90 degrees or not.

The SigBots Wiki has some good resources on PID: PID Controller | Purdue SIGBots Wiki

I usually have people watch this video when I teach PID: https://youtu.be/4Y7zG48uHRo (it’s my personal favorite, and it has a great real-world example).

Essentially, for any kind of control loop, you need some kind of feedback on how well your control is working. For example, if you are turning and apply some amount of voltage to the motors, you will need to know how far you have turned to calculate how much voltage you need to apply now in response. Just applying voltage isn’t good, because the real world isn’t perfect and applying the same amount of force isn’t always going to do the same thing.