AGRIBOT localizes itself using two sensors — an NEO-M8N GPS module that publishesDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Dhruv2012/Autonomous-Farm-Robot/llms.txt
Use this file to discover all available pages before exploring further.
NavSatFix messages and an MPU-9265 9-DOF IMU/magnetometer that provides compass heading. The GPS_data_conversion.py node bridges raw sensor data to the navigation controller by converting geodetic coordinates to a local planar frame, computing distance and bearing to the operator-specified goal, and republishing everything the downstream data_manipulation and autonomousdrive nodes need.
GPS Coordinate Conversion
Raw GPS data arrives as WGS84 latitude and longitude. Before a PD controller can work with it, those geodetic values must become linear distances in metres. Thell2xy() function performs this conversion using a Mercator projection anchored at a local origin point.
mdeglat() and mdeglon() return the number of metres represented by one degree of latitude and longitude respectively at a given latitude, accounting for Earth’s ellipsoidal shape:
Inverse Conversion: XY to Lat/Lon
Thexy2ll() function is the inverse of ll2xy(). It converts a local XY position back to WGS84 latitude and longitude by dividing out the metres-per-degree scale factors.
xy2ll() is used to reconstruct the goal coordinate as a NavSatFix message that is published on the goal_GPS topic. Mapviz subscribes to goal_GPS alongside the live /agribot/fix stream so operators can see both the robot position and the target waypoint on a satellite map overlay in real time.
UTM Support
GPS_data_conversion.py also bundles complete LLtoUTM() and UTMtoLL() implementations derived from equations in USGS Bulletin 1532 (originally authored by Chuck Gantz). These functions handle the full UTM zone-letter designation, false northing for the southern hemisphere, and special zone rules for Svalbard and Norway.
UTM conversion is available as an alternative to the Mercator approach when operating over areas that span multiple degrees of latitude, or when integrating with external tools that work natively in UTM coordinates. The active code path uses ll2xy() / xy2ll() via their vectorized NumPy wrappers vll2xy and vxy2ll.
Bearing and Distance Calculation
Insideget_xy_based_on_lat_long(), the GPS callback computes three separate local XY frames to derive the distance and bearing needed by the controller:
(xa, ya) is the goal expressed in a frame centred on the robot’s current position, so atan2(ya, xa) gives the bearing from the robot to the goal directly. The Euclidean norm of (xa, ya) gives the remaining distance in metres. Both values are published every time a new GPS fix arrives.
The current pose published to
/currentPose uses (xa, ya) — goal relative to current position — not (xc, yc) (current position relative to origin). Downstream nodes in data_manipulation therefore see a pose that shrinks toward zero as the robot approaches the goal.Magnetometer Heading
Compass heading is extracted from the rawgeometry_msgs/Vector3Stamped message published by the IMU driver on the /magnetic topic:
atan2() produces a heading in degrees measured from the positive X axis of the sensor frame. Because raw magnetometer output is noisy — particularly in environments with metallic structures or electrical cables — this value is fed directly into the Moving Median filter before being used by the controller. See Sensor Noise Filtering for the full filter implementation.
ROS Node: gps_converter
Thegps_converter node is the entry point for the navigation stack. It initialises publishers and subscribers, then spins to process incoming GPS messages:
/Pole/fix subscriber calls publishing_OriginGPS(), which updates startingPoint_latitude and startingPoint_longitude whenever a new message arrives. Placing a second GPS receiver at a fixed pole in the field and publishing its position on /Pole/fix lets the operator set the coordinate origin dynamically without modifying any source code.