CS 354 Autonomous Robotics
Fall 2020
Introduction
The goal of this lab is to use numpy
to give our Turtlebots the ability to
detect and report intruders.
Step 1:
Start the Gazebo simulator and rviz2:
ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py
ros2 launch turtlebot3_bringup rviz2.launch.py
Then download and execute detector.py
. For now, just run this as a Python script:
python3 detector.py
Click the "Add" button in the lower-left corner of the Rviz window to add a visualization for the intruder detection. If you select the "by topic" tab you should see an option for "intruder -> PointStamped". Once you select that option, you should see a small ball appear one meter in front of the robot. That ball is the position where the robot is reporting an intruder.
Part 2
Open detector.py
and make sure you understand the provided code.
Your goal is to update the timer_callback
method so that it
publishes to the intruder
topic only when a sufficiently large
change is observed in the laser scan data. When a change is observed,
the published point should indicate its location. Your solution must
use only vectorized numpy operations. No loops are allowed.
Some points to consider as you develop your solution:
The first step will be to convert both
self.scan.ranges
andself.prev_scan.ranges
to numpy arrays.You should be able to subtract the two by just using the
-
operator, but keep in mind that the result will be signed. You want to look for the direction with the largest change regardless of the sign. This can be accomplished by squaring the distances or taking the absolute value of the result.The range readings are likely to contain some
inf
values indicating readings beyond the range of the sensor. You can zero these out as follows:x[np.isinf(x)] = 0
A similar trick can be used with
np.isnan
to zero out NaN values.The sensor readings will change slightly from one reading to the next even if there is nothing moving in the environment. You'll need to establish a threshold value to filter out changes unrelated to motion.
You'll need to do some trigonometry to determine where the obstacle is relative to the robot given the distance and angle of the changed range value.
Part 3
Once you are happy with the behavior of your node, turn it into a ROS2
package named detector
and submit through GitHub classroom.