Welcome to Rt1_assignment2_documentation's documentation!

On this repository, I have the privilege to share with you my modest response to the Research Track's second assignment, wherein we are tasked to build a package for a robot simulation in Gazebo and Rviz. Therefore, I did create a new ROS package, for which we will develop 3 nodes to perform specific tasks as follows:

1-An action client node that permits the user to set or cancel a target (x, y) and also publishes the robot's position and velocity as a custom message (x, y, vel x, vel y), by using the values published on the subject /odom.

2-A service node that when we activate, it will print the number of target reached and cancelled.

3-A node for printing both the distance that separates the robot from the target and its average speed. In addition, It subscribes to the robot’s position and speed, this will be through using a custom message. A parameter will be used to set the frequency of publishing the data.

4-In order to run all the simulation together, a launch file was created for this purpose. Set the value for the frequency of the information published by node 3

Indices and tables

Rt1_2nd_Assignment_Documentation

This the documentation for assignment 2 rt1

action_user.py

An action client node that permits the user to set or cancel a target (x, y) and also publishes the robot's position and velocity as a custom message (x, y, vel x, vel y), by using the values published on the subject /odom..

Functions:
  • publisher(): Use to get both position and velocity informations

  • action_client(): Get the keyboard inputs and also create the goal to send to the server.

Usage:
  • The user is able to set a parameter to send a target position or can also cancel an existing target with pressing c.

  • User interface prompts to get the input of the user for executing the function above.

---

Global Variables:

pub

scripts.action_user.action_client()

This function creates an action client that communicates with an action server called '/reaching_goal' that provides a service of planning a path for the robot to reach a target pose. The function asks the user to input the x and y coordinates of the target pose or type c to cancel the goal. If the user enters c, the function cancels the current goal. Otherwise, the function sends the goal to the action server and waits for feedback.

scripts.action_user.main()

This function creates a node called (action_user) that publishes and subscribes to custom messages that contain the position and velocity of the robot. It also creates an action client that sends goals to an action server.

scripts.action_user.publisher(msg)

this function takes an odometry message as input and publishes a custom message that contains only the x and y componenets of the position and velocity of the rebot

bug_as.py

This code is a ROS program that implements the bug0 algorithm for planning a path to a goal while avoiding obstacles. It uses a laser scan sensor and an odometry sensor to get the information about the environment and the robot's pose. It also uses two services to control the robot's motion: go to point and wall follower. It also defines an action server that takes a goal as an input and publishes feedback and result messages

---

Global Variables: srv_client_go_to_point

the service client for the go to point service

srv_client_wall_follower

the service client for the wall follower service

yaw

the yaw angle of the robot

yaw_error_allowed

the allowed error in yaw angle

position

the position of the robot

pose

the pose of the robot

desired_position

the desired position of the robot

regions

the regions of the laser scan

state_desc

the list of strings for describing the state of the robot

state

the state of the robot

scripts.bug_as.change_state(state)

This is the function to change the state of the robot and call the appropriate services. It updates the global variable for the state of the robot and logs a message with the state description. It also calls the go to point service and the wall follower service with true or false depending on the state

scripts.bug_as.clbk_laser(msg)

This is the callback function for the laser scan subscriber. It updates the global variable for the regions of the laser scan using the laser scan message. It divides the laser scan into five regions: right, fright, front, fleft and left. It also takes the minimum distance in each region and caps it at 10 meters

scripts.bug_as.clbk_odom(msg)

This is the callback function for the odometry subscriber. It updates the global variables for the position, pose and yaw of the robot using the odometry message. It also converts the quaternion orientation to euler angles using the transformations library

scripts.bug_as.done()

This is the function to stop the robot when it reaches its goal or cancels its action. It creates a twist message and sets the linear and angular velocities to zero. It then publishes the twist message to the cmd_vel topic

scripts.bug_as.main()

This is the main function that runs the program. It initializes the ROS node, sets the desired position parameters, creates the subscribers, publisher, service clients and action server. It also calls the planning function and sleeps at a rate of 20 Hz

scripts.bug_as.normalize_angle(angle)

This is the function to normalize an angle to be within [-pi, pi]. It checks if the absolute value of the angle is greater than pi, and if so, it subtracts or adds 2*pi depending on the sign of the angle. It then returns the normalized angle

scripts.bug_as.planning(goal)

