tobyloki / ros2-docker-instructions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ros2-docker-instructions

Instructions

  1. Pull Docker image
docker pull arm64v8/ros:humble-ros-base
  1. Run Docker container while allowing GUIS to show (e.g. rqt_graph)
DOCKER_COMMON_ARGS="--env=DISPLAY --env=QT_X11_NO_MITSHM=1 -v /tmp/.X11-unix:/tmp/.X11-unix:rw"

sudo docker run -it -d --net=host --privileged $DOCKER_COMMON_ARGS --name ros --restart unless-stopped arm64v8/ros:humble-ros-base
  1. Add source script to ~/.bashrc
echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc
  1. Source (to get access to ros2 command)
source ~/.bashrc
  1. Make ros workspace
mkdir -p ros2_ws/src
cd ~/ros2_ws
  1. Make pub-sub package
ros2 pkg create --build-type ament_python py_pubsub
  1. Add pub-sub files
cd ~/ros2_ws/src/py_pubsub/py_pubsub

apt-get update -y

apt-get install wget

wget https://raw.githubusercontent.com/ros2/examples/humble/rclpy/topics/minimal_publisher/examples_rclpy_minimal_publisher/publisher_member_function.py

wget https://raw.githubusercontent.com/ros2/examples/humble/rclpy/topics/minimal_subscriber/examples_rclpy_minimal_subscriber/subscriber_member_function.py
  1. Add dependencies in package.xml under <license>
<exec_depend>rclpy</exec_depend>
<exec_depend>std_msgs</exec_depend>
<exec_depend>ros2launch</exec_depend>

Add entry points to setup.py

entry_points={
    'console_scripts': [
        'talker = py_pubsub.publisher_member_function:main',
        'listener = py_pubsub.subscriber_member_function:main',
    ],
},
  1. Add launch file
mkdir ~/ros2_ws/src/py_pubsub/launch

cd  ~/ros2_ws/src/py_pubsub/launch

touch pubsub.launch.py
  1. Add code to pubsub.launch.py
from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
    return LaunchDescription([
        Node(
            package='py_pubsub',
            executable='talker',
            name='talker',
            output='screen'
        ),
        Node(
            package='py_pubsub',
            executable='listener',
            name='listener',
            output='screen'
        )
    ])
  1. Install dependencies
cd ~/ros2_ws

rosdep install -i --from-path src --rosdistro humble -y
  1. Build
colcon build
  1. Add ros workspace source script to ~/.bashrc
echo "source ~/ros2_ws/install/setup.bash" >> ~/.bashrc
  1. Source
source ~/.bashrc
  1. Run
  • Run via ros2 run commands
ros2 run py_pubsub talker

ros2 run py_pubsub listener
  • Run via ros2 launch command
ros2 launch py_pubsub pubsub.launch.py

Notes

  • when editing python files, don't need to re-run source, but still need to re-build

About