The goal of this lab is to use numpy
to give our Turtlebots the ability to
detect and report intruders.
Bringup the Turtlebot and rviz according to the instructions from this previous lab.
Then download and execute sentry.py
. For now, just run
this as a Python script:
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.
Open sentry.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
and
self.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:
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.
Once you are happy with the behavior of your node, turn it into a ROS 2
package named sentry
and submit through GitHub classroom.