Warning
This page is located in archive.

Homework 02

Your task will be to create a simple control algorithm for the Turtlebot in a simulator. Something similar to what you can see here:

Start by downloading template package and the simulator packages . There, you will find a package with basic structure and a script with many useful comments. The TODOs are there to guide you on what you should put into the code. It is not required that your code looks exactly as hinted in the template. If you can come up with a better solution/nicer code format, please, feel free to do it. You code however, should work EXACTLY as is described below.

If you don't know how to do some of the required steps, please first try re-reading the lab 01 and 02 materials. Then, try searching for your answer at wiki.ros.org. And if everything else fails, contact us.

The archive also contains the necessary files to launch the simulation in its own package. To test it out, build the package workspace, source it and launch:
$ roslaunch aro_sim onlysim.launch If you are running a custom ROS install, you will also need:
$ sudo apt install ros-noetic-turtlebot3-simulations

After a few moments, you should see the RViz tool and Gazebo simulator with the robot and a simple maze (see image below). Since the you have not programmed a localization routine for the robot yet, precise odometry is unknown, so don't get startled by red errors in RViz. Try experimenting with choices of base frame instead to get the idea of how the visualization works!

Third step is to launch your homework package containing the source code and a launch file (see below). You have to put the package in the same workspace as aro_sim package. After that, you can start reading the description below and implementing your solution, good luck. To test your solution in simulator, build the package workspace, source it and launch:
$ roslaunch aro_robocop robocop_sim.launch

Also make sure you explore the launch files to get an idea how they work, ie. how a launch file from our homework package executes scripts through launch files belonging to a different package.

General Description

The robot will be spawned in a simple maze with some walls (see below, robot is the black thing just below the obstacle in the middle). You should constantly check the robot's laser scanner output to see if there are obstacles in front of the robot. If not, the robot should move ahead at full speed. If the robot is getting closer to an obstacle (first distance limit), it should slow down its forward movement speed and start turning away from the obstacle. If it comes even closer, 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.

This should continue until a 30 second time limit (from the start of the robot control node) expires. At that moment, the robot should stop and remain stopped. Also, the sun should be removed from the simulation, turning off the light.

Requirements & Constraints

  • The robot should be moving at two speeds:
    • slow_speed = 20 cm/s → obstacle detected, turning
    • fast_speed >= 0.5 m/s → no obstacles detected (you can go faster, if you dare but not slower)
  • The angular speed must be higher than 0.3 rad/s
  • The first distance limit (robot slows down & starts turning) must be between 1.5 to 3 meters
  • The second distance limit (robot stops, only turns) must be at most 0.7 meters
  • You can tune all of the parameters above to your liking, as long as they are within the specified constraints
  • Each change in speed (both linear & angular) must be logged (see template code for examples)
  • After 30 seconds from the start, the robot must stop and not move again.
  • After 30 seconds from the start (i.e., when the robot stops), call the Gazebo service to remove the sun (turn off the light). You can list the existing services, once the simulation is started to find the proper service (remember, rosservice list/info)
  • Both, your code and the simulator, must be started using a single launch file. That is, this launch file will start onlysim.launch and your robot control script.

Submission and evaluation

Successful solution (worthy of the points) must:

  • Be launchable using a single launch file that is provided, but also stand-alone using rosrun.
  • Not include any bugs (e.g., no crashing of the code).
  • Correctly control the robot, that is:
    • the robot must be stopping, slowing down, speeding up, and turning, depending on the obstacles around it, as described in the previous section,
    • it is allowed for the robot to crash while going at full speed (the higher speed limit) but it must not crash when in slow moving mode,
    • if robot crashes, it must always recover (e.g., continue rotating away from the obstacle and start moving forward as soon as it can),
    • the robot must be always moving (either rotating, or moving forwards, or both but never completely stopping, unless the time limit is up).
  • The robot must log what it is doing (i.e., rospy.loginfo when changing behavior).
  • Stop the robot and turn off the light after 30 second from the start of the control node.
  • The script must unsubscribe from topic and cleanly finish by itself after the time limit is up.
  • The code must work in the robolab singularity image, without any modifications or additions.

Submit your whole aro_robocop package FOLDER in a single .zip file to the submission system. Do not submit aro_sim package.

Hints

  • The robot can be controlled using the /cmd_vel topic. The message type is “Twist”. Key components are the “x” from linear velocity (forwards speed in m/s, negative for reverse) and “z” from angular velocity (rotational speed in rad/s, positive/negative to rotate in CCW/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 HW 01 for subscribing. The data is similar, but be sure to check the data from laser scanner first. However, since you want the robot to not crash, it is best to look at the minimum distance in front of it.
  • You might want to look to the left/right of the robot (the same way, as you did when looking in front of it, just a different angle) before turning left or right.
  • You can also move in reverse if you wish to, in order to recover from “dangerous” places.
  • 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 doing whatever it was doing at the moment of node shutdown).
courses/b3m33aro/tutorials/homework02.txt · Last modified: 2022/02/24 11:32 by nekovfra