Following config described here: https://www.kevsrobots.com/learn/learn_ros/00_intro.html
There is also a more detailed cheet sheet available here: https://www.theconstructsim.com/wp-content/uploads/2021/10/ROS2-Command-Cheat-Sheets-updated.pdf
(to use GUI components)
References:
https://www.kevsrobots.com/learn/learn_ros/15_rviz.html
https://gist.github.com/cschiewek/246a244ba23da8b9f0e7b11a68bf3285
https://stackoverflow.com/questions/72586838/xquartz-cant-open-display-mac-os
docker-compose.yml
version: "3.9"
services:
ros2:
build: .
network_mode: "host"
ipc: host
tty: true
environment:
- DISPLAY=192.168.1.135:0 # your IP (value of `/usr/sbin/ipconfig getifaddr en0`)
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix # may not be needed
dockerfile
# This is an auto generated Dockerfile for ros:ros-base
# generated from docker_images_ros2/create_ros_image.Dockerfile.em
FROM ros:humble-ros-core-jammy
# install bootstrap tools
RUN apt-get update && apt-get install --no-install-recommends -y \
build-essential \
git \
python3-colcon-common-extensions \
python3-colcon-mixin \
python3-rosdep \
python3-vcstool \
&& rm -rf /var/lib/apt/lists/*
# bootstrap rosdep
RUN rosdep init && \
rosdep update --rosdistro $ROS_DISTRO
# setup colcon mixin and metadata
RUN colcon mixin add default \
https://raw.githubusercontent.com/colcon/colcon-mixin-repository/master/index.yaml && \
colcon mixin update && \
colcon metadata add default \
https://raw.githubusercontent.com/colcon/colcon-metadata-repository/master/index.yaml && \
colcon metadata update
# install ros2 packages
RUN apt-get update && apt-get install -y --no-install-recommends \
ros-humble-desktop=0.10.0-1*
RUN apt-get update
RUN apt-get install -y --no-install-recommends ros-humble-navigation2 ros-humble-nav2-bringup
RUN apt-get install nano -y --no-install-recommends
RUN sudo echo "source /opt/ros/humble/setup.bash" >> /root/.bashrc
brew install --cask xquartz
# reinstall if necessary
docker-compose build --no-cache
docker-compose up -d
Run Xquarts
IP=$(/usr/sbin/ipconfig getifaddr en0)
/opt/X11/bin/xhost + "$IP"
docker run -it -e DISPLAY="${IP}:0" --name docker-ros2 docker-ros2
docker exec -it docker-ros2 bash
source /opt/ros/humble/setup.bash
only if dockerfile does not output this to .bashrc
cd /ros2
mkdir first_app
cd first_app
mkdir src
colcon build
ls
ros2 pkg create my_py_pkg --build-type ament_python --dependencies rclpy
colcon build
chmod 777 -R my_py_pkg/
source install/setup.bash
ros2 run my_py_pkg pub
ros2 topic echo Hello
rqt
rqt_graph
ros2 run rqt_console rqt_console
ros2 node list
ros2 node info <node_name>
ros2 node info /my_turtle
ros2 topic list [-t]
ros2 topic echo <topic_name>
ros2 topic info <topic_name>
ros2 interface show <msg type>
ros2 topic hz <topic_name>
ros2 topic pub <topic_name> <msg_type> '<args>'
ros2 topic pub --once /turtle1/cmd_vel geometry_msgs/msg/Twist "{linear: {x: 2.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 1.8}}"
Once
ros2 topic pub --rate 1 /turtle1/cmd_vel geometry_msgs/msg/Twist "{linear: {x: 2.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 1.8}}"
Every second
ros2 service type <service_name>
ros2 service list -t
ros2 service find <type_name>
ros2 service call <service_name> <service_type> <arguments>
ros2 service call /spawn turtlesim/srv/Spawn "{x: 2, y: 2, theta: 0.2, name: ''}"
ros2 param get <node_name> <parameter_name>
ros2 param set <node_name> <parameter_name> <value>
ros2 param set /turtlesim background_r 150
ros2 param dump <node_name> > <file_name>
ros2 param load <node_name> <file_name>
ros2 run <package_name> <executable_name> --ros-args --params-file <file_name>
Load on startup
ros2 action list -t
ros2 action info <action_name>
ros2 action send_goal <action_name> <action_type> <values> [--feedback]
ros2 bag record [-o <bag_file_name>] <topic(s)>
ros2 bag info <bag_file_name>
ros2 bag play <bag_file_name>