This is a simple robot simulator in ROS, which should avoid collision with the borders. It was done as a part of Research Track I course and written in C++.
The simulator required a World map, which was provided by professor Carmine Recchiuto in the following repository. Besides that, user should type catkin_make
being in catkin workspace.
To run script in the simulator, use roscore
or roscore&
(to run it in background) in your terminal at first.
After that, you should run files from downloaded repository:
$ rosrun stage_ros stageros $(rospack find second_assignment)/world/my_world.world
$ rosrun second_assignment regulator
$ rosrun second_assignment controller
Note that second_assignment
above should be changed on your folder name, where all of downloaded files from this repository are stored on your computer. For example catkin_ws/src/second_assignment/src/controller.cpp
, where second_assignment is the name of your folder in your catkin workspace.
- We can use ROS for controlling the robot
- The robot is endowed with laser scanners
- We want to have a node for the control of the robot, and an additional node which interacts with the user to:
increase/decrease the speed
andreset the robot’s position
- Everything should be done in cpp
- You should publish a velocity on the cmd_vel topic
- You can use the /base_scan topic to get information about the surrounding environment.
- In particular, the information about the distance of the obstacles is in the ranges vector.
Hint: divide the ranges vector into subsections, and take the minimum value of each subsection. This will provide information about the closest obstacles.
- The node controlling the robot should also implement the functionality for increasing/decreasing the speed
- The UI node should constantly wait for an input for the user, which can either ask to increment or decrement the velocity, or to put the robot in the initial position.
- The robot may crash if the speed is increased too much.
The proposed solution is simple and efficient and works almost perfectly. The solution consists of several cases when the robot needs to complete a particular command.
- UP arrow key = move on 0.25 faster.
- DOWN arrow key = move on 0.25 slower.
- R or r buttons = place robot on initial position.
- Q or q buttons = close program.
- Other buttons are not recognizible
- We update our speed each time, meaning that our
new_speed
is equal toold_speed + 0.25
. Besides that, we compare ournew_speed
withold_speed
each time, in order to prevent it from going in reverse direction. For example ifnew_speed
is negative, then it should stop, meaning thatnew_speed
is equal to zero. - Controller files calculates distance in 3 directions: in
front
of him, inright
andleft
in order to calculate collision risk. Since robot has vision of 360 degress following restrictions was introduced.Front
side is angle between45 and
135,
Leftside is angle between
0 and 45and
Rightside is angle between
135 and 180`. - Taking into account above restrictions, if robot is too close to the borders
threshold = 0.7
and osbtacle is from theleft
, then it should turn toright
direction. Similarly, if obstacle is from theright
side, then it should turn toleft
.
- This file is responbile for input commands. It uses
ncurses.h
, which allows to use arrow keys without waiting of pressingEnter
from the user. Right after user pressesUp arrow key
orDown arrow key
, robot will react and move with appropriate speed. The same thing is withQ - quit
andR - reset
. - It publishes results of successful commands. If robot increases/decreases a speed, then it publishes it in the terminal.
- In case if you will give to much acceleration to the robot and press
Reset
after that, acceleration will remain the same. For the future improvement, it will be better to reset acceleration as well, so robot will be placed at initial position with zero velocity and acceleration. - Pause feature can be implemeneted as well in case user wants to pause the process.