Welcome to ros_robot_sim_pkg’s documentation!

Indices and tables

Research Track 2 - Assignment 1: Documentation

This is the documentation of the ROS package ‘ros_robot_sim_pkg’.

This package was developed for the Research Track 1 course and documented for the Research Track 2 course.

Below, you will find further descriptions of Nodes (a), (b) and (c) written in Python which were used to simulate a robot in Gazebo environment.

Node (a)

platform:

Unix

synopsis:

Action-Client ROS Node for robot simulator

Module author: Ami Sofia Quijano Shimizu

This node implements an action-client, allowing the user to input in the terminal a target (x, y) or to cancel it. It uses the feedback of the action-server to know when the target has been reached. The node also publishes the robot position and velocity as a custom message (x, y, vel_x, vel_z), by relying on the values published on the topic /odom.

Subscribes to:

/odom : Topic which receives the robot’s odometry as messages of type nav_msgs/Odometry, which includes header, child_frame_id, pose (xyz position, xyzw orientation, covariance), and twist (xyz linear twist, xyz angular twist, covariance)

Publishes to:

/PosVel : Topic which receives the robot’s position (in x and y) and velocity (in x and z) as a custom message of type PosVel.

Action Client of this Action Server:

/reaching_goal

class scripts.acNode_a.ActionClient[source]

Brief: Class for representing the Action-Client node

__init__()[source]
Brief:

Initialization function for the required ROS Action-Alient, Subscriber, Publisher and Message

Detailed Description:
  1. Creates an action-client for the action-server /reaching_goal with action message Planning

  2. Creates a goal object for the action message Planning

  3. Creates a subscriber for the topic /odom

  4. Creates a publisher for the topic /PosVel, where the custom message type PosVel is sent

feedback_callback(feedback)[source]
Brief:

Action callback function that displays the feedback sent by the action-server

Detailed Description:

1. The feedback message of the action Planning is printed. The feedback message incudes the actual pose (xyz position and xyzw orientation) and the status (which tells if the target has been reached or not)

Parameters:

feedback – Feedback message of the action Planning

get_user_input()[source]
Brief:

Function that asks the user to input a goal coordinate or to cancel the current goal.

Detailed Description:
  1. Prompts a message in the terminal asking the user to input ‘X Y’ coordinates or ‘c’ to cancel the goal

  2. If ‘c’ is inputted, the function for cancelling the goal is called

  3. If an ‘X Y’ coordinate is entered, those values are sent to the action-server

  4. In case of invalid inputs, sends an error message and prompts again.

odom_callback(msg)[source]
Brief:

Subscriber callback function that publishes the x and y position and the x and z velocity of the robot

Detailed Description:
  1. Stores the x position, y position, x velocity and z velocity from the /odom topic in a PosVel type message

  2. Publishes these positions and velocities in the topic /PosVel

Parameters:

msg – Message from the /odom topic

scripts.acNode_a.main()[source]
Description

Initialization of action-client node and calling of function get_user_input() to ask and read the user’s input

Node (b)

platform:

Unix

synopsis:

Service ROS Node for robot simulator

Module author: Ami Sofia Quijano Shimizu

This node implements a service node that, when called, returns the coordinates of the last target sent by the user.

Subscribes to:

/reaching_goal/goal : Topic which receives coordinates of the last target sent

Service:

get_last_target : Service which replies with the x and y coordinates of the last target sent as well as a boolean which indicates if the service request was successful or not.

class scripts.srvNode_b.GetLastTargetService[source]
Brief:

Class for representing the GetLastTargetService node

__init__()[source]
Brief:

Initialization function for the ROS service, Subscriber and variables as required

Detailed Description:
  1. Creates a list variable last_target to store the last target coordinates sent as [x y]

  2. Creates the service get_last_target with service message type GetLastTarget

  3. Creates a subscriber for the topic /reaching_goal/goal

handle_get_last_target(req)[source]
Brief:

Service callback function to handle requests for the last target coordinates

