Browsing through the simple pub sub model in ROS2
- Download install_ros2.sh in your computer.
- Open a terminal and run sudo chmod +x install_ros2.sh.
- Execute the bash file by running sudo ./install_ros2.sh.
- Source the bashrc file source ~/.bashrc.
printenv | grep -i ROS
The response should be something like this:
ROS_VERSION=2
ROS_PYTHON_VERSION=3
ROS_DISTRO=foxy
mkdir -p ~/dev_ws
Clone the repository. While still at the root directory ~/dev_ws, make sure you do not have any missing dependencies.
rosdep install -i --from-path src --rosdistro foxy -y
We have two packages here for pubsub: one in python and the other in cpp. We need to build both of them before execution. Remember to run the following commands from root directory ~/dev_ws.
colcon build --packages-select cpp_pubsub
colcon build --packages-select py_pubsub
Let's run the talker(publisher) node in python and the listener(subscriber) in cpp.
- Open new terminal, navigate to
~/dev_ws
and source the setup file by running. install/setup.bash
- Run the talker node :
ros2 run py_pubsub talker
- Open another terminal, navigate to
~/dev_ws
and source the setup file by running. install/setup.bash
- Run the subscriber node :
ros2 run cpp_pubsub listener