Skip to content

Research Track 1 - Third assignment - Control of a robot in a simulated environment using Gazebo and Rviz

Notifications You must be signed in to change notification settings

simone-contorno/rt-assignment-3

Repository files navigation

Third Assignment of Research Track 1 - Robotics Engineering

Author: Simone Contorno


Control of a robot in a simulated environment.

Introduction

An overview of this program function.
Go to Introduction

How it works

A rapid description of how the program works (pseudo-code).
Go to How it works

Installation and Execution

How install and run this program in Linux.
Go to Installation and Execution

Improvements

How this program could be improved.
Go to Improvements

Introduction

This program manage a robot, endowed with laser scanners, which should move autonomously inside a map.
You can use the user interface to:

  1. Let the robot to autonomously reach a x,y coordinate inserted by command line.
  2. Drive the robot with the keyboard.
  3. Drive the robot with the keyboard availing of a simple driving assistance.

The map is this one:

Rviz:


Gazebo:

How it works

The program use the launch file "simulation_gmapping.launch" to run the simulated environment, and the launch file "move_base.launch" to run the action move_base that provides several topics, including:

  • move_base/goal to publish the goal position;
  • move_base/feedback to receive the feedback;
  • move_base/cancel to cancel the current goal.

There are 3 subscribers that run simultaneously thanks to a multi-thread architecture given by the ROS class AsyncSpinner:

  • sub_pos: subscribes to the topic /move_base/feedback through the function currentStatus that continuosly update the current goal ID and check whether the robot has reached the goal position.
  • sub_goal: subscribes to the topic /move_base/goal through the function currentGoal that continuosly update the current goal coordinates.
  • sub_laser: subscribes to the topic /scan through the function drivingAssistance that continuosly take data by the laser scanner and, if the driving assistance is enabled, help the user to drive the robot stopping its if there is a wall too close in the current direction.

The robot can:

  1. Autonomously reaching a goal position:
    • ask to the user to insert the coordinates x and y to reach;
    • save the current time;
    • set the frame_id to "map" (corresponding to the environment that is used) and the new coordinates to reach;
    • publish the new goal to move_base/goal.
  2. Cancel the current goal:
    • take the current goal ID;
    • publish its to the topic move_base/cancel.
  3. Be driven by the user through the keyboard (the list of commands is printed on the console).

You can change 3 constant values to modify some aspect of the program:

  • DIST: minimum distance from the wall with the driving assistance enabled.
  • POS_ERROR: position range error.
  • MAX_TIME: maximum time to reach a goal (microseconds).
In the code these appear like:

#define DIST 0.35 
#define POS_ERROR 0.5 
#define MAX_TIME 120000000 

A short description of the program behavior is this one:


FUNCTION manualDriving
    WHILE user does not quit
        TAKE user input through the keyboard
        EXEC corresponding task
        PUBLISH new robot velocity
    ENDWHILE
ENDFUNCTION

FUNCTION drivingAssistance WITH (msg)
    COMPUTE minimum distance on the right
    COMPUTE minimum distance in the middle
    COMPUTE minimum distance on the left
    
    IF driving assistance is enabled AND
        the robot is going against a wall THEN
        SET robot velocity TO 0
        PUBLISH robot velocity
    ENDIF

    IF a goal position is set THEN
        COMPUTE the time elapsed
        IF the time elapsed IS GREATER THAN 120 seconds THEN
            DELETE current goal
        ENDIF
    ENDIF
ENDFUNCTION

FUNCTION currentStatus WITH (msg) 
    SET current robot position
    COMPUTE the difference between the current robot position
    and the current goal position
    IF the difference IS LESS THAN 0.5 THEN
        STOP to compute the elapsed time
    ENDIF
ENDFUNCTION

FUNCTION currentGoal WITH (msg)
    SET current goal position
ENDFUNCTION

FUNCTION userInterface 
    WHILE user does not quit
        TAKE user input through the keyboard
        EXEC corresponding task
    ENDWHILE
ENDFUNCTION

FUNCTION main WITH (argc, argv)
    INITIALIZE the node "final_robot"

    SET the first publisher TO "move_base/goal"
    SET the second publisher TO "move_base/cancel"
    SET the third publisher TO "cmd_vel"

    SET the first subscriber TO "/move_base/feedback" WITH currentStatus
    SET the second subscriber TO "/move_base/goal" WITH currentGoal
    SET the third subscriber TO "/scan" WITH drivingAssistance

    INITIALIZE spinner WITH 3 threads
    START spinner
    CALL userInterface
    STOP spinner
    CALL ros::shutdown
    CALL ros::waitForShutdown

    RETURN 0
ENDFUNCTION

Look the pseudocode file final_robot_pseudocode for more details.

Installation and Execution

Open the terminal, and download this repository:

git clone https://github.com/simone-contorno/rt-assignment-3

Copy or move the folder final_assignment into the src folder of your ROS workspace.
Go into the root folder of your ROS workspace and type:

catkin_make

Afterwards type:

rospack profile

Now, open 3 terminals; in the first one launch the environment:

roslaunch final_assignment simulation_gmapping.launch

In the second one launch the action move_base:

roslaunch final_assignment move_base.launch

In the third one run the node final_robot:

rosrun final_assignment final_robot

Alternatively, you can launch all these nodes using the launch file final_assignment.launch, but first you need to install xterm:

sudo apt install xterm

Now you can type:

roslaunch final_assignment final_assignment.launch

Improvements

The driving assistance can be improved by move the robot in the right direction when the user is driving its against a wall, instead of just stop it.

Thanks to have read this file, i hope it was clear and interesting.

About

Research Track 1 - Third assignment - Control of a robot in a simulated environment using Gazebo and Rviz

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages