A ROS2 package that makes a turtlesim turtle autonomously draw the boundaries of its domain. The behavior is interruptible: press SPACE at any time to take manual control via teleop.
A Finite State Machine (FSM) drives the turtle through these states:
| State | Description | Pen |
|---|---|---|
MOVE_TO_BOUNDARY |
Drives straight toward the nearest wall | UP |
FOLLOW_BOUNDARY |
Traces the perimeter rectangle counter-clockwise | DOWN |
RETURN_HOME |
Navigates back to initial position | UP |
IDLE |
Done — turtle stops | — |
MANUAL |
Teleop mode (entered/exited via SPACE) | unchanged |
- draw_boundaries_node — Main FSM controller. Subscribes to
/turtle1/poseand/keyboard_input, publishes to/turtle1/cmd_vel, calls/turtle1/set_pen. - keyboard_listener — Captures spacebar presses from terminal, publishes
toggle_manualon/keyboard_input. - turtlesim_node — Standard turtlesim.
- turtle_teleop_key — Standard turtlesim teleop for manual control.
cd ~/robotics/ROS-TP2
colcon build
source install/setup.bashros2 launch turtle_boundary_controller draw_boundaries.launch.pyThis opens:
- The turtlesim window
- An xterm for the keyboard listener (press SPACE here to toggle manual mode)
- An xterm for turtle_teleop_key (use arrow keys when in manual mode)
| Option | Default | Description |
|---|---|---|
speed |
2.0 |
Maximum linear/angular speed |
boundary_margin |
0.5 |
Distance from wall edge defining the boundary |
Example:
ros2 launch turtle_boundary_controller draw_boundaries.launch.py speed:=1.5 boundary_margin:=1.0- Launch the system — the turtle automatically starts moving toward the nearest wall
- When it reaches the boundary, pen goes down and it traces the full perimeter counter-clockwise
- After completing the rectangle, pen goes up and the turtle returns to its starting position
- At any time, press SPACE in the keyboard listener terminal to enter manual mode
- In manual mode, use arrow keys in the teleop terminal to move the turtle
- Press SPACE again to resume autonomous boundary-following from the current position
- ROS2 Jazzy
turtlesimxterm(for the launch file to open separate terminal windows)
Install xterm if needed:
sudo apt install xterm