gpsDistanceX (Functionblock)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

MX2, CX1, SX1, MX2 turbo/encore/warp, NX-200, NX-400, NX-900, LX2, LX5

Firmware version:

1.00 / 1.00.00


This function block is used for calculating the distance and bearing (direction) between two latitude/longitude positions. Compared to the gpsDistance() function block, gpsDistanceX() expects the latitude/longitude to be expressed in two DINT variables. The gpsDistanceX() function is therefore more efficient to use than gpsDistance().

 

 

Input:

 

Position 1:

 

latitude1 : DINT

Negative is south (ddmm.mmmm (multiplied by 10000)).

 

longitude1 : DINT

Negative is west (dddmm.mmmm (multiplied by 10000)).

 

Position 2:

 

latitude2 : DINT

Negative is south (ddmm.mmmm (multiplied by 10000)).

 

longitude2 : DINT

Negative is west (dddmm.mmmm (multiplied by 10000)).

 

Output:

 

distance : DINT

Distance between the two positions in meters.

 

bearing : INT

Bearing between the two points in degrees.

 

Declaration:

FUNCTION_BLOCK gpsDistanceX;
VAR_INPUT
  // Position 1 parameters:
  latitude1   : DINT;   | Negative is South (ddmm.mmmm (multiplied by 10000))
  longitude1   : DINT;   | negative is West (dddmm.mmmm (multiplied by 10000))
 
  // Position 2 parameters:
  latitude2   : DINT;   | Negative is South (ddmm.mmmm (multiplied by 10000))
  longitude2   : DINT;   | negative is West (dddmm.mmmm (multiplied by 10000))
END_VAR;
VAR_OUTPUT
  distance     : DINT;   | Distance between the two points in meters
  bearing     : INT;     | Direction in degrees between the two points
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
VAR_OUTPUT
  gsmConnect : BOOL; | Indicates that the GSM is connected to a basestation (Green)
  gpsValid   : BOOL; | Indicates that a position fix has been obtained (Red)
END_VAR;
 
PROGRAM GPS_Example;
VAR
  sms     : gsmIncomingSMS;
  gps     : gpsFix;
  gc       : gpsDistanceX;
  str     : STRING;
  awaitFix : BOOL;
END_VAR;
 // Turn on power to the GPS receiver
  gpsPower(power:=TRUE);
  // Turn on power to the GSM module
  gsmPower(power:=TRUE);
BEGIN
// Update GPS data
  gps();
  // If we got a valid fix from the GPS
  IF gps.mode > 1 THEN
    // Calculate distance and bearing to Logic IO in Denmark
     gc(latitude1:=55513078, longitude1:=9510530, latitude2:=gps.latitude, longitude2:=gps.longitude);
    // Build string with information  
     str:=strFormat(format:="Distance to Logic IO=\4.\3 KM, bearing=\2 deg",
          v4:=gc.distance/1000, v3:=INT(gc.distance MOD 1000), v2:=gc.bearing);
  END_IF;
 
  // If we receive a SMS message, we want the next GPS position that is valid
  IF sms.status > 0 THEN
     awaitFix:=TRUE;
  END_IF;
 
  // If we are waiting for next valid GPS position, and GPS position is valid,
  IF awaitFix AND gps.mode > 1 THEN
     awaitFix:=FALSE;
    // Send an SMS with the position
    gsmSendSMS(phonenumber:=sms.phonenumber, message:=str);
  END_IF;
 
  // Indicate on LED (green part) if we are connected to a GSM basestation
  gsmConnect:=gsmConnected();
  // Indicate on LED (red part) if valid GPS position
  gpsValid:=gps.mode > 1;
END;
 
END_PROGRAM;