This is the function to implement the planning algorithm using bug0 and ROS actions. It takes a goal as an argument and changes the state of the robot accordingly. It also publishes feedback and result messages to the action server. It checks if the robot has reached the goal, encountered an obstacle, or received a preemption request. It uses the go to point and wall follower services to control the robot's motion.

goal_service.py

This service node that when we activate, it will print the number of target reached and cancelled.

Subscribes to:

  • /reaching_goal/result: Use to receive status updates on goals.

Service:

  • goal_service: Service use to take the number of reached goals and canceled goals.

Functions:

  • init(self): This function makes a class that can send and receive goals. It counts how many goals were done or stopped. It makes a service and a subscriber for this.

  • result_callback(self, msg): This function is a callback method that handles the messages from the result topic.

  • data(self, req): This function defines a method called data that takes two parameters: self and req.

Usage:

  • The result_callback It checks the status of the result and updates the counters for goals cancelled or reached accordingly

  • The data is used to return an object of type goal_rcResponse that contains the values of two attributes of self: goal_reached and goal_cancelled.

Variables:
count_canceledint

Count the amount of canceled goals.

count_reachedint

Count the amount of reached goals.

scripts.goal_service.main()

This is the Main entry point of our node.

  • Start to intialize the ROS node with the name "goal_service".

  • Create an instance of the Service class.

  • Keeps the node activated by calling rospy.spin().

print_dis_avgvel.py

Python module for the Subscriber node (print_dis_avgvel).

This node for printing both the distance that separates the robot from the target and its average speed. In addition, It subscribes to the robot position and speed, this will be through using a custom message. A parameter will be used to set the frequency of publishing the data

Subscribes to:

  • /posxy_velxy (message type: Posxy_velxy)

---

scripts.print_dis_avgvel.main()

This code defines a function called main that tries to suppress the timestamps from the log messages, initializes the node with the name "print_dis_avgvel" and creates an object of the PrintInfo class that subscribes to a topic and prints the distance and speed information of the robot at a given frequency, and waits for messages. The code also calls the main function if the file is being run directly.

wall_follow_service.py

This is a Python script that implements a wall follower behavior using laser scan data. The robot navigates in an environment with walls and adjusts its movement to follow the contours of the walls.

scripts.wall_follow_service.change_state(state)

Function to change the state of the wall follower. This function changes the state of the wall follower behavior. It takes the new state as input. It updates the global variable 'state_' with the new state. If the state has changed, it prints a message indicating the current state.

scripts.wall_follow_service.clbk_laser(msg)

Callback function for the laser scan subscriber. This is a callback function for laser scan subscriber. It receives a LaserScan message 'msg' as input. It extracts the ranges from the laser scan message and assigns them to the 'regions_' dictionary, representing different regions of the robot's surroundings. It then calls the 'take_action()' function to perform appropriate actions based on the current regions.

scripts.wall_follow_service.find_wall()

Function to control the robot's movement to find the wall. This function generates a 'Twist' message to control the robot's movement to find the wall. It sets a linear velocity 'msg.linear.x' to 0.2 and an angular velocity 'msg.angular.z' to -0.3, causing the robot to move forward while slightly turning to the left. It returns the generated 'Twist' message.

scripts.wall_follow_service.follow_the_wall()

Function to control the robot's movement to follow the wall. This function generates a 'Twist' message to control the robot's movement to follow the wall. It sets a linear velocity 'msg.linear.x' to 0.5, causing the robot to move forward at a moderate speed. It returns the generated 'Twist' message.

scripts.wall_follow_service.main()

This is the main function

scripts.wall_follow_service.take_action()

Function to take action based on the laser scan regions. This function determines the action to be taken based on the current regions of the laser scan. It calculates various distance thresholds ('d0' and 'd') to define different cases. Based on the values of the regions, it selects the appropriate case and changes the state using the 'change_state()' function. The function prints the state description for debugging purposes.

scripts.wall_follow_service.turn_left()

Function to control the robot's movement to turn left. This function generates a 'Twist' message to control the robot's movement to turn left. It sets an angular velocity 'msg.angular.z' to 0.3, causing the robot to rotate in place to the left. It returns the generated 'Twist' message.

scripts.wall_follow_service.wall_follower_switch(req)

Service callback function to switch the wall follower on or off. This function is a service callback that handles the switching on or off of the wall follower behavior. It takes a request message 'req' as input. It updates the global variable 'active_' based on the value of 'req.data'. It returns a response message indicating the success of the switch operation.