前言
最近在逛ros buglist
的时候发现了一个新功能,通过ssh
远程开启节点,不是ssh
登录上之后再开,是ros
通过ssh
开。。。
我都能ssh
,为啥子还要配置很复杂的去开节点,先不管,体验一把
配置本地环境
这里的配置和主从机有点像,但是实现方式不一样
打开 .bashrc
export ROS_IP=192.168.0.113
export ROS_MASTER_URI=http://192.168.0.116:11311
export ROSLAUNCH_SSH_UNKNOWN=1
配置完source
下
配置远端环境
修改 /opt/ros/melodic/env.sh
,根据版本变
#!/usr/bin/env sh
# generated from catkin/cmake/templates/env.sh.in
#add here
export ROS_IP=192.168.0.116
#add
if [ $# -eq 0 ] ; then
/bin/echo "Usage: env.sh COMMANDS"
/bin/echo "Calling env.sh without arguments is not supported anymore. Instead spawn a subshell and source a setup file manually."
exit 1
fi
# ensure to not use different shell type which was set before
CATKIN_SHELL=sh
# source setup.sh from same directory as this file
_CATKIN_SETUP_DIR=$(cd "`dirname "$0"`" > /dev/null && pwd)
. "$_CATKIN_SETUP_DIR/setup.sh"
exec "$@"
这个地方加下ip
配置启动launch
ros
有例子叫 example-ssh.launch
:
<!-- an example launch configuration that launches two demo nodes on a remote machine -->
<launch>
<group ns="local">
<node name="talker" pkg="rospy" type="talker.py" />
<node name="listener" pkg="rospy" type="listener.py" />
</group>
<!-- default only affects nodes defined later -->
<machine name="machine-1" default="true" address="foo.bar.com" env-loader="/opt/ros/fuerte/env.sh" user="whoami" ssh-port="22" />
<group ns="remote">
<node name="talker" pkg="rospy" type="talker.py" />
<node name="listener" pkg="rospy" type="listener.py" />
</group>
</launch>
local
部分意思是在本地开启的的节点,machine
部分就是ssh
的关键配置,下面的部分就是远端的节点
这个是我的启动脚本,我只启动了远端的talk节点,有三个配置方式:
<!-- an example launch configuration that launches two demo nodes on a remote machine -->
<launch>
<!-- default only affects nodes defined later -->
<!-- 这个是需要配置免密登录 -->
<machine name="machine-1" default="true" address="192.168.0.116" env-loader="/opt/ros/melodic/env.sh" user="utry" ssh-port="22" />
<!-- 这个是通过ssh跳转机直接开启的 -->
<!-- <machine name="machine-1" default="true" address="47.93.211.215" password="xxxx" env-loader="/opt/ros/melodic/env.sh" user="utry" ssh-port="2225" /> -->
<!-- 这个是通过账户密码,内网直接登录的 -->
<!-- <machine name="machine-1" default="true" address="192.168.0.116" password="xxxx" env-loader="/opt/ros/melodic/env.sh" user="utry" ssh-port="22" /> -->
<!-- 我就不加组了 -->
<!-- <group ns="remote"> -->
ssh免密登录
本地输入:
ssh-keygen -t rsa
一路确定
ssh-copy-id username@remoteip
验证效果
我分别启动,gif显示三个效果
记得远端的roscore先开,不然报没有mster的错
1.免密的方式
2.ssh 跳转方式
怎么跳转,参考我的这篇文章https://mengleil.blog.csdn.net/article/details/109576115
3.账号密码形式
这个其实就是不用配置免密了
总结
这个其实和主从模式还是有点差别的,但是有个小问题,虽然是通过ssh连接,但是启动的节点没法捕捉键盘信号,也就没办法在本地输入,只能启动节点啥的,抽空再研究研究。