Warning
This page is located in archive. Go to the latest version of this course pages. Go the latest version of this page.

Homework 02

Your task is to create a simple random walk navigation algorithm for the Turtlebot robot in a simulator. The robot should randomly move in the environment without colliding with obstacles. The onboard laser scanner should be used to detect obstacles in front of the robot and based on the obstacle proximity one of the following actions should be performed:

  • go forward without turning (no obstacles ahead),
  • go forward while turning from the obstacle (obstacle in far proximity),
  • turn away from the obstacle by rotating at one position (obstacle in close proximity).

The robot has only 30s for random movement. During that time it should get at least 1 m away from the start. After 30s from start of the node, the robot should stop, and the light in the environment should be turned off. An example of the expected behavior can be seen here:

How to start

Start by downloading the archive for this homework. There, you will find two packages:

  • aro_sim — package containing all necessary files to launch the ARO simulation (including launch files, models, and worlds specifications),
  • aro_robocop — template package for implementation of reactive control of the robot (and also template package for your homework).

The aro_robocop package contains a basic structure and a script robocop.py with TODOs including many useful comments. These TODOs are there to guide you on what should be put into the code. You are not required to exactly follow the hints in the template. Feel free to come up with your own, better, solution or nicer code format. However, your code has to conform all requirements described in Requirements & constraints section.

To run the simulation, unpack the downloaded zip into the src folder of your workspace, start the singularity, build the workspace, source the devel/setup.bash, and launch the simulation by command roslaunch aro_sim onlysim.launch. If you have the same workspace as for the second lab then please remove the aro_sim package from the lab02_packages folder such that you do not have two aro_sim packages in the same workspace.

After a few moments, you should see the RViz tool and Gazebo simulator with the robot and a simple maze. Since you have not programmed a localization routine for the robot yet, precise odometry is unknown, so do not get startled by red errors in RViz.

If you are running a custom ROS install, you will also need to install an additional package: sudo apt install ros-noetic-turtlebot3-simulations

The next step is to launch the robocop node along with the ARO simulation. For this, you have to put the aro_robocop package in the same workspace as aro_sim package, build the package workspace, source it and launch the simulation and the robocop node by a single launch file: roslaunch aro_robocop robocop_sim.launch

Explore the launch files to get an idea how they work, i.e., how a launch file from one package can execute scripts through launch files belonging to a different package.
If you do not know how to do some of the required steps, please first try re-reading the Lab 01 and Lab 02 materials. Then, try searching for your answer at wiki.ros.org.

General Description

The robot will be spawned in a simple maze with some walls (see below).


The motion of the robot can be controlled by setting its desired forward and angular velocity (differential drive robot). In this homework, you should implement reactive behavior by constantly checking the robot's laser scanner output to see if there are obstacles in front of the robot and adapt the control inputs (velocities) so that the robot is moving through the environment while avoiding collisions. For example, you can check the minimum distance in the measurements taken at an angle between -30° and 30° (similarly to the first homework) to determine whether there is a potential collision in direction of robot movement. If not, the robot can move ahead at full speed safely. If the robot is getting closer to an obstacle (first distance limit), it should decrease its forward velocity and start turning away from the obstacle. The direction of the rotation can be determined, e.g., by comparing the average distance from the left half of the scan (between -30° and 0°) and the right half of the scan (between 0° and 30°). If the robot comes even closer (second distance limit), it should stop the forward movement completely and only turn. Once there are no obstacles in front of it, it should start moving forward again.

Requirements & constraints

  • The robot has to start moving after start of the node and has to be moving all the time during the 30 seconds period (at least one of the control inputs has to be non-zero).
  • After 30 seconds from the start of the node, the robot must stop and do not start to move again.
  • After 30 seconds from the start (i.e., when the robot stops), the light with name sun has to be removed from the simulation world (turn off the light) by calling the Gazebo service.
  • The robot has to reach a position at least 1 meter far from its starting position within the 30 second limit (neither turning on a single spot without forward motion for 30 seconds, nor applying unreasonably small forward velocity for the whole time is not acceptable).
  • The robot is not allowed to hit an obstacle.
  • The script must unsubscribe from topic and cleanly finish by itself after the time limit is up.

Submission and evaluation

Submit your whole aro_robocop package FOLDER including robocop.py script in a single .zip file to the submission system.

Successful solution must:

  • Be launchable stand-alone using rosrun.
  • Not include any bugs (e.g., no crashing of the code).
  • The code must work in the robolab singularity image, without any modifications or additions.
  • Fulfill all requirements described in Requirements & constraints section.
Do not submit aro_sim package.

Hints

  • The robot can be controlled using the /cmd_vel topic. The message type is geometry_msgs/Twist. Key components are the x component from linear velocity (forward velocity in m/s, negative for reverse) and z component from angular velocity (angular velocity in rad/s, positive/negative to rotate in counter clockwise (CCW)/clockwise (CW) direction). It is suggested to use the keyword argument latch=True for the publisher. This keeps the last published message in the topic (a single published message might otherwise not be received by the robot).
  • You can reuse the code from your solution of HW 01 for data subscription. The data is similar, but be sure to check the validity of the data from laser scanner first.
  • You might want to evaluate the data on the left/right of the robot (the same way, as you evaluate them in front of the robot, just a different range of angles) to determine the best direction of turning (CW or CCW).
  • You can also move in reverse if you wish to, in order to recover from “dangerous” places. However, note that these situations can be solved also by turning the robot and then applying positive forward velocity.
  • There is an “on_shutdown” event callback set in the template code. This is to make life easier for you and stop the robot when you stop the node (otherwise the robot would keep applying the control inputs set at the moment of node shutdown).
  • You can tune all of the parameters above to your liking.
  • You can use two speed levels based on the obstacle proximity, e.g.:
    • slow_speed = 0.2 m/s → obstacle detected, turning away from obstacles.
    • fast_speed >= 0.5 m/s → no obstacles detected (you can go faster if you dare).
  • The angular velocity is suggested to be higher than 0.3 rad/s during turning.
  • The first distance limit (robot slows down & starts turning) is suggested to be between 1.5 to 3 meters.
  • The second distance limit (robot stops, only turns) is suggested to be at least 0.7 meters.
  • You can list all existing services, once the simulation is started to find the proper service (remember, rosservice list/info).
courses/aro/tutorials/homework02.txt · Last modified: 2023/03/01 13:28 by penicrob