This is an example of ROS driver being run as an OAK 4 app together with a custom follow_object ROS2 node.
The app launches depthai_filters spatial bounding boxes (/spatial_bb) and then uses spatial detections to follow a selected object.
Object selection is done by filtering marker text in code with self.OBJECT_MARKER_TEXT (default: "person").
The node computes linear/angular velocity commands from the selected marker position and publishes them to /cmd_vel.
It is based on ROS2 Kilted, but you should be able to subscribe to topics in other distributions such as Humble or Jazzy.
Before you begin, ensure you have the following installed on your host machine:
- ROS2 (Humble, Jazzy, or Kilted)
- Rviz2
-
Install the required ROS packages:
sudo apt update sudo apt install ros-$ROS_DISTRO-rviz2 -
Source your ROS2 environment:
source /opt/ros/$ROS_DISTRO/setup.bash
-
Launch the OAK 4 app:
cd <path_to_this_example> oakctl app run .
-
In a new terminal, source your ROS2 environment and inspect topics:
source /opt/ros/$ROS_DISTRO/setup.bash ros2 topic list
-
Optionally monitor output commands:
ros2 topic echo /cmd_vel
To follow another detected object class, edit:
apps/ros/ros-follow-object/src/follow_object/follow_object/follow_object_node.py
and change:
self.OBJECT_MARKER_TEXT = "person"to the desired marker text label (for example "bottle" or "car"), then rebuild/restart the app.
- In Rviz, add a "Marker" display.
- Set the topic to
/spatial_bb. - Optionally add other displays from depthai ROS topics if needed.
This package can be adapted to any robot that listens to the /cmd_vel topic for motion control. We deployed it on an iRobot Create 3; read more in this blog post.
If you encounter issues with topic names or data types, verify that your ROS2 distribution matches the one used in the example. You may need to adjust topic names or data types accordingly.
sudo apt install ros-$ROS_DISTRO-rmw-cyclonedds-cpp
export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp