偷得浮生半桶水(半日闲), 好记性不如抄下来(烂笔头). 信息爆炸的时代, 学习是一项持续的工作.
全部博文(1748)
分类: 其他平台
2020-06-17 10:38:44
-
source /opt/ros/<distro>/setup.bash ## 最好加入到 .bashrc
-
-
printenv | grep -i ROS
-
应该出现
-
ROS_VERSION=2
-
ROS_PYTHON_VERSION=3
-
ROS_DISTRO=foxy
当环境中有多个ROS2在跑时, 需要区别 通过 ROS_DOMAIN_ID [0-232].
点击(此处)折叠或打开
-
echo "export ROS_DOMAIN_ID=
" >> ~/.bashrc
-----------------------------------------------------------------------------
学习 turtlesim 和 rqt 工具.
sudo apt install ~nros--rqt*
然后可执行 rqt
-----------------------------------------------------------------------------
ROS2 graph 是 ROS 2 的网络体系.
remapping 机制允许你重新指派节点的默认属性, 包括node_name, topic_name,
service_name 等等
例如 ros2 run turtlesim turtlesim_node --ros-args --remap __node:=my_turtle
即把名称有默认的 turtle1/2/3 改成 my_turtle
ros2 topic hz / list -t / echo / info
ros2 interface show geometry_msgs/msg/Twist #查看消息类型的定义
ros2 topic pub ''
单次 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}}"
1Hz 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}}"
-----------------------------------------------------------------------------
ros2 service list / type / list -t / find
ros2 interface show std_srvs/srv/Empty.srv # 查看 srv 的内容.
ros2 service call
例如 ros2 service call /spawn turtlesim/srv/Spawn "{x: 2, y: 2, theta: 0.2, name: ''}"
-----------------------------------------------------------------------------
ros2 param list | get
| set
| dump 被存储在 node_name.yaml 文件.
运行时加载参数文件
ros2 run --ros-args --params-file
竟然没了 load 指令, 惊讶.
-----------------------------------------------------------------------------
ros2 node info /teleop_turtle 会列出发布的话题,订阅的话题, services, action servers 和 action clients.
ros2 action list -t
ros2 action info action_name # 列出action的服务端 和 客户端.
ros2 interface show turtlesim/action/RotateAbsolute.action
ros2 action send_goal values应该是yaml的格式.
例如
ros2 action send_goal /turtle1/rotate_absolute turtlesim/action/RotateAbsolute "{theta: 1.57}"-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
rqt_console 是个GUI工具. 在此你可看到日志信息,可过滤检索手机等等
ros2 run rqt_console rqt_console
日志级别: Fatal / Error / Warn / Info 默认 / Debug
设置默认日志级别.
ros2 run turtlesim turtlesim_node --ros-args --log-level WARN
-----------------------------------------------------------------------------
建立launch 文件.
1. touch launch目录/turtlesim_mimic_launch.py
内容
点击(此处)折叠或打开
-
from launch import LaunchDescription
-
from launch_ros.actions import Node
-
-
def generate_launch_description():
-
return LaunchDescription([
-
Node(
-
package='turtlesim',
-
namespace='turtlesim1',
-
executable='turtlesim_node',
-
name='sim'
-
),
-
Node(
-
package='turtlesim',
-
namespace='turtlesim2',
-
executable='turtlesim_node',
-
name='sim'
-
),
-
Node(
-
package='turtlesim',
-
executable='mimic',
-
name='mimic',
-
remappings=[ //相当于让 turtlesim2 模拟 turtlesim 1 的动作.
-
('/input/pose', '/turtlesim1/turtle1/pose'), 相当于订阅/turtlesim1/turtle1/pose
-
('/output/cmd_vel', '/turtlesim2/turtle1/cmd_vel'), 发布到/turtlesim2/turtle1/cmd_vel
-
]
-
)
-
])
ros2 launch
ros2 launch turtlesim_mimic_launch.py 如果launch文件在当前目录下的情况
-----------------------------------------------------------------------------
sudo apt-get install ros--ros2bag ros--rosbag2*
ros2 bag record 产生一个 rosbag2-时间点 的文件.
ros2 bag record -o 录音名称 /topic1 /topic2
ros2 bag info
ros2 bag play
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------