turtlebot3_patrol_server

This file is ai generated. Do not edit this file directly. Instead, edit the node source code and run the generate-node-docs command to update this file.

Description

An action server node that autonomously patrols the TurtleBot3 in predefined geometric patterns (square or triangle). The server accepts patrol action goals specifying the shape, side length, and number of iterations. It provides feedback on progress and returns the completion status.

Publishers

Subscribers

Actions

Server

  • turtlebot3 (turtlebot3_msgs/Patrol)

    • Goal:

      • goal.x (float): Pattern type (1.0 = square, 2.0 = triangle)

      • goal.y (float): Side length in meters

      • goal.z (float): Number of iterations

    • Feedback:

      • state (string): Current progress (e.g., “line 1”, “line 2”)

    • Result:

      • result (string): Completion status message

Parameters

The node uses hardcoded parameters that vary by pattern:

Square Pattern:

  • Linear velocity: 0.2 m/s

  • Angular velocity: 13 * (90°/180°) * π / 100.0 rad/s

  • Turn angle: 90°

  • Sides: 4

Triangle Pattern:

  • Linear velocity: 0.2 m/s

  • Angular velocity: 8 * (120°/180°) * π / 100.0 rad/s

  • Turn angle: 120°

  • Sides: 3

Example Usage

Start the patrol server:

ros2 run turtlebot3_example turtlebot3_patrol_server

Send a patrol goal using the client:

ros2 run turtlebot3_example turtlebot3_patrol_client

Or use the action command line:

# Square patrol - 1.0m sides, 2 iterations
ros2 action send_goal /turtlebot3 turtlebot3_msgs/action/Patrol "{goal: {x: 1.0, y: 1.0, z: 2.0}}"

# Triangle patrol - 0.5m sides, 3 iterations
ros2 action send_goal /turtlebot3 turtlebot3_msgs/action/Patrol "{goal: {x: 2.0, y: 0.5, z: 3.0}}"

Behavior

Square Patrol (mode = 1)

  1. Move forward for specified distance

  2. Rotate 90° counterclockwise

  3. Repeat 4 times to complete square

  4. Repeat entire square for specified iterations

  5. Return success result

Triangle Patrol (mode = 2)

  1. Move forward for specified distance

  2. Rotate 120° counterclockwise

  3. Repeat 3 times to complete triangle

  4. Repeat entire triangle for specified iterations

  5. Return success result

Feedback

During execution, the server publishes feedback after completing each side:

  • “line 1” - First side completed

  • “line 2” - Second side completed

  • etc.

Completion

Upon completion:

  • Final feedback: “square patrol complete!!” or “triangle patrol complete!!”

  • Result: Same completion message

  • Server shuts down (triggers rclpy.shutdown())

Control Implementation

Forward Movement

def go_front(position, length):
  - Increment position counter
  - Publish linear.x velocity
  - Continue until position >= length
  - Stop robot

Rotation

def turn(target_angle):
  - Calculate target yaw from current pose
  - Spin until yaw_diff < 0.01 rad
  - Publish angular.z velocity
  - Stop robot

Notes

  • The server uses ReentrantCallbackGroup to handle concurrent callbacks

  • Only one goal can be executed at a time (standard action server behavior)

  • The node automatically shuts down after completing a patrol

  • Restart the server for subsequent patrol missions

  • Does not perform obstacle avoidance during patrol

  • Odometry drift may cause inaccuracies in geometric patterns

  • Angular velocities are carefully tuned for each pattern’s turn angles