Inertial Sensor vs PID

Yes but he is responding to my Q

Also does the Inertial Sensor have to be put on the center of the robot?

My apologies for not answering your question properly. In regards to that, the “distance remaining to get to the target” is a bit confusing. Let’s say I am -100 feet from a target. If applied on a GPS, it will always tell me my distance remaining is 100 feet (and never -100 feet). So, if that makes sense, it just seems confusing to say distance remaining. I stated what I said to more or less clarify what you’re trying to explain.

oh, ok. I did forget to clarify that distance does matter (assuming you want the bot to, you know, work) :sweat_smile:

making it centered saves you a lot of math, so do it if you can (I just put mine in the bottom of the bot and vibrations from the chassis barely affected it)

I used p loops (pid would be better) based on inertial sensor reading for the 68 pt program I ran at MD states. when you don’t have tracking wheels, inertial + pid would be more consistent than pid only.


Just to clarify for anyone confused, PID is not an algorithm isolated to only lateral movements. PID is a general algorithm that can be implemented for any system that needs to achieve a certain state. For most vex applications, PID is used to get a chassis to a certain position on a field. But PID can be used for things like keeping the temperature in a room constant, or maintaining the position of an arm . Wording such as “PID + inertial” makes it seem like you’re somehow combing two different algorithms.

TL;DR the wording on the name of this thread should be changed and a lot of the conversation going on in this thread can be misleading. It should be something like "What sensor should I use to control turns with PID?"

Note PID is a closed loop, feedback based algorithm meaning you’ll always use some kind of sensor as feedback. There will never be a case with PID where a sensor isn’t being used for the system to respond to.


I’m assuming it doesn’t, since all points on the body rotate by the same amount regardless of its position.

1 Like

Hi there! I’m pretty new to PID loops and inertial sensors as well. I think I understand that PID could be used for lateral movement. So for turns, I’m kind of confused about how I could program the inertial sensor; I looked at the VexCode example code but it didn’t really help. Also, once I do figure out the inertial sensor code, would I just run the PID and inertial sensor as needed in the autonomous task? My main question here is how would I code an inertial sensor?

Thanks, AD24

1 Like

I would say that you need to take a few steps back and answer a few fundamental questions:

  • What does an IMU actually do?
  • How does this apply to the robot?
  • How can I use the relationship between the IMU and the robot to control the robot?

I’ll answer each to make it clear how your thought process should be when solving these kinds of problems instead of just seeking a copy and paste answer.

The IMU is simply a sensor that measures a change in rotation (usually in degrees) of a body it’s attached to. The geometry and shape of the body does not affect the net angular displacement the sensor measures (if the body is fully rigid).

This applies to the robot because the sensor is mounted rigidly to it. The mechanism (for lack of a better word) that allows the robot to turn is a differential-style chassis (tank drive). So by spinning the left side in one direction and the right side in the opposite direction, you can rotate the robot and it is then measured by the sensor.

So how can I create a relationship between the sensor and the mechanism I want to control?
if(!atAngle) //while the robot is not at the desired angle
robot -> spin
robot -> stop

So, with a basic control structure, you can use the sensor values and relate it to rotations of the wheels on the base. Implementing PID in this is essentially the pseudocode with a lot more math. But the basic premise is sort of this: while the robot is not at the target angle, spin towards angle. If you want more insight on the math then look here are all the resources you could need (and feel free to ask more questions):


A PID is basically a series of function that help a program run faster and more effectively.

  • P is the proportional value
  • I is the integral value
  • D is the derivative.
    You can use it for both turning and lateral movement but the purpose of this thread was to see if using an Inertial Senor was more viable than a turn PID. There are many other threads on the forums about this topic.
    If you do not have any prior experience with coding, I would first get the basics down and use an inertial sensor.
    The logic behind it would be something like this.
if ( angle != desiredAngle ) 

Ok, so I took the approach that you gave me and I think I got how to use the inertial sensor. So would you recommend using PID for lateral movements? I think I want to use an inertial sensor for turns definitely since I don’t think I understand turns with PID.

Gotcha. I think I figured out how to use an inertial sensor now. I’m still considering using PID for lateral movements though. Would you recommend this? And also do you think a PD control loop would be more effective than a PID control loop?

1 Like

Yes using a PID will greatly increase your auton score.
Without the integral controller your robot may not reach the target value sometimes but people still find a way around it.
Using a PID controller is better than a PD controller just because of accuracy.

1 Like

Ok that makes sense. I think I’ll use a PID controller in that case!

1 Like

Not really… It’s decreases the settling time of the controller and prevents steady state error. If you look more into PID this will make sense. The resources have been linked above


I know this is kind of off topic but is an inertial sensor more accurate than the old gyroscope for turning?

1 Like

Yes and no. I think both return the same degree of precision or at least more than you’ll need for a robot. Both are prone to drifting, but it’s been reported that the IMU drifts less. Correcting for drift has something to do with integrating error over time from the drift rate calculation during calibration (or something along those lines). I haven’t done this so don’t ask me how it works, but I have used the IMU for over a year now and haven’t really had any serious issues.

There’s more thorough discussion here, but you can always ask @jpearman for specifics


This resource from George Gillard is very helpful in understanding PIDs.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.