I am using the MotionFit SDK revB board with the default firmware. I have developed my own software to obtain the quaternion outputs via the virtual serial port. In my application I convert to ZYX euler angles. If the sensor is laying flat on the table, rotations about Y and X are 0, and rotation about Z provides the heading.
In the eMPL documentation (DOC-eMPL-FS-V1.0), it says
inv_get_heading_float is used to get single number representing the heading of the device relative to the Earth, in which 0 represents North, 90 degrees represents East,and so on. The heading is defined as the direction of the +Y axis if the Y axis is horizontal, and otherwise the direction of the -Z axis.
Will inv_get_heading_float return the same heading obtained from inv_get_quaternion or inv_get_rot_mat?
I do not yet have the developer tools to make changes to the firmware, so I can't test this myself.
The reason I ask this is because the initial heading I get (obtained from quaternion) when turning on the device (and letting it sit for several seconds), does not seem dependent on the direction of the Y-axis with respect to North. If I turn on two devices in different orientations, and then move them into exactly the same orientation, they do not output the same heading.
I know that my conversion to Euler angles is correct because I can move the board in all directions and I get the expected rotations.
I can see this when running the teapot app as well. no matter which way the device is oriented (but flat) on the table, before hitting 'enter', the teapot handle is cocked 30-40 degrees to the left (assuming i did not move the device after turning it on). Clearly the initial heading orientation for the quaternion is not Y-axis relative to North, but its also not 0 relative to the orientation when turned on. So where does it come from?
Also, when I rotate the device exactly 360 deg, the resulting heading is about 8deg off...this adds up every time I rotate the device in the same direction. When I rotate the device in the opposite direction it subtracts. Clearly there is some drift. I thought the magnetometer (when no motion is detected) would correct the drift.
I'm avoiding testing the device near ferrous metals as I know this will affect the magnetometer reading.
Thanks for any input!
Re: Re: Initial heading (from quat) on start up
Get heading will return the euler angle associated with the device orientation w.r.t. north direction, irrespective of tilt angle. It does not provide an orientation matrix.
The example application provided on the SDK board, as written, will default to 6-axis operation, until a compass calibration is performed. After startup, you need to do a “figure 8” motion with the device. It will collect magnetometer data, then auto-calculate the mag. field bias and provide a correct direction.
Try rotating the device in all axes, then check the rotation accuracy.
Re: Re: Initial heading (from quat) on start up
Can you describe this "figure 8" motion in more detail? Does this automatically start the compass calibration? If not, how do I start the compass calibration (in the teapot app or my own app) using the default embedded firmware.
from manual:
I don't actually see it drift...It just always starts with handle cocked to left (assuming flat on table, and not moved after turned on).
Re: Re: Initial heading (from quat) on start up
I looked at the embedded firmware code in more detail and realized I can get the heading.
Using RealTerm, or similar serial program, I send 'mfs' 4 times to mode change to compass:
INV_NINE_AXIS -> mfs
INV_SIX_AXIS_GYRO_ACCEL -> mfs
INV_THREE_AXIS_GYRO -> mfs
INV_THREE_AXIS_ACCEL -> mfs
(INV_THREE_AXIS_COMPASS)
I then send 'mfm' to get the magnetometer readings
The response (in hex) is:
Note it will give new readings until 'mfm' is sent again.
the first line is raw magnetometer values (0x6D='m'). These change when I move the sensor.
the second line is the magnetometer biases (0x63='c'). These are always zero for some reason
the third line is the heading (0x68 = 'h'). This is always 0xB4 or 180deg, until 'mft' is sent.
'mft' causes a call to inv_self_test_calibration_run
After 'mft' is sent, the heading is always reset to between 26 and 29deg no matter which way the device is oriented (but flat on table)
How do I get the actual compass bearing?
Re: Re: Initial heading (from quat) on start up
Calling "mft" should wipe the current bias values, then perform a gyro / accel cal, and default back to 6 axis, giving a default start-up orientation. For a correct sensor heading, you should turn on the device, perform a "figure 8" by manually picking up and moving the device, then you should be able to see the correct heading from the eMPL "get heading" function. To simplify for your testing, you could store the compass calibration values in flash memory and set the compass bias on offset with the provided eMPL api's. The sample application we provided will store accel / gyro biases on exit, and load on startup, but you'll have to do store / retreive the compass values by yourself.