Detailed Description:
  1. Creates a response object for the service message GetLastTarget

  2. If at least one target has been sent by user, the x and y coordinates of the last target (obtained from the Subscriber callback function) as well as a successful request confirmation are set as the service response message

  3. If no target has been sent at all, an unsuccessful request confirmation is sent as the service response message

Parameters:

req – Request message sent to the server

Returns:

GetLastTarget service response message

Return type:

GetLastTargetResponse

target_callback(msg)[source]
Brief:

Subscriber callback function that updates the last target coordinates when the user enters a new target

Detailed Description:
  1. Saves the x and y coordinates of the last target in the variable last_target by splitting the message received in the /reaching_goal/goal topic

Parameters:

msg – Message received in the /reaching_goal/goal topic

scripts.srvNode_b.main()[source]
Description:

Initialization of the service node

Node (c)

platform:

Unix

synopsis:

Service ROS Node for robot simulator

Module author: Ami Sofia Quijano Shimizu

This node subscribes to the robot’s position and velocity (using the custom message) and implements a service to retrieve the distance of the robot from the target and the robot’s average speed. The size of the averaging window is set as a parameter in the launch file.

Subscribes to:

/PosVel: Topic which receives the robot’s position (in x and y) and velocity (in x and z) as a custom message of type PosVel.

/reaching_goal/goal: Topic which receives information about the last goal sent including header, goal ID, target position and target orientation

Service:

get_dist_speed: Service which replies with the x, y and euclidean distances from the robot to the current target, the average linear speed in x, the average angular speed in and z, a boolean which indicates if the service request was successful for distance calculation and another boolean which indicates if the service request was successful for velocity calculation

class scripts.srvNode_c.GetDistSpeedService[source]
Brief:

Class for representing the GetDistSpeedService node

__init__()[source]
Brief:

Initialization function for the ROS service, subscriber, and variables as required

Detailed Description:
  1. Creates a list variable last_target to store the last target coordinates sent as [x y]

  2. Creates a variable posvel of the message type PosVel to store the robot’s current xy position and xz velocity

  3. Creates the window_size variable which corresponds to the N velocities that will be averaged. It is a parameter from the launch file

  4. Creates the variables avg_vel_x_queue and avg_vel_z_queue to queue and store the last N velocities in x and z

  5. Creates the service get_dist_speed with service message type GetDistSpeed

  6. Creates a subscriber for the /reaching_goal/goal topic

  7. Creates a subscriber for the /PosVel topic

handle_get_dist_speed(req)[source]
Brief:

Service callback function to handle requests for the robot’s distance from the target and average speed

Detailed Description:
  1. Creates a response object for the service message GetDistSpeed

  2. If at least one target has been sent by user, the cartesian x and y distances and euclidean distance from the robot to the target are computed (with values obtained from the previous 2 Subscriber callback functions) and sent as a service response message together with a successful request confirmation for the distance calculation

  3. If no target has been sent at all, an unsuccessful request confirmation for the distance calculation is sent as the service response message

  4. If there are N registered speeds according to the window size, the average of x and z velocities are computed and sent as a service response message together with a successful request confirmation for the average speed calculation

  5. If there are less than N registered speeds according to the window size, an unsuccessful request confirmation for the average speed calculation is sent as a service response message

Parameters:

req – Request message sent to the server

Returns:

GetDistSpeed service response message

Return type:

GetDistSpeedResponse

posvel_callback(msg)[source]
Brief:

Subscriber callback function that updates the robot’s current x,y positions and x,z velocities and stores it in the queue the velocities

Detailed Description:
  1. Saves the current x and y coordinates and the current x and z velocities in the variable posvel by splitting the message received in the /PosVel topic

  2. Appends in the queue list variables avg_vel_x_queue and avg_vel_z_queue the x and z velocities (for average caculation)

Parameters:

msg – Message received in the /PosVel topic

target_callback(msg)[source]
Brief:

Subscriber callback function that updates the last target coordinates when the user enters a new target

Detailed Description:
  1. Saves the x and y coordinates of the last target in the variable last_target by splitting the message received in the /reaching_goal/goal topic

Parameters:

msg – Message received in the /reaching_goal/goal topic

scripts.srvNode_c.main()[source]
Brief:

Initialization of the service node