TheDocumentation 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.
autonomous_drive package is the core navigation layer of AGRIBOT. It contains Python scripts implementing three cooperating ROS nodes that transform raw GPS and magnetometer data into motor velocity commands, plus an action-based waypoint patrol node. The nodes are intentionally separated by concern: coordinate conversion happens in one node, sensor filtering and angle computation in a second, and velocity command generation in a third. This pipeline design makes it easy to inspect or replace any stage independently.
Node: gps_converter (GPS_data_conversion.py)
The gps_converter node is the entry point for all positional data. It converts raw WGS84 latitude/longitude readings into a local Cartesian XY frame, computes the Euclidean distance and bearing to the goal, and republishes that information for downstream nodes.
Node initialization — the node prompts the operator for the target coordinates at startup before entering the ROS spin loop:
ll2xy() function (AlvinXY) that converts latitude/longitude pairs to local metres relative to a dynamic origin. The origin is updated in real time from a reference GPS receiver mounted at a fixed pole on the field boundary.
Subscriptions:
| Topic | Message Type | Callback | Description |
|---|---|---|---|
/agribot/fix | NavSatFix | get_xy_based_on_lat_long() | Current robot GPS position |
/Pole/fix | NavSatFix | publishing_OriginGPS() | Reference GPS at the field origin pole |
| Topic | Message Type | Description |
|---|---|---|
/distance | Float64 | Euclidean distance to goal in metres |
angleOG | Float64 | Bearing angle from current position to goal (degrees, atan2-based) |
/currentPose | Pose | Current XY position expressed as a Pose message (position.x, position.y) |
goal_GPS | NavSatFix | Goal coordinates packaged as NavSatFix for Mapviz visualization |
Node: data_manipulation (data_manipulation.py)
The data_manipulation node fuses magnetometer heading with the GPS bearing computed by gps_converter. Raw magnetometer readings are noisy, so the node applies a Moving Median filter over a window of 7 samples before using the heading in navigation calculations.
Subscriptions:
| Topic | Message Type | Callback | Description |
|---|---|---|---|
/magnetic | Vector3Stamped | callback() | Raw magnetometer readings from libhector_gazebo_ros_magnetic.so |
/currentPose | Pose | angle_to_move() | Current XY position from gps_converter |
angleOG | Float64 | angleassignment() | Cached bearing-to-goal from gps_converter |
| Topic | Message Type | Description |
|---|---|---|
Filteredheading | Float64 | Moving Median filtered magnetometer heading (degrees) |
Rawheading | Float64 | Unfiltered raw heading computed from atan2(y, x) of the magnetic vector |
/angle | Float64 | Corrected angle-to-move sent to the drive controller |
angle_to_move() by combining the cached GPS bearing with the filtered magnetic heading and normalising the result to the [-180, 180] range:
Node: autonomousdrive (autonomus_drive.py)
The autonomousdrive node is the lowest-level node in the pipeline. It reads the heading error and distance-to-goal produced upstream and translates them into Twist velocity commands on /agribot/cmd_vel. A proportional-derivative (PD) control law with kp = 0.01 and kd = 0.5 governs angular corrections while the robot also moves forward.
Subscriptions:
| Topic | Message Type | Callback | Description |
|---|---|---|---|
/angle | Float64 | callback_for_angle() | Heading error in degrees |
/distance | Float64 | callback_for_distance() | Distance to goal in metres |
| Topic | Message Type | Description |
|---|---|---|
/agribot/cmd_vel | Twist | Velocity commands (linear.x, angular.z) |
GPSAlgoV1() function implements the navigation policy:
- If
|orientation_error| >= 2°and the robot is far from the goal, it rotates while moving forward slowly (linear.x = 0.2). - If
|orientation_error| > 10°, it rotates in place (linear.x = 0). - If
|orientation_error| < 2°, it moves straight at full speed (linear.x = 0.4). - Angular velocity is clamped to
±0.5 rad/s. - When
distance_to_goal <= 0.5 mordestination_flag == 1, the node stops all motion and latches the flag.
Node: patrol (AutonomusDriveAction.py)
The patrol node is an alternative high-level navigation client built on the move_base action interface. Rather than the direct GPS pipeline used by autonomousdrive, it sends pre-defined map-frame waypoints to a running move_base server, which handles local path planning and obstacle avoidance internally.
Waypoints are defined as a list of [(x, y, z), (qx, qy, qz, qw)] tuples in the map frame:
MoveBaseGoal and waiting for the action server to report success before advancing to the next.
Running All Nodes Together
The following sequence brings up the complete autonomous navigation stack from a cold start.Start the Gazebo farm simulation
Farm.world, spawns AGRIBOT, starts the PID controllers, and opens the gps_converter and sensor_data nodes in xterm windows automatically.Start the wheel controllers (if not using my_world.launch)
my_world.launch, which includes agribot_control.launch internally.Run the GPS converter and enter goal coordinates
/distance, angleOG, and /currentPose immediately after.Run the data manipulation node
/angle topic consumed by the drive controller.