Help accurately using the inertial sensor

Hi,

I recently saw a video of a 301 point prog skills and the person who made it said that they were using PID and the inertial sensor. In my programs, I currently use PID along with tracking wheels, and it works quite well for distances. The program always drives in a straight line and is within a couple centimeters of its target every time.

The main source of error in all of my programs is turning. For my turns I use the initial sensor’s heading to find my position. This usually works quite well for the first part of any run, but on some runs it quickly loses accuracy. Here are some examples:

In our programming skills autonomous, around 30 seconds in, we go to grab a neutral goal. However, the angle the robot goes to grab the neutral goal at is sometimes off by 2 degrees on either side and misses grabbing the goal as a result.

In one of our elimination autons, our robot rushes a neutral goal. It quickly comes back over to our home zone and turns to pick up our alliance goal. Sometimes this turn is off by over 10 degrees not even 10 seconds into the program. Our back lift is quite forgiving and we pick it up almost every time, but I am unsure how the program loses so much accuracy so quickly.

I am fairly certain it is not an issue with my “turn to” function. It is very simple and it prints the gyro heading on the screen. Every time the program turns, it thinks that it turned the correct amount. It usually says that it is within 0.1 degrees of were it is supposed to be. I know I am not using PID to make my turns, but I think the error is coming from drift not any errors with my turn.

Here is an example (Gyro is the name of the inertial sensor):

while(Gyro.heading() > (168)) {
  leftFront.spin(reverse, 10, percent);
  rightFront.spin(forward, 10, percent);
  rightBack.spin(forward, 10, percent);
  leftBack.spin(reverse, 10, percent);
  Brain.Screen.clearLine();
  Brain.Screen.print(Gyro.heading());
}
Drive.stop();

Every time the robot makes this turn it says the heading is around 168 degrees (within 0.1 degrees). However, sometimes it is off by 10 degrees of were it is supposed to be.

I think that the issue with this is drift in the inertial sensor. I make sure to calibrate the gyro before every run. It seems that other teams are not getting the same amount of drift that our team is. Does anyone know why this is the case, and how to prevent it?

Tl;Dr: I think our inertial sensor is getting a lot of drift.
Thanks in advance!

2 Likes

While I have never seen inertial sensor drift this bad, this is my way to fix drift. It works on the assumption that the error changes proportionally.
First, turn the robot 360 degrees manually and measure the value the inertial sensor returns. Recalibrate and repeat this for turning the other way.
Second, declare a global variable of the bot angle (I call mine glblBotAngle)
Third, declare a global function to update the bot angle

void updateBotAngle(){
  //Convert the errors to normal degrees
  double positiveUpdate = 360.0 / (degrees returned from manual right turn);
  double negativeUpdate = 360.0 / (degrees returned from manual left turn as a positive number);
  // The previous inertial sensor angle
  static double lastAngle = 0.0;
  while(1){
    //Get the current angle
    double currentAngle = SENSOR.heading();
    //The change in angle
    double changeInAngle = currentAngle - lastAngle;
    //Update glblBotAngle
    if(changeInAngle < 0){
      glblBotAngle += negativeUpdate * changeInAngle;
    } else {
      glblBotAngle += positiveUpdate * changeInAngle;
    }
    lastAngle = currentAngle;
    task::sleep(5);
  }
}

Then, in main(), declare a thread that takes that function as its argument

thread angleUpdate = thread(updateBotAngle);

Now, rather than using Gyro.heading(), just use glblBotAngle

5 Likes

Since you are already using tracking wheels, why not just calculate the heading with them? It almost eliminates drift entirely and is much more accurate.

1 Like

I don’t believe this is the case for us. There does seem do be a relatively consistent amount of drift, but some of it is variable. For example, it one of our programs, I need the robot to turn 90 degrees, however, in order for it to actually do that, I tell it to turn 103 degrees.

Our robot only has 2 tracking wheels. I don’t have a sideways wheel, because our drive can’t strafe and we have locked omnis.

A sideways tracking wheel is not needed for calculating orientation. The equation is as follows: Δ𝜃 = (Δ𝐿 − Δ𝑅) / (s_L + s_R). This equation does not require the perpendicular wheel and you can calculate the orientation using only the left and right tracking wheels.

1 Like

What do s_L and s_R stand for?

s_L is the left-right distance between the left tracking wheel and the tracking center and s_R is the left-right distance between the right tracking wheel and the tracking center. The sum of these is essentially the track width, or the distance from the left tracking wheel to the right tracking wheel.

3 Likes