bug_as module

Bug0 Navigation Node

This module implements a ROS-based navigation strategy for a robot using the Bug0 algorithm. The system subscribes to odometry and laser scan data, processes sensor information, and utilizes an action server to reach specified target positions while avoiding obstacles.

The main functionalities include: - Subscribing to /odom for robot pose and orientation. - Subscribing to /scan for laser-based obstacle detection. - Publishing velocity commands to /cmd_vel. - Managing different navigation states: moving to a goal, avoiding obstacles, and stopping. - Using an action server (/reaching_goal) to execute navigation commands. - Calling services to switch between goal-seeking and wall-following behaviors.

Dependencies:

  • rospy: ROS Python library for communication.

  • geometry_msgs: Provides Point, Pose, and Twist message types.

  • sensor_msgs: Provides LaserScan message type.

  • nav_msgs: Provides Odometry message type.

  • std_srvs: Provides standard ROS service message types.

  • tf: Provides transformations for quaternion processing.

  • actionlib: Provides tools for implementing action-based communication.

bug_as.change_state(state)[source]

Updates the robot’s navigation state and adjusts service calls accordingly.

Parameters: state (int):

The new state to transition to (0: go to point, 1: wall following, 2: done).

bug_as.clbk_laser(msg)[source]

Callback function for the laser scanner subscriber.

Processes laser scan data and segments obstacle distances into predefined regions.

Parameters: msg (sensor_msgs.msg.LaserScan):

The laser scan message containing range data.

bug_as.clbk_odom(msg)[source]

Callback function for the odometry subscriber.

Updates the robot’s position and yaw angle based on odometry data.

Parameters: msg (nav_msgs.msg.Odometry):

The odometry message containing the robot’s pose.

bug_as.done()[source]

Stops the robot by publishing zero velocity.

bug_as.main()[source]

Initializes the ROS node, sets up subscribers, publishers, and services, and starts the action server.

bug_as.normalize_angle(angle)[source]

Normalizes an angle to the range [-pi, pi].

Parameters: angle (float):

The angle in radians.

Returns: angle (float):

The normalized angle.

bug_as.planning(goal)[source]

Executes the robot’s goal-reaching behavior while avoiding obstacles.

Parameters: goal (assignment_2_2024.msg.PlanningGoal):

The goal message containing the target pose.

bug_as.state_ = 0

Current navigation state (0 - go to point, 1 - wall following, 2 - done, 3 - canceled)