Welcome to Research Track I Final Assignment’s documentation!

Indices and tables

User Interface Module

This module implements an user interface that allows the user to switch among the three modalities. ROS parameter are used in order to activate / deactivate the chosen modality.

ROS parameters:
  1. “active”: (type: int) parameter for activate the desired control modality

  2. “des_pos_x”: (type: double) parameter for the desired X coordinate

  3. “des_pos_y”: (type: double) parameter for the desired Y coordinate

class scripts.UI.bcolors[source]

This class is used for printing colors on the terminal

scripts.UI.flag = False

Global bool for knowing if the prevoius modality was the first one so that a goal can be canceled during the execution.

scripts.UI.interpreter()[source]

This function gets the keyboard user input and changes the ROS parameter active depending on which modality was chosen.

  • ‘1’ keyboard key is used for choosing the autonomously reaching modality;

  • ‘2’ keyboard key is used for the free keyboard driving modality;

  • ‘3’ keyboard key is used for the free keyboard driving modality with a collision avoidance algorithm;

  • ‘4’ keyboard key is used for quitting the application and terminates all nodes.

    No Args.

    No Returns.

scripts.UI.main()[source]

In the main() function the interpreter() function is looped and some introductory messages are printed on the terminal. “

First Modality Module

This is the First Robot Controlling Modality. This node makes the robot autonomously reach a x,y position inserted by the user. The robot can reach the user defined x,y coordinates thanks to the ‘move_base’ action server. The robot is going to plan the path through the Dijkstra’s algorithm.

ROS parameters:
  1. “active”: (type: int) parameter for activate the desired control modality

  2. “des_pos_x”: (type: double) parameter for the desired X coordinate

  3. “des_pos_y”: (type: double) parameter for the desired Y coordinate

These ROS parameters too and they are set by the UI node.

class scripts.go_to_desired_pos.bcolors[source]

This class is used for printing colors on the temrinal

scripts.go_to_desired_pos.goal_msg = target_pose:    header:      seq: 0     stamp:        secs: 0       nsecs:         0     frame_id: ''   pose:      position:        x: 0.0       y: 0.0       z: 0.0     orientation:        x: 0.0       y: 0.0       z: 0.0       w: 0.0

Global action message

scripts.go_to_desired_pos.active_ = 0

Global ROS poarameter to block/unlock the modality

scripts.go_to_desired_pos.desired_position_x = 0

Global X desired coordinate

scripts.go_to_desired_pos.desired_position_y = 0

Global Y desired coordinate

scripts.go_to_desired_pos.client = <actionlib.simple_action_client.SimpleActionClient object>

Global action client.

scripts.go_to_desired_pos.achieved = False

Global bool for defining if a goal was achieved or not. Useful in order to differentiate the case in which a goal was achieved (in this case the cacel request of an already canceled goal may cause an error, so I avoided to send the cancel request to the action server), and the case in which the user decides to send a cancel request before the goal achievement (in this case we must send a cancel request to the server).

scripts.go_to_desired_pos.goal_cont = 1

Global Goal counter. Takes into account the number of requests.

scripts.go_to_desired_pos.cont = 1

Feedback index. Takes into account the number of feedback for each request.

scripts.go_to_desired_pos.action_client()[source]

This function is called for both wait until we are connected to the action server and to set some parameters of the action message.

No Args.

No Returns.

scripts.go_to_desired_pos.done_cb(status, result)[source]

This is a callback function called after the execution of the action server. It gives the client information about the termination of the goal process. In particular, this callback function puts a value that into the argument status. Depending on the value of this variable the client knows the status of the goal processing after the execution.

Parameters
  • status (actionlib_GoalStatus) – terminal state (as an integer from actionlib_msgs/GoalStatus)

  • result (MoveBaseResult) – result of the goal processing.

No Returns.

scripts.go_to_desired_pos.active_cb()[source]

Callback that gets called on transitions to Active.

No Args.

No Returns.

scripts.go_to_desired_pos.feedback_cb(feedback)[source]

Callback that gets called whenever feedback for this goal is received.

Parameters

feedback (move_base_msgs/MoveBaseActionFeedback.msg) – information about the robot status during the the action server execution.

No Returns.

scripts.go_to_desired_pos.set_goal(x, y)[source]

This function fills the x, y fields of the goal message and sends a goal request to the action server.

Parameters
  • x (double) – x coordinate of the position that we want the robot to reach.

  • y (double) – y coordinate of the position that we want the robot to reach.

No Returns

scripts.go_to_desired_pos.update_variables()[source]

Function for updating the ROS parameters: active, des_pos_x, des_pos_y.

No Args

No Returns

scripts.go_to_desired_pos.main()[source]

In the main funciton some goals parameters of the goal message are set, updated variables and, if the current modality is chosen, the set_goal() function is called. Finally, the the case in which a goal was achieved and the one in which the user decides to send a cancel request before the goal achievement is managed.

Second Modality Module

Publishes to:

/cmd_vel

This is the Second Robot Controlling Modality. This node reads inputs from the keyboard and makes the robot freely navigate in the environment. Messages of type Twist() are published to the ‘/cmd_vel’ topic.

The functionality is quite similar to the teleop_twist_keyboad’s one.

