Adding a Magnetic Compass

Our current pose estimation (forward kinematics) process is based solely on wheel encoders. This method is prone to drift and will become less accurate over time. To improve our process we will add a magnetic compass.

What you will learn

  • Simulate a noisy actuator/sensor
  • How to add a compass to our pose estimation (localization) system

Terminology

localization
The process of determining the pose of a robot in a given environment

Lecture

Introduction to using a magnetic compass

Using the magnetic compass Arduino library

Interactive

Exercise

You will now implement an improved pose estimator by incorporating both odometry from the wheel encoders and a heading from the magnetic compass.

  1. (Tuesday) Update your simulation and run a compass example.
  2. (Thursday) Implement sensor fusion on your robot.

You will submit your responses on gradescope. Only one partner should submit. The submitter will add the other partner through the gradescope interface.

Additional details for using gradescope can be found here:

You should open the gradescope assignment now so that you know what to work complete.

Grading

I will grade all exercises using a scale of “Nailed It” / “Not Yet”. See the course grading policy for more information, and check gradescope for deadlines.

Overview

In this exercise you will start by updating your simulation from chapter 16, and then you’ll run an example sketch provided by the compass library.

Simulation

Your main loop should look something like this:

while t < TIME_END:
  pose = forward_kinematics(v_left, v_right, dt)
  v_left, v_right = position_control(pose, GOAL)
  t = t + dt

In the current version of your simulation, you assume that the values for v_left and v_right are true. You should now update your code to include noise in these values. This will simulate that the sensors are readings are imperfect (or alternatively that the robot’s actuators are not perfect). You should use a Normal distribution to “perturb” the values of v_left and v_right.

You will will then simulate the following scenarios and generate plots to upload to gradescope.

  1. No noise
  2. Noise in the left wheel only
  3. Noise in the right wheel only
  4. Noise in both wheels

Try different values for the standard deviation of the noise and report on your findings.

Magnetic Compass Library

To get started with the magnetic compass, you will do the following:

  1. Install the library.
  2. Attach the compass to your robot.
  3. Run both the azimuth and xyz sketches and record the outputs for four known orientations.
  4. Run the calibrate sketch and record the outputs.
  5. Rerun both the azimuth and xyz sketches at the same orientations as before but this time with the calibration method call.

Report on your findings on gradescope.

Wrap-Up

In the second part of this exercise, you will implement “sensor fusion” to combine the wheel encoders and compass data to improve your robot’s pose estimation.

Resources