A behavior-based reactive control system for the TurtleBot3 Burger, inspired by the instinctive, memory-free responses of cockroaches in nature. Built with ROS Noetic and Python, the robot reacts to real-time LiDAR data using a priority-driven Finite State Machine (FSM) — no mapping, localization, or learning involved.
Course: BAXI3523 – Artificial Intelligence in Robotics & Automation Faculty: Faculty of Artificial Intelligence and Cyber Security (FAIX), Universiti Teknikal Malaysia Melaka (UTeM) Semester: 1, 2025/2026
📺 Demo video: Watch on YouTube
Cockroaches don't plan — they react. Their behavior is governed by Innate Releasing Mechanisms (IRM), where specific stimuli trigger fixed, instantaneous responses. This project brings that idea to a real robot: the TurtleBot3 continuously senses its environment via LiDAR and reacts using simple, prioritized rules, producing lifelike, emergent behavior from purely reactive logic.
| Behavior | Trigger | Response |
|---|---|---|
| FLEE | Obstacle very close in front | Reverse and turn sharply away (highest priority) |
| HIDE | Walls close on both sides (corner/confined space) | Align and settle near the nearest wall |
| WALL_FOLLOW | Wall detected at a moderate distance | Proportional control to travel smoothly alongside it |
| RANDOM_WALK | No significant obstacle detected | Forward motion with randomized heading perturbations (default/lowest priority) |
The four behaviors are organized into a priority-based FSM. Higher-priority (survival) behaviors always override lower-priority (exploratory) ones:
FLEE > HIDE > WALL_FOLLOW > RANDOM_WALK
START → RANDOM_WALK ⇄ (obstacle in front?) → FLEE → WALL_FOLLOW ⇄ (corner/close wall?) → HIDE
↑___________________________|
(no obstacles detected at any time) → back to RANDOM_WALK
LiDAR data is filtered (removing zero, negative, infinite, and out-of-range values) and split into three sectors:
- Front (~350°–360° and 0°–10°)
- Left (~60°–120°)
- Right (~240°–300°)
The minimum valid distance per sector is compared against tuned thresholds to decide which behavior state should be active on each control cycle.
| Component | Description |
|---|---|
| Robot Platform | TurtleBot3 Burger |
| Sensor | 360° LiDAR |
| Software Framework | ROS Noetic |
| Programming Language | Python |
| Control Strategy | Behavior-based reactive control |
| Environment | Indoor laboratory, static obstacles |
| Constraints | No mapping, localization, or learning |
- Subscribes:
/scan—sensor_msgs/LaserScan - Publishes:
/cmd_vel—geometry_msgs/Twist
- Ubuntu with ROS Noetic installed
- TurtleBot3 packages (
turtlebot3,turtlebot3_bringup,turtlebot3_msgs) - A catkin workspace set up
cd ~/catkin_ws/src
git clone <this-repo-url> cockroach_behavior
cd ~/catkin_ws
catkin_make
source devel/setup.bash# On the TurtleBot3 (or in simulation)
roslaunch turtlebot3_bringup turtlebot3_robot.launch
# On the remote PC — start the cockroach FSM node
rosrun cockroach_behavior cockroach_fsm.pyUse RViz to visualize live LiDAR data and confirm behavior transitions:
roslaunch turtlebot3_bringup turtlebot3_remote.launch
rvizThe system was built incrementally, validating each behavior in isolation before integration:
- Verified baseline motor response on
/cmd_vel - Implemented and tested
RANDOM_WALKin an open lab space - Implemented and tested wall detection / stop-on-obstacle
- Implemented and tested
FLEE(reverse-and-turn near walls) - Implemented and tested
HIDE(corner alignment) - Merged all behaviors into a single FSM-driven ROS node
- Ran 5 full indoor test runs across varied wall/corner layouts, tuning thresholds, control gains, and velocities to reduce oscillation and improve switching stability
- LiDAR sensor noise caused unstable state switching near walls — mitigated with sensor filtering and threshold tuning.
- Conflicting behaviors (e.g., wall-following vs. hiding activating simultaneously near corners) — resolved via strict FSM priority ordering.
- Flee-loop instability from noisy readings — resolved by adding a brief timer to let the escape maneuver complete before re-evaluating sensor input.
- The system is purely reactive: it has no memory, learning, or path optimization, and reacts only to what it senses at each instant. This is an intentional simplification for the project's educational scope.
- Course Lecture Slides – BAXI 3523 Artificial Intelligence in Robotics and Automation
- ROS Official Documentation
- TurtleBot3 e-Manual
- Python Documentation