VEEK-MT2 User Manual
44
www.terasic.com
July 4, 2016
Figure 4-19 Block diagram of the e-compass demonstration
In the NIOS II program, the graphic interface is implemented in the gui_gsensor.cpp. The MPU9250
class (implemented in MPU9250.cpp.h) is used to retrieve accelerometer information from the
MPU9250. The member function initialize should be called before calling any other member functions.
In this demonstration, the member function getMotion9 is called to get the gravity value of X/Y/Z. The
function Light_Init is designed to initialize the sensor APDS-9300. The function Light_GetID is
designed to get the chip ID of APDS-9300. The Function Light_Get_ADCData0 and
Light_Get_ADCData1 are designed to get the two ADC values in APDS-9300.
The section introduces the method to calculate the heading angle based on the values measured by
accelerometer and magnetometer in this demonstration. If the compass is on a flat surface, then heading
angle can be calculated with the following formula:
arctan(Xh/Yh)
where X
h
and Y
h
are the magnetic field in X and Y directions. If the compass is not on a flat surface, the
X
h
and Y
h
can be calculated with the following formula:
X
h
= mx * cos (pitch) + my * sin (roll) * sin(pitch)
– mz * sin(pitch)*cos(roll)
Y
h
= my*soc(roll) + mz*size(roll)
Where mx/my/mz are the measured valued by the magnetometer in the MPU9250. The pitch and roll
can be calculated by the gravity valued measured by the accelerometer in the MPU9250.
Содержание VEEK-MT2
Страница 1: ...1 ...