gpsPositionToUtm (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Firmware version:

2.80 / 1.00.00


This function is used for converting a position from RTCU format to Universal Transverse Mercator (UTM) format.

 

For the calculation, the WGS-84 ellipsoid is used to model the Earth in the UTM coordinate system.
 

 

Input:

lat : DINT [-80000000 .. 84000000]
Negative is south (ddmm.mmmm (multiplied by 10000)).

 

lon : DINT [-2147483648 .. 2147483647]
Negative is west (dddmm.mmmm (multiplied by 10000)).

 

 

Output:

zone : INT
UTM zone number.
>0        The position is on the northern hemisphere.

<0        The position is on the southern hemisphere.

 

east : DINT
UTM easting coordinate in meters east of the central meridian of the zone.

 

north : DINT
UTM northing coordinate in meters north of the Equator on the northern hemisphere. On the southern hemisphere, it is 10,000 km minus the distance to the Equator.

 

 

Return:

0        Success.
-1        Invalid input.

 

 

Declaration:

FUNCTION gpsPositionToUtm : INT;
VAR_INPUT
   lat    DINT;
   lon    DINT;
   zone   ACCESS INT;
   east   : ACCESS DINT;
   north  ACCESS DINT;
END_VAR;

 

Example:

INCLUDE rtcu.inc
 
PROGRAM sample;
VAR
   gps         : gpsFix; // Receives information from GPS module
   report      : TON;
   zone        : INT;
   east,north  : DINT;
END_VAR;
 
// Activate power to the GPS module
gpsPower(power:=ON);
BEGIN
   gps();
   IF gps.mode >= 3 THEN
      report(trig := NOT report.q);
   ELSE
      report(trig := FALSEpt := 0); // report first gps fix fast
   END_IF;
   IF report.q THEN
      report.pt := 2000// report each 2nd second
 
      DebugMsg(message := "GPS position:");
      DebugFmt(message := "   latitude = \4", v4 := gps.latitude);
      DebugFmt(message := "   longitude = \4", v4 := gps.longitude);
      
      gpsPositionToUtm(
         lat := gps.latitudelon := gps.longitude,
         zone := zoneeast := eastnorth := north);
     
      DebugMsg(message := "UTM position:");
      DebugFmt(message := "   zone  = \1", v1 := zone);
      DebugFmt(message := "   east  = \4", v4 := east);
      DebugFmt(message := "   north = \4", v4 := north);
   ELSE
      Sleep(delay := 500);
   END_IF;
END;
END_PROGRAM;