Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

🪳 Simple Cockroach Behavior on TurtleBot3

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


📖 Overview

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.

Core behaviors

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)

🧠 System Design

Finite State Machine

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

Stimulus–Response Thresholds (IRM)

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.


🛠️ System Requirements

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

ROS Topics

  • Subscribes: /scansensor_msgs/LaserScan
  • Publishes: /cmd_velgeometry_msgs/Twist

🚀 Getting Started

Prerequisites

  • Ubuntu with ROS Noetic installed
  • TurtleBot3 packages (turtlebot3, turtlebot3_bringup, turtlebot3_msgs)
  • A catkin workspace set up

Installation

cd ~/catkin_ws/src
git clone <this-repo-url> cockroach_behavior
cd ~/catkin_ws
catkin_make
source devel/setup.bash

Running the robot

# 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.py

Use RViz to visualize live LiDAR data and confirm behavior transitions:

roslaunch turtlebot3_bringup turtlebot3_remote.launch
rviz

🧪 Development & Testing Approach

The system was built incrementally, validating each behavior in isolation before integration:

  1. Verified baseline motor response on /cmd_vel
  2. Implemented and tested RANDOM_WALK in an open lab space
  3. Implemented and tested wall detection / stop-on-obstacle
  4. Implemented and tested FLEE (reverse-and-turn near walls)
  5. Implemented and tested HIDE (corner alignment)
  6. Merged all behaviors into a single FSM-driven ROS node
  7. Ran 5 full indoor test runs across varied wall/corner layouts, tuning thresholds, control gains, and velocities to reduce oscillation and improve switching stability

⚠️ Challenges & Limitations

  • 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.

📚 References

  1. Course Lecture Slides – BAXI 3523 Artificial Intelligence in Robotics and Automation
  2. ROS Official Documentation
  3. TurtleBot3 e-Manual
  4. Python Documentation

About

Simple wall-following and foraging behavior inspired by cockroach locomotion, implemented on real TurtleBot3 hardware using ROS/ROS2.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages