Warning
This page is located in archive.

Homework 02 - Reactive controller

Deadline: 10 March 2024, 23:59 CET (Monday labs) / 13 March 2024, 23:59 CET (Thursday labs)

Your task is to create a simple reactive behavior for the Turtlebot robot in a simulator. The robot should move in the environment without colliding with obstacles. The onboard laser scanner should be used to detect obstacles in the surrounding 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 motion of the robot has to be started after an activation service is called. Then, the robot has only 50 s for a movement. Within the specified time limit the robot should visit a location at least 1.5 m away from the start, travel at least 8 meters, stop its motion and call a service requesting evaluation of the mission. During the mission, the robot also has to respond to call of deactivation service by stopping its motion. The more detailed instructions are provided in task description below. An example of the expected behavior can be seen here:

Responsible lecturer: Robert Pěnička (penicrob@fel.cvut.cz)

Assignment

  1. Follow the instructions provided to install ARO ROS environment for the solution of all home works and a semestral work in Autonomous Robotics course.
  2. Implement the reactive controller for navigation of the Turtlebot robot in the environment in file reactive_controller.py in package aro_reactive_control. The implementation can be based on your code implemented in HW 01 and has to implement following functionality:
    • ROS service server that accepts requests of type SetBool on topic /reactive_control/activate. When a request with data == True is obtained the robot is allowed to move. Once a request with data == False is obtained, the robot has to stop and remain static until a request with data == True is obtained.
    • Control the robot's forward velocity and angular velocity by publishing message of type geometry_msgs/Twist on topic /cmd_vel.
    • Implement ROS service client for initiating evaluation of the mission of type std_srvs/Trigger on topic /reactive_control/evaluate_mission.
    • Implement ROS Timer to check the time elapsed from the start and stop the robot and call the mission evaluation request at the correct time.
  3. The correct implementation has to further fulfill following requirements:
    • The robot is static before the activation service is called for the first time.
    • The robot applies zero control inputs after activation service with data == False is called and remains static till next call of the activation service.
    • The robot stops its motion and sends request for mission evaluation within 50 seconds from the first call of activation service.
    • The robot reaches position which is at least 1.5 meters far from the starting position.
    • The robot travels at least 8.0 meters during the mission.
    • The robot does not collide with obstacles.
The navigation of the robot (computation of control inputs) is expected to be based on detected minimum distances in particular sectors that you have implemented in HW 01. However any navigation approach that fulfills the stated requirements is acceptable solution of this homework. Thus, feel free to explore other approaches.

Robot control

The Turtlebot robot is a robot of type differential drive, which has two control inputs forward velocity and angular velocity. In the ROS implementation, these control inputs are set by publishing message of type geometry_msgs/Twist on topic /cmd_vel where the control inputs are represented by field linear.x for forward velocity (m/s, negative for reverse) and angular.z for angular velocity (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).

Example approach

The following description suggests one of possible approaches to achieve desired reactive behavior. Feel free to improve it or implement your own idea to solve the introduced problem.

Desired reactive behavior can be achieved 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 minimum 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.

Visualization and local testing

You can run your solution including RViz visualization by running

roslaunch aro_reactive_control hw02_sim.launch
. This launch file starts:

  • simulation of Turtlebot robot,
  • your node implemented in reactive_controller.py,
  • script that calls a service to activate the motion of the robot and publishes data for visualization,
  • and preconfigured RViz window visualizing the robot in the environment and mission-related statistics.

Local Evaluation

Local evaluation of your solution can be run using

roslaunch aro_reactive_control hw02_eval.launch
This will start an evaluation script which calls the activation service to activate and deactivate motion of the robot, checks correct reaction of your node on service calls, and checks the performance metrics. Once the evaluation is finished, the script prints results of the evaluation in the command line. The output of the evaluation for correct implementation should look like:

Hints

  • You can reuse the code from your solution of HW 1 for data subscription and processing. 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.
  • 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.
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.

Submission and evaluation

Run script aro_exploration/homeworks/create_hw02_package.sh to create an archive containing your implementation (reactive_controller.py) and upload it to upload system. The script reactive_controller.py must be “runnable” from the provided launch file hw_2_eval.launch. 5 points will be awarded for a valid submission fulfilling all requirements described in Assignment section.

Be patient. The evaluation process can take up to 2 minutes. Depending on performance of your solution.
courses/aro/tutorials/homework02.txt · Last modified: 2024/03/20 11:03 by peckama2