Skip to content

A ROS Robotics simulator of a mobile robot to drive autonomously in the Monza circuit

Notifications You must be signed in to change notification settings

MatteoCarlone/Monza_Circuit_ROS

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ROS Robotics Simulator

Second Assignment of the course Research_Track_1 , Robotics Engineering.

Professor. Carmine Recchiuto.


This project makes use of a set of software libraries ROS (Robot-Operating-Systems) to build a robot application that consists in making a robot run autonomously in the Monza F1 circuit.

This assignment aims to increase my knowledge of ROS, learn the use of packages, nodes and standard ways of making these nodes communicate such as messages and services.

In Particular, I created two nodes:

  • The first one to control the movement of the robot in the environment.
  • The second one to create a basic UI (Uman-Interface) to increase or decrease, run-time, the velocity of the robot and also to reset it to its starting position.

Installing and running

In order to run more than one node at the same time i created a .launch file named run.launch.

run.launch :

<launch>	
	<node name="carcontroller_node" pkg="second_assignment" type="carcontroller_node" output="screen" launch-prefix="xterm -fg white -bg black -e" required="true"/>
	<node name="UI_node" pkg="second_assignment" type="UI_node" output= "screen" required="true"/>
	<node name="stageros" pkg="stage_ros" type="stageros" required ="true" args = "$(find second_assignment)/world/my_world.world"/>
</launch>

I wanted to open the Controller_Node in a new terminal console, so I installed and used xterm which is a standard terminal emulator build for Unix-like environments.

Command to Install xterm:

	sudo apt-get install xterm

The user can easily run all the nodes I created and also the stageros node that opens the enviroment and provides a list of usable messages and services.

Command to launch the project:

	roslaunch second_assignment run.launch

where second_assignment is the name of the ros package I created for this assignment.

StageRos_Node

The stageros node wraps the Stage 2-D multi-robot simulator, via libstage. Stage simulates a world as defined in the my_world.world file in the folder world. This file tells Stage everything about the environment, in this project the world is passed to Stage via a .png image which represents the Monza Formula 1 circuit.

Enviroment

tracciato

The robot which will be moved in the circuit is also defined in the .world file and elaborated by the stageros node. It's a simple red cube.

robot

robot

A very handy feature of the Stageros Node is its subscription to the topic cmd_vel from geometry_msgs package which provides a Twist type message to express the velocity of a robot in free space, broken into its linear and angular parts.

The Stageros Node also publishes on the base_scan topic from sensor_msgs package which provides a LaserScan type message to express a single scan from a planar laser range-finder.

Besides that, I also used a standard service called reset_position from the std_srvs package. std_srvs contains a type of service called Empty where no actual data is exchanged between the service and the client, but has proved very useful for restoring the robot's position to its starting point.

UI_Node

This node manages the UI ( USER INTERFACE ) of the project. The user can control the speed of the robot by increasing and decreasing its acceleration. He can also reset the robot's position to its initial state. The UI node receives input from a terminal window. The keyboard buttons that can be pressed are:

Commands Description
[a] To Accelerate
[d] To Decelerate
[r] To Reset the position

UI

As soon as an input arrives from outside, it is transmitted to the Controller_Node, which in turn answer by sending back the robot's degree of acceleration. This client-server communication system has been implemented by creating a custom service called Accelerate.srv . The structure of the service is:

     char input
     ---
     float32 value

Where:

  • char input is the character typed by the user on the keyboard: [a] , [d] or [r].

  • float32 value is the degree of acceleration of the robot that is transmitted as a response from the server to the client.

Controller_Node

The Controller_Node is the core of the logic for the robot's movement in the circuit, but it's also the handler of the inputs coming from the UI_Node.

In this Node, implemented in controller.cpp in the folder src, there are 4 main functions:

  • Wall_detection(range_min, range_max , Laser_Array)

    I designed this function to calculate the minimum distance between the robot and the walls. This function enables the sensor to detect obstacles in a visual cone between the range_min and the range_max argument, not expressed in degrees but in the number of elements of an array of 721 elements. The array comes from the base_scan topic and simply returns the distances between the robot and the circuit contours at a 180° angle in front of it.

    Arguments :

    • range_min (int) : the lower end of the array Laser_Scan

    • range_max (int) : the top end of the array Laser_Scan

    • Laser_Scan (float) : the array of 721 elements representing the 180° field of view in front of the robot.

    Returns :

    • low_value (float) : the minimum value of the array, between the two bounds range_min and range_max, that represent the minimum distance between the robot and the walls in the interval considered.
  • Rotation_Callback

I have implemented a Callback function that will be called whenever a message is posted on the base_scan topic.

Thanks to the function Wall_detection(), the robot can detect the shortest distance to the walls on its right, left and front :

	dist_right = Wall_Detection(0,100,Laser_Array); // detecting the shortest distance to wall on its right 
	
	dist_left = Wall_Detection(620,720,Laser_Array); // detecting the shortest distance to wall on its left 
	
	dist_front = Wall_Detection(310,410,Laser_Array); // detecting the shortest distance to wall on its front

The Logic implemented to move the robot in the track is similar to the first assignment of this course Assignment_1 :

First, the robot checks for the presence of a wall in front of it at a distance of less than 1.5, if there is not it will move straight ahead by publishing a linear velocity on the "cmd_vel" topic which, by default, is equal to 2, otherwise it will detect walls to its left and right. If the wall is closer to the robot's right, it will turn left and vice versa.

  • Reaccelerate

While testing this project, I noticed that increasing the speed of the robot also increased the probability of hitting a wall. so I created a function that simulates the curve exit of a real car. A bolean variable allows me to understand whether the robot has just curved or is coming from a straight line. The concept is simply that, only after a curve, the robot gradually increases its speed to the maximum speed set by the user thanks to the UI_Node.

  • Server

The actual server to receive the client request from the UI_Node.

Here is where the user's keyboard input is received. A switch-case statement handles the different client requests. The [a] allows to accelerate, the [d] to decelerate and the [r] to call the standard 'reset_position' service from the 'std_srvs' package: this tool made it very easy to reset the robot to its initial position. Whenever the user decides to accelerate, a multiplier ( global variable ) will be incremented. The opposite happens for deceleration. the reset of the robot also change its velocity to the default value of 2.

This function also creates the server's "response" to the client's "request"; in particular, the "response" consists of the float containing the degree of acceleration (i.e. the value of the multiplier), which will then get printed on the screen in the UI_Node.

if the user inputs a wrong key the server will send a negative to the UI which will print a message advertising the user.

Project flowchart

the logic of this assignment is well illustrated by the flowchart in the figure below.

Blank diagram - Page 1

Possibile Improvements

  1. Having implemented a function for exiting a curve, it is certainly also possible to manage the behaviour of the robot when entering a curve. However, even with the re-acceleration function, the robot can complete a lap at a maximum speed of 20.
  2. One might think of dividing the robot's field of view more widely and changing the speed of rotation in a curve more precisely with respect to the position of the wall closest to the robot.

Robot Movement

The video shows a complete lap.

lap.mp4

About

A ROS Robotics simulator of a mobile robot to drive autonomously in the Monza circuit

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 54.8%
  • CMake 45.2%