Getting a rough heading from the magnetometer
Now that we've got calibration settings, we can start using magnetometer readings to estimate where North is, like a compass. The words heading and yaw mean the same thing —which way we face relative to a reference point—in this case, magnetic North. Let's see how we can do this. Have a look at the following screenshot:
Figure 16.15 shows a method we will build. It takes the magnetometer with calibration data applied and uses atan2
, as we did with the gyroscope to approximate the heading. We can also add a rough compass with it too.
Let's make this, as follows:
- Create a
plot_mag_heading.py
file. Start with the imports, as follows:import vpython as vp from robot_imu import RobotImu from delta_timer import DeltaTimer import imu_settings
- We can initialize the
RobotImu
with the settings, like this...