This project implements a Bump and Go behavior for a robot using sensors to detect obstacles. The robot moves forward, responds to obstacles by reversing and turning, and then continues forward. To manage this behavior effectively, a Finite State Machine (FSM) is employed for structured decision-making, ensuring code simplicity and scalability.
Implementing FSM for Bump and Go is simple. Assign states for distinct robot actions (stop, move forward, go back, turn), and define transitions between these states based on conditions.
The BumpGoNode class represents a ROS 2 node responsible for autonomous robot navigation based on laser scan data. The class implements a finite state machine to control the robot's behavior, including forward movement, backward movement, turning, and stopping. Key attributes include the current state, timestamps for state transitions, and durations for turning, backing, and scan timeouts. The class subscribes to laser scan messages and updates its internal state accordingly. The control_cycle method orchestrates the robot's actions based on the current state, obstacle detection, and timeout conditions. Public methods such as is_obstacle_detected and is_scan_timeout provide checks for specific conditions, and publish_velocity is responsible for sending velocity commands to the robot. Overall, the BumpGoNode class encapsulates the logic for a reactive robot navigation system that responds to environmental cues and adjusts its behavior accordingly.