Heading and GPS Coordinates Formatting
By Jose Alcantar, E&C Engineer
The GPS information received through the Arxterra control panel can be sent through three different data types. The first data type is a 32-bit floating point, the second is a 64-bit floating point or “double” and lastly a 32-bit integer or “long”. Depending on how the settings are configured through the “Robot Capabilities Configuration” menu in the app, the user can choose between any of these three data types. For further information on the data types see the blogpost by Jeff Gomes,
https://www.arxterra.com/arxterra-now-supports-waypoint-navigation/
For our purpose, the 32-bit integer was selected as the data type due to some formatting issues when using the 32-bit floating or 64-bit floating types.
To begin with formatting the coordinates, it must first be understood what values are being sent through the Arxterra app. From the link above, Gomes explains that for the 32-bit integer the units are set to decimicrodegrees. This means that for example, coordinates 33.794904, -117.913712 would be encoded as 33794904, -117913712. The app sends the coordinate values through a 16-byte packet, in which the first 4 bytes are the latitude and the last 4 bytes are the longitude coordinates, bytes being represented in hexadecimal.
There are different commands available related to GPS navigation, further described in this link,
https://www.arxterra.com/pathfinder-arxterra-communication-commands/
Example:
The following firmware code is based on the WAYPOINT _COORD command, which is used to receive the waypoint coordinate packet data and to format the coordinates into usable values.
After a waypoint is created, for example, 33.794904, -117.124567, the app converts these values into decimicrodegrees and sends the values to the MCU as a 32-bit long. The data being sent will be as follows
{A5, 10 (packetlength),14 (command id), 02 03 AB 58 F9 04 D6 80, (checksum)};
To extract the data through the Arduino some variables must first be declared:
long waypointLat4;
long waypointLat3;
long waypointLat2;
long waypointLat1;
unsigned long waypointLat;
long waypointLon4;
long waypointLon3;
long waypointLon2;
long waypointLon1;
unsigned long waypointLon;
The byte vales are extracted from the packet and the bits are shifted to be stored into a 32-bit unsigned long.
void waypoint_coordHandler (uint8_t cmd, uint8_t param[], uint8_t n)
{
waypointLat4 = param[0];
waypointLat3 = param[1];
waypointLat2 = param[2];
waypointLat1 = param[3];
waypointLat = (waypointLat4 << 24 | waypointLat3 << 16| waypointLat2 << 8| waypointLat1);
waypointLon4 = param[4];
waypointLon3 = param[5];
waypointLon2 = param[6];
waypointLon1 = param[7];
waypointLon = (waypointLon4 << 24 | waypointLon3 << 16| waypointLon2 << 8| waypointLon1);
waypointLon = ~waypointLon;
waypointLon = (waypointLon + 1) * -1;
}
The longitude coordinates require a secondary step to get the right value. Because longitude is a negative value, a 2’s complement operation must be done on the final value to get the right coordinate. Using this formatting, successfully converts the packet data being sent into usable coordinates needed for GPS navigation.
Conclusion:
Following this method, the GPS data sent through the Arxterra control panel can be converted into usable values, which will help with autonomous navigation.
Resources:
https://www.arduino.cc/en/Reference/Bitshift
https://www.arduino.cc/en/Reference/UnsignedLong
https://www.arduino.cc/en/Reference/Long
https://en.wikipedia.org/wiki/Two’s_complement