class scripts.my_teleop_twist_keyboard.bcolors[source]

This class is used for printing colors on the terminal.

scripts.my_teleop_twist_keyboard.moveBindings = {',': (-1, 0, 0, 0), '.': (-1, 0, 0, 1), '<': (-1, 0, 0, 0), '>': (-1, -1, 0, 0), 'I': (1, 0, 0, 0), 'J': (0, 1, 0, 0), 'L': (0, -1, 0, 0), 'M': (-1, 1, 0, 0), 'O': (1, -1, 0, 0), 'U': (1, 1, 0, 0), 'b': (0, 0, -1, 0), 'i': (1, 0, 0, 0), 'j': (0, 0, 0, 1), 'l': (0, 0, 0, -1), 'm': (-1, 0, 0, -1), 'o': (1, 0, 0, -1), 't': (0, 0, 1, 0), 'u': (1, 0, 0, 1)}

Dictionary for movement commands. The values in the key/value pair represents the direction in which the robot should move.

scripts.my_teleop_twist_keyboard.speedBindings = {'c': (1, 0.9), 'e': (1, 1.1), 'q': (1.1, 1.1), 'w': (1.1, 1), 'x': (0.9, 1), 'z': (0.9, 0.9)}

Dictionary for velocities commands. The values in the key/value pair represents the linear and angular velocity combinations that the robot should assume after that an input occurrs.

class scripts.my_teleop_twist_keyboard.PublishThread(rate)[source]
run()[source]

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

scripts.my_teleop_twist_keyboard.main()[source]

In the main() function I made the most important changes from teleop_twist_keyboard code, that are:

  • Insertion of an if(active == 2) statement in order to block the code when another modality is running.

  • The keys now must be kept pressed in order to move the robot. I did this by setting the key_timeout variable to 0.1. Such variable was the select() timeout. That means that the select() function waits 0.1 seconds for new inputs at every loop.

Third Modality Module

Subscribes to:

/scan

Publishes to:

/cmd_vel

This is the Third Controlling Modality. Reads inputs from the keyboard and makes the robot navigate in the environment with an obstacle avoidance algorithm. Messages of type Twist() are published to the ‘/cmd_vel’ topic.

The functionality is quite similar to the teleop_twist_keyboad’s one.

class scripts.teleop_avoid.bcolors[source]

This class is used for printing colors on the terminal.

scripts.teleop_avoid.ok_left = True

Bool global variable that is True when there’s no wall on the left of the robot, otherwise is False

scripts.teleop_avoid.ok_right = True

Bool global variable that is True when there’s no wall on the right of the robot, otherwise is False

scripts.teleop_avoid.ok_straight = True

Bool global variable that is True when there’s no wall in front of the robot, otherwise is False

scripts.teleop_avoid.moveBindings = {'i': (1, 0, 0, 0), 'j': (0, 0, 0, 1), 'k': (-1, 0, 0, 0), 'l': (0, 0, 0, -1)}

Dictionary for allowed movement commands. The values in the key/value pair represents the direction in which the robot should move.

scripts.teleop_avoid.speedBindings = {'c': (1, 0.9), 'e': (1, 1.1), 'q': (1.1, 1.1), 'w': (1.1, 1), 'x': (0.9, 1), 'z': (0.9, 0.9)}

Dictionary for velocities commands. The values in the key/value pair represents the linear and angular velocity combinations that the robot should assume after that an input occurrs.

class scripts.teleop_avoid.PublishThread(rate)[source]
run()[source]

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

scripts.teleop_avoid.clbk_laser(msg)[source]

This callback function is for detecting the obstacles from laser scan information. This subscription allowed me to detect the obstacles in the simulation environment but also their position with respect to the robot by slicing the LaserScan array in three parts: front, left and right direction.

  • If no obstacles are detected on the right of the robot the variable ok_right is set to True, otherwise to False.

  • If no obstacles are detected on the left of the robot the variable ok_left is set to True, otherwise to False.

  • If no obstacles are detected in front of the robot the variable ok_straight is set to True, otherwise to False.

Parameters

msg – sensor_msgs/LaserScan.msg, scan from a planar laser range-finder.

No Returns.

scripts.teleop_avoid.pop_dict(dictionary)[source]

The obstacle avoidance algorithm is based on the modification of the Dictionary for the allowed movements. Such collision avoidance algorithm just uses the .pop(key) method that removes and returns the element idexed by key of the dictionary. When an obstacle is detected, thanks to the /scan subscription we also know its direction with respect to the robot, and this function just pops the index of such direction from the dictionary. In this way the obsatcle direction is no more allowed and it will be impossible to publish on the /cmd_vel in that direction. The .pop(key) methos is applied by considering all the combinations that the robot could face.

Parameters

dictionary (dict) – allowed movements dictionary

No Returns

scripts.teleop_avoid.main()[source]

In the main() function I made some other changes from the teleop_twist_keyboard code, that are:

  • Insertion of an if(active == 3) statement in order to block the code when another modality is running.

  • The keys now must be kept pressed in order to move the robot. I did this by setting the key_timeout variable to 0.1. Such variable was the select() timeout. That means that the select() function waits 0.1 seconds for new inputs at every loop

  • Added the above descripted functions: clbk_laser and pop_dict