gpsDistance (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.

The input to this function block is the same format as the gpsFix() deliver positions in.

 

Also see gpsDistanceX().

 

 

Input:

 

Position 1:

 

lat1south : BOOL

True is south, false is north.

 

lat1deg : SINT

Degrees (0..90).

 

lat1min : SINT

Minutes (0..59).

 

lat1decmin : INT

Decimal minutes (0..9999).

 

lon1west : BOOL

True is west, false is east.

 

lon1deg : INT

Degrees (0..180).

 

lon1min : SINT

Minutes (0..59).

 

lon1decmin : INT

Decimal minutes (0..9999).

 

Position 2:

 

lat2south : BOOL

True is south, false is north.

 

lat2deg : SINT

Negative is south (-90..+90).

 

lat2min : SINT

Minutes (0..59).

 

lat2decmin : INT

Decimal minutes (0..9999).

 

lon2west : BOOL

True is west, false is east.

 

lon2deg : INT

Negative is west (-180..+180).

 

lon2min : SINT

Minutes (0..59).

 

lon2decmin : INT

Decimal minutes (0..9999).

 

Output:

 

distance : DINT

Distance between the two positions in meters.

 

bearing : INT

Bearing between the two points in degrees.

 

Declaration:

FUNCTION_BLOCK gpsDistance;
VAR_INPUT
  // Position 1 parameters:
  lat1south   : BOOL;   | True is South, False is North
  lat1deg     : SINT;   | degrees (0..90)
  lat1min     : SINT;   | minutes (0..59)
  lat1decmin   : INT;     | decimal minutes (0..9999)
  lon1west     : BOOL;   | True is West, False is East
  lon1deg     : INT;     | degrees (0..180)
  lon1min     : SINT;   | minutes (0..59)
  lon1decmin   : INT;     | decimal minutes (0..9999)
 
  // Position 2 parameters:
  lat2south   : BOOL;   | True is South, False is North
  lat2deg     : SINT;   | degrees (0..90)
  lat2min     : SINT;   | minutes (0..59)
  lat2decmin   : INT;     | decimal minutes (0..9999)
  lon2west     : BOOL;   | True is West, False is East
  lon2deg     : INT;     | degrees (0..180)
  lon2min     : SINT;   | minutes (0..59)
  lon2decmin   : INT;     | decimal minutes (0..9999)
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       : gpsDistance;
  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(lat1south:=FALSE, lat1deg:=55, lat1min:=51, lat1decmin:=3078, lon1west:=FALSE, lon1deg:=9, lon1min:=51, lon1decmin:=530,
        lat2south:=gps.latsouth, lat2deg:=gps.latdeg, lat2min:=gps.latmin, lat2decmin:=gps.latdecmin,
        lon2west:=gps.lonwest, lon2deg:=gps.londeg, lon2min:=gps.lonmin, lon2decmin:=gps.londecmin);
    // 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;