msCompassHeading (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

All

Firmware version:

1.52.00


This function takes the measured magnetometer readings in the plane perpendicular to the axis passing through the center of the earth and the RTCU device and gives a measure for magnetic north, also called Compass Heading.

Returned value is in degrees.

 

The measured compass heading follows the rules:

If the result is greater than 337.25° or less than 22.5° – North

If the result is between 22.5° and 67.5° – North-East

If the result is between 67.5° and 112.5° – East

If the result is between 112.5° and 157.5° – South-East

If the result is between 157.5° and 202.5° – South

If the result is between 202.5° and 247.5° – South-West

If the result is between 247.5° and 292.5° – West

If the result is between 292.5° and 337.25° – North-West

 

Input:

MagX : FLOAT

The measured magnetometer reading on the X-axis.

 

MagY : FLOAT

The measured magnetometer reading on the Y-axis.

 

Returns: FLOAT

The measure for the compass heading in the range [0.0° - 360.0°[

 

Declaration:

FUNCTION msCompassHeading : FLOAT;
VAR_INPUT
  MagX : FLOAT;
  MagY : FLOAT;
END_VAR;

 

Example:

INCLUDE rtcu.inc
 
PROGRAM example;
VAR
  val     : msDataSet;

  heading : FLOAT;
END_VAR;
 
msOpen();
msMagEnable(enable := TRUE);
 
BEGIN
msRead(data := val);
heading := msCompassHeading(MagX := val.MagX, MagY := val.MagY);
DebugMsg(message:="Heading is "+floatToStr(v:=heading));
 ...
END;
END_PROGRAM;