ROS2 : 1/? Create a visual follower =================================== We'll learn how launch ROS1 nodes with ROS2 nodes. In this example we'll see a follower robot with a camera (same concept as the sensorfollower but he will detect target with the color) in ROS2 with a node that allows object recognition. Step 1 : Create the visual follower package ------------------------------------------- We'll create a new package who allow the following of a visual target called ``pkg_visu`` and a new node ``visu.cpp``:: ros2 pkg create --build-type ament_cmake pkg_visual --dependencies sensor_msgs geometry_msgs rclcpp OpenCV cv_bridge image_transport --node-name visual .. note:: parameters: - dependencies : parameter to declare dependencies - sensor_msgs : library to use sensor, in this tuto we'll use a camera - geometry_msgs : library to use variables like vector or poses - rclcpp : primary library, allow the use of ROS with c++ - OpenCV : library allowing the exploitation of images - cv_bridge : library bridging opencv and ros - image_transport : Optimize and transport images - node : parameter to create nodes - visual : main node - DetectionCnam_codels : ??? (à modifier) Step 2 : -------- Open on QtCreator and edit visu.cpp. You can delete all what is written. First, include the libraries:: #include #include "opencv2/opencv.hpp" #include "rclcpp/rclcpp.hpp" #include "sensor_msgs/msg/image.hpp" #include "geometry_msgs/msg/twist.hpp" #include "cv_bridge/cv_bridge.h" Now paste this universal main code:: int main(int argc, char ** argv) { (void) argc; (void) argv; rclcpp::init(argc, argv); rclcpp::spin(node); rclcpp::shutdown(); return 0; } - init is the initialization - spin is a loop of ``node`` which is not even declared - shutdown is the end of execution Now we'll create a class ``visual``, we'll declare inside this class the main algorithm. Paste that between the ``include`` and the ``main()``:: class Visu : public rclcpp::Node { }; You can add the following line in the ``main`` before the ``spin``, it will define which node will be launched:: auto node = std::make_shared();