Getting Started with ROS on Embedded Systems - Examples - Proximity detector node
Getting Started with ROS on Embedded Systems RidgeRun documentation is currently under development. |
Getting Started with ROS on Embedded Systems |
---|
ROS on Embedded Systems Basics |
Getting Started |
C++ User Guide |
Examples |
Basic pipelines |
Performance |
Xavier |
Contact Us |
This page describes the ROS proximity detector node developed by RidgeRun on C++ language.
ROS versions
Distribution: Melodic Morenia [1]
Build system: catkin [2]
Introduction
To be aware of the surroundings is important for many applications, e.g. for security reasons, to avoid collisions on robotic systems, among other possibilities. This node uses information from depth images to detect nearby objects and publishes a notification message when an object is detected.
Getting the code
Contact support@ridgerun.com for getting the code or any question you have.
ROS node description
Getting the depth images
The proximity detector node uses sensor_msgs::Image type images[3]. These images are obtained by using a ROS subscriber, that subscribes to a selected ROS topic.
Processing the images
The depth images are transformed with CvBridge[4] to be processed with morphological[5] and thresholding[6] operations from the OpenCV library.
For each depth image, the following sequence of basic operations is performed:
- Invalid depth pixels removal.
- Binary threshold at a configurable distance to keep nearby objects only.
- Image erosion with a custom size kernel to remove objects that are smaller than the desired size (measured in pixels).
Sending detection notifications
The previous steps allow to detect nearby objects. If an object is detected or stops being detected, a custom ROS message is published to a ROS topic so that this information may be used by other ROS nodes.
Using the ROS node
Installing OpenCV
You may follow our Compiling OpenCV from Source page to install OpenCV. ROS Melodic Morenia uses OpenCV 3.2[7], so it is recommended to use this version to avoid conflicts.
Compilation of ROS node
To compile the proximity detector node, install ROS on your system (Getting Started) and follow the next steps:
1. Export the main directory of the proximity detector node to ease all the building process for the guide
export DEVDIR=`pwd`
2. Move to the ROS workspace and build the node with catkin
cd $DEVDIR/ros_ws catkin_make
3. Source the package
source $DEVDIR/ros_ws/devel/setup.bash
4. Install the package so that it may be used by other ROS nodes (optional)
cd $DEVDIR/ros_ws catkin_make install
Launch parameters
The following parameters are available for configuration:
- namespace: ROS namespace for the node.
- output: This may be set to "screen" to let the node print to console or to "log" to hide the node output.
- publish_to: Name of the ROS topic to publish turn notification messages to.
- subscribe_to: Name of the ROS topic that publishes the sensor_msgs::Image messages.
- publisher_buffer: Number of messages to buffer by the ROS publisher.
- subscriber_buffer: Number of messages to buffer by the ROS subscriber.
- detection_distance: Detection distance, has to be provided in millimeters.
- kernel_type: Kernel shape based on cv::MorphShapes.
- kernel_size: The kernel size sets the minimum size of objects to detect.
- message_step: Step to skip processing messages from the subscribed topic. This allows to reduce the data processing frequency.
Testing ROS proximity detector node
To launch the node:
roslaunch proximity_detector proximity_detector.launch <param>:=<value>
Replace <param> with any of the previous parameters that you may want to change, and <value> with the value you want to set to that parameter.
References
- ↑ http://wiki.ros.org/melodic
- ↑ http://wiki.ros.org/catkin
- ↑ http://docs.ros.org/en/noetic/api/sensor_msgs/html/msg/Image.html
- ↑ http://wiki.ros.org/cv_bridge
- ↑ https://docs.opencv.org/4.x/db/df6/tutorial_erosion_dilatation.html
- ↑ https://docs.opencv.org/4.x/db/d8e/tutorial_threshold.html
- ↑ https://www.ros.org/reps/rep-0003.html#melodic-morenia-may-2018-may-2023