Dead Reckoning

Back in the days without GPS and other navigational tools there was a navigation technique that was used by airplanes that was known as Dead Reckoning. The basic idea was that if you know how fast you were going and the direction you were traveling, you could keep track of your position.

We are going to use something similar to keep track of our robot’s position when it cannot see the tower.  We have a gyro which will tell us what direction the robot is heading, and encoders on the wheels which will tell us how far it has moved in that direction.  If we check periodically (say every 20th of a second) and compute how far and in what direction it has moved in the X and Y directions, we can keep track of it’s absolute position.

The main trouble with this approach is that each time we do our incremental calculation there will be a small error and, over time, these errors will add up until we have a significant error in the robot’s position.  Fortunately, every time the robot turns so that it can see the tower we will be able to reacquire it’s absolute position on the field.

We are, of course, going to need access to the encoders attached to the drive system.  Rather than using the encoders that are returned directly from our DriveSubsystem class, we are going to create copies which will allow us to control the zero point of the encoders.  First we declare two member variables to hold the left and right encoders:

Then in the Init() function we create copies of the left and right encoders used by the DriveSubsystem. Note the call to the Clone() function.  This returns a copy of the referenced encoder.  This copy still access the same physical device, but has it’s own zero point.

Now each time our Update() function is called we want to compute the distance the robot has traveled since the last call.  To do this we will need member variables to store the previous encoder values:

Then in our Update() function, in the case where we cannot see the tower, we will use the yaw angle and the distance to compute a new X and Y from the previous, as follows:

At the beginning of the function get the current encoder values for the left and right.  Then if we cannot see the tower we determine the amount the left and right encoders have changed since the last call and take their average to get the distance the robot has moved.  Note that we are using the constant k_ticksPerInch to convert from the raw encoder value to inches.  Previously we have found that the robot moves 38.5 inches in 8000 encoder units which means we define k_ticksPerInch to be 38.5/8000.

Next using trigonometry, we compute the change in the X and Y coordinates and add that change to the current position.  Finally we save the left and right encoder values for next time.

Your file should now look like:

Now if we deploy and run our program, we should see the position of the robot changing, even when we cannot see the tower.

Next: Plotting the position

Pierre Pierre, who replica handbag 185cm tall, gucci replica handbags the "Diamond King" in his hermes replica handbags . He has been selected as one of the handbag replica most beautiful 50 people in the "People" magazine. It is also known as replica handbags most elegant and quiet in the world. Unforgettable prince.