← 返回

ROS2 on docker 简记

常用命令

  • xhost +local:docker
    • 让容器能够创建窗口
  • docker exec -it ros2dev bash
    • 进入已经在运行的容器
  • ros2 run my_py_pkg py_node --ros-args -r __node:=newName
    • 运行时重命名节点
  • ros2 run turtlesim turtlesim_node
    • 启动 turtlesim_node
  • ros2 run turtlesim turtle_teleop_key
    • 启动 turtle_teleop_key
  • colcon build or colcon build --packages-select my_py_pkg
    • 编译一个 ros2
  • rqt
    • 启动图形调试

R1LITE topic数据

  • topic /motion_target/target_joint_state_arm_left
---
header:
  stamp:
    sec: 1786357361
    nanosec: 918092933
  frame_id: ''
name: []
position:
- -1.3376312470362794
- 2.084679890736586
- -2.0
- -0.1825437137583914
- -0.05982525072754008
- -0.08283496254582445
velocity: []
effort: []
---
header:
  stamp:
    sec: 1786357361
    nanosec: 923052224
  frame_id: ''
name: []
position:
- -1.333029304672622
- 2.084679890736586
- -2.0
- -0.1825437137583914
- -0.06135923151542588
- -0.08283496254582445
velocity: []
effort: []
---
  • topic /motion_target/target_position_gripper_left
---
header:
  stamp:
    sec: 1786357603
    nanosec: 608128127
  frame_id: ''
name: []
position:
- 0.0
velocity: []
effort: []
---
header:
  stamp:
    sec: 1786357603
    nanosec: 658965343
  frame_id: ''
name: []
position:
- 100.0
velocity: []
effort: []
---
~$ ros2 interface show sensor_msgs/msg/JointState
# This is a message that holds data to describe the state of a set of torque controlled joints.
#
# The state of each joint (revolute or prismatic) is defined by:
#  * the position of the joint (rad or m),
#  * the velocity of the joint (rad/s or m/s) and
#  * the effort that is applied in the joint (Nm or N).
#
# Each joint is uniquely identified by its name
# The header specifies the time at which the joint states were recorded. All the joint states
# in one message have to be recorded at the same time.
#
# This message consists of a multiple arrays, one for each part of the joint state.
# The goal is to make each of the fields optional. When e.g. your joints have no
# effort associated with them, you can leave the effort array empty.
#
# All arrays in this message should have the same size, or be empty.
# This is the only way to uniquely associate the joint name with the correct
# states.

std_msgs/Header header
	builtin_interfaces/Time stamp
		int32 sec
		uint32 nanosec
	string frame_id

string[] name
float64[] position
float64[] velocity
float64[] effort

远程直连机器人

docker run -it --rm --network host \
  -e ROS_DOMAIN_ID=0 \
  -e RMW_IMPLEMENTATION=rmw_fastrtps_cpp \
  -e ROS_DISCOVERY_SERVER=192.168.0.229:11811 \
  -e ROS_SUPER_CLIENT=true \
  ros:humble-ros-base \
  bash

创建工作空间

cd ~
mkdir ws
cd ws
mkdir src

colcon build
echo "source /root/ws/install/setup.bash" >> /root/.bashrc

cd src
ros2 pkg create py_pkg --build-type ament_python --dependencies rclpy