- Creating the workspace:
mkdir -p ~/learning_ros_ws/src
cd ~/learning_ros_ws/src- Generate the C++ package:
ros2 pkg create --build-type ament_cmake learning_nodes --dependencies rclcpp std_msgs- Added my minimal publisher and subscriber
.cppfiles - Edit CMakeLists.txt to add the rules to compile the
.cppfiles into executables:- Rules added before
ament_package()section
- Rules added before
# Add the publisher executable
add_executable(talker src/minimal_publisher.cpp)
ament_target_dependencies(talker rclcpp std_msgs)
# Add the subscriber executable
add_executable(listener src/minimal_subscriber.cpp)
ament_target_dependencies(listener rclcpp std_msgs)
# Tell ROS 2 where to install the executables so it can find them later
install(TARGETS
talker
listener
DESTINATION lib/${PROJECT_NAME})- Build the workspace:
cd ~/learning_ros_ws
colcon build- Source and Run
- The install folder contains the setup scripts needed to inject this specific workspace into your terminal's environment
source ~/learning_ros_ws/install/setup.zsh
ros2 run learning_nodes talkerand
source ~/learning_ros_ws/install/setup.zsh
ros2 run learning_nodes listener