情況說明:目標是實現ros2容器和ros1主機的通信,可以起一個ros1容器作為橋梁(若是在一個主機同時包含ros1&ros2,配置更加方便).
1.起一個 noetic 的容器
docker run -it --network host --name my_bridge ros:noetic-ros-core
2.進入 https://github.com/ros2/ros2/releases/tag/release-foxy-20230620,把ros2 的預編譯版本拷貝到noeltic容器里 (注意版本,lsb_release -a 查看ubuntu版本,下對應的ros2預購建二進制文件).
docker cp /home/firefly/ros-linux my_bridge:/
(筆者這里是先下載到ubuntu主機里,后拷貝到容器里面)
3.進入容器,在~/.bashrc
或 bash
或 ~/.zshrc
或zsh
中配置環境(一般在~/.bashrc
里面配):
export ROS1_INSTALL_PATH=/opt/ros/noetic
export ROS2_INSTALL_PATH=/ros-linux
source ~/.bashrc
4.在noetic容器里裝 spdlog
apt install libspdlog-dev
5.在noetic容器git clone ros2/ros1_bridge源碼:
git clone https://github.com/ros2/ros1_bridge.git
6.按照GitHub官方ros2/ros1_bridge教程依次啟動四個終端(使用docker attach my_bridge
&docker exec -it my_bridge /bin/bash
)
(1)shell A:source ${ROS1_INSTALL_PATH}/setup.bashroscore
(2)shell B:source ${ROS1_INSTALL_PATH}/setup.bashsource ${ROS2_INSTALL_PATH}/setup.bashexport ROS_MASTER_URI=http://localhost:11311ros2 run ros1_bridge dynamic_bridge --bridge-all-topics
(3)shell C:source ${ROS1_INSTALL_PATH}/setup.bashsudo apt-get install ros-noetic-ros-tutorialsrosrun rospy_tutorials talker
(4)shell D:source ${ROS2_INSTALL_PATH}/setup.bashros2 run demo_nodes_cpp listener