ros-roslaunch启动多台机器ros节点

本文介绍如何在两台Ubuntu16.04系统上通过ROS进行远程节点启动的配置及解决SSH连接问题的方法。涉及ROS环境变量设置、launch文件编写、SSH密钥算法调整等内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

两台电脑,分别为p11和p12,环境均为ubuntu16.04,launch代码如下

<launch>
  <machine name="p12" address="p12" env-loader="/home/nvidia/setup.sh" user="nvidia"/>
  <machine name="p11" address="p11" env-loader="/home/nvidia/setup.sh" user="nvidia"/>
  <node machine="p12" name="test_node" pkg="projection" type="test_node" output="screen">
  </node>
</launch>

On p12, the /home/nvidia/setup.sh :

#!/usr/bin/env bash
#export p11=192.168.10.37
#export p12=192.168.10.54
#export fangli0=192.168.10.42
export ROS_IP=p12
export ROS_MASTER_URI=p11:11311
export ROSLAUNCH_SSH_UNKNOWN=1

export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/lib
export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig/
export ROS_MASTER_URI=http://p11:11311
#export ROS_IP=192.168.10.54
export ROS_HOSTNAME=p12

# for lanemarking_liuli
export LD_LIBRARY_PATH=/home/nvidia/Liuchao/local/lib:${LD_LIBRARY_PATH}

#. /home/nvidia/setup.sh
source /home/nvidia/.bashrc
source /opt/ros/kinetic/setup.bash
source /home/nvidia/fangli/perception/code/perception_ros/devel/setup.bash
exec "$@"

attention please:

ROS has a flaw (feature?) in that it uses a library to so SSH, rather than the usual SSH client. This library does not support the default key algorithm used by the typical SSH client. This means that even though you can SSH to the remote machine, ROS cannot, because the key algorithm isn’t supported.

The fix is to remove the stored key in ~/.ssh/known_hosts, then SSH again to the remote machine, specifying the -oHostKeyAlgorithms=’ssh-rsa’ command-line option to force the use of the the RSA algorithm. Once this is done ROS can connect to the remote machine.
http://answers.ros.org/question/244060/roslaunch-ssh-known_host-errors-cannot-launch-remote-nodes/?answer=244064#post-id-244064

### 如何通过 `roslaunch` 启动 ROS 的话题发布与订阅节点ROS 中,`roslaunch` 是一种强大的工具,用于同时启动多个节点并管理复杂的依赖关系。要实现通过 `roslaunch` 启动一个话题发布和订阅的节点,可以按照以下方法设计配置文件。 #### 配置 launch 文件 创建一个新的 `.launch` 文件来定义需要启动节点及其参数。假设我们有一个简单的发布者节点 (`talker_node`) 和一个订阅者节点 (`listener_node`),它们分别负责发布和接收 `/chatter` 主题的消息。 以下是示例 launch 文件的内容: ```xml <launch> <!-- 定义 talker 节点 --> <node pkg="my_package" type="talker_node" name="talker" output="screen"> <!-- 可选:设置参数 --> <param name="publish_rate" value="10"/> </node> <!-- 定义 listener 节点 --> <node pkg="my_package" type="listener_node" name="listener" output="screen"/> <!-- 如果有额外需求,比如条件化运行某些节点 --> <group if="$(arg condition)"> <node pkg="other_package" type="additional_node" name="extra_node"/> </group> </launch> ``` 上述代码中: - `<node>` 标签指定了包名 (`pkg`)、可执行文件名称 (`type`)、节点名称 (`name`) 以及日志输出方式 (`output`)。 - 参数可以通过 `<param>` 标签传递给节点[^1]。 - 使用 `<group>` 标签可以根据特定条件控制一组节点的行为[^3]。 #### 编写发布者和订阅者的 Python 或 C++ 实现 为了使 `roslaunch` 正常工作,确保已编写好对应的发布者和订阅者逻辑。这里提供了一个基于 Python 的简单例子作为参考。 ##### 发布者 (talker_node.py) ```python #!/usr/bin/env python import rospy from std_msgs.msg import String def talker(): pub = rospy.Publisher('chatter', String, queue_size=10) rospy.init_node('talker', anonymous=True) rate = rospy.Rate(10) # 设置发布频率为每秒 10 条消息 while not rospy.is_shutdown(): hello_str = "hello world %s" % rospy.get_time() rospy.loginfo(hello_str) pub.publish(String(data=hello_str)) rate.sleep() if __name__ == '__main__': try: talker() except rospy.ROSInterruptException: pass ``` ##### 订阅者 (listener_node.py) ```python #!/usr/bin/env python import rospy from std_msgs.msg import String def callback(msg): rospy.loginfo(rospy.get_caller_id() + ' I heard %s', msg.data) def listener(): rospy.init_node('listener', anonymous=True) rospy.Subscriber('chatter', String, callback) rospy.spin() if __name__ == '__main__': listener() ``` 以上两个脚本应保存至相应的 ROS 包目录下,并赋予可执行权限以便被 `roslaunch` 执行。 #### 运行 Launch 文件 完成上述配置后,在终端输入如下命令即可启动整个系统: ```bash roslaunch my_package example.launch ``` 其中 `example.launch` 即为我们之前编写的 launch 文件名字[^2]。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值