7.10 Teleoperating your Robot (遥控你的机器人)
对机器人保持某种手动控制总是一个好主意,尤其是在测试新代码时。 我们已经看到,机器人的基本控制器订阅了/ cmd_vel话题,并将在那里发布的所有Twist消息映射为电机信号。 如果我们可以使用诸如操纵杆或游戏控制器之类的远程控制设备在/ cmd_vel主题上发布Twist消息,则可以使用它来遥控机器人。 (这是ROS如何使我们能够从底层硬件中抽象出来的另一个很好的例子。)
It is always a good idea to maintain some kind of manual control over your robot, especially when testing new code. We have seen that the base controller for a robot subscribes to the /cmd_vel topic and maps any Twist messages published there into motor signals. If we can coax a remote control device such as a joystick or game controller to publish Twist messages on the /cmd_vel topic, we can use it to teleoperate the robot. (This is another good example of how ROS enables us to abstract away from the underlying hardware.)
幸运的是,turtlebot_teleop软件包已经包含用于通过键盘,操纵杆或PS3控制器发送Twist命令的节点。 要获取所需的ROS软件包,请运行以下命令:
Fortunately, the turtlebot_teleop package already includes nodes for sending Twist commands via the keyboard, a joystick or a PS3 controller. To get the required ROS packages, run the command:
sudo apt-get install ros-indigo-joystick-drivers \
ros-indigo-turtlebot-teleop
注意:如果是melodic版本的,安装这个会出错:
使用以下命令完成安装:
sudo apt-get install ros-melodic-joystick-drivers \
ros-melodic-turtlebot3-*
在遥控真正的机器人之前,请使用ArbotiX模拟器进行尝试。 如果假TurtleBot尚未运行,请启动它:
Before teleoperating a real robot, try it out using the ArbotiX simulator. Bring up the fake TurtleBot if it is not already running:
roslaunch rbx1_bringup fake_turtlebot.launch
而且它RViz仍未运行,请立即启动它:
And it RViz is not still running, fire it up now:
rosrun rviz rviz -d `rospack find rbx1_nav`/sim.rviz
现在,让我们看一下使用键盘或操纵杆对模拟机器人进行遥控操作。
Now let’s take a look at teleoperating the simulated robot using either the keyboard or a joystick.
7.10.1 Using the Keyboard (使用键盘)
turtlebot_teleop软件包包括一个keyboard_teleop.launch文件,该文件已复制到rbx1_nav / launch目录,以便我们可以编辑下面描述的几个参数。 使用以下命令来运行启动文件的此副本:
The turtlebot_teleop package includes a keyboard_teleop.launch file that has been copied to the rbx1_nav/launch directory so that we can edit a couple of parameters described below. Use the following command to run this copy of the launch file:
roslaunch rbx1_nav keyboard_teleop.launch
注意:这里如果使用的是melodic版本的需要修改这个launch 文件,修改为这个turtlebot3就行(修改之前请备份,备份是一个好习惯):
roscd rbx1_nav
cd launch
gedit keyboard_teleop.launch
然后,您应该在终端屏幕上看到以下说明:
You should then see the following instructions on your terminal screen:
实际是这个样子:
将光标悬停在Teleop终端窗口上,尝试点按字母i(上图中使用WASDX键移动机器人)。 您应该看到假的TurtleBot在RViz中向前行进。 请注意,如果停止轻击,机器人将减速并停止。 尝试其他一些键以确保一切正常。
With your cursor over the teleop terminal window, try tapping the letter i . You should see the fake TurtleBot move forward in RViz . Notice that if you stop tapping, the robot will slow down and stop. Try some of the other keys to make sure everything is working.
如果查看rbx1_nav / launch目录中的keyboard_teleop.launch文件,则会看到键盘操作节点采用两个参数:scale_linear和scale_angular,用于确定机器人的默认线性速度和角速度。 首次在真实机器人上测试遥控操作时,最好将这些值设置为小于默认值,以便机器人缓慢移动。 不幸的是,在编写代码时,turtlebot_teleop软件包中存在一个错误,该错误会阻止keyboard_teleop节点读取两个参数,因此暂时将忽略这些参数。
If you look at the keyboard_teleop.launch file in the rbx1_nav/launch directory, you will see that the keyboard teleop node takes two parameters: scale_linear and scale_angular for determining the default linear and angular speed of the robot. When first testing teleoperating on a real robot, it is a good idea to set these values smaller than the defaults so that the robot will move slowly. Unfortunately, at the time of this writing, there is a bug in the turtlebot_teleop package that prevents the two parameters from being read by the keyboard_teleop node, so for the time being, these parameters will be ignored.
7.10.2 Using a Logitech Game Pad (使用Logitech游戏手柄)
如果您有操纵杆或游戏手柄,则可以使用turtlebot_teleop软件包中的joystick_teleop.launch文件。 我们在rbx1_nav / launch目录中创建了此文件的本地副本,以便可以编辑各种参数以满足您的需要。 以下描述专门适用于Logitech无线游戏手柄。
If you have a joystick or game pad you can use the joystick_teleop.launch file in the turtlebot_teleop package. We have made a local copy of this file in the rbx1_nav/launch directory so that various parameters can be edited to suit your needs. The following description applies specifically to a Logitech wireless game pad.
要使用操纵杆伸缩节点,请运行以下命令:
To use the joystick teleop node, run the following command:
roslaunch rbx1_nav joystick_teleop.launch
如果出现以下错误:
If you get an error such as:
则说明您的游戏杆或游戏手柄未插入USB端口,或者未被Ubuntu识别。 如果您没有收到任何错误,请按“dead man”按钮(请参阅下面的注释),然后尝试移动操纵杆或游戏手柄上的左拨杆。。
then your joystick or game pad is either not plugged in to a USB port or it is not recognized by Ubuntu. If you do not receive any errors, press the “dead man” button (see Note below) and try moving the joystick or the left-hand toggle stick on the game pad.
注意:如果您使用的是Logitech游戏手柄,则必须首先按住右食指按钮,然后机器人才能响应左拨动杆。 该按钮称为“dead man”开关,因为如果松开它,机器人将停止移动。
NOTE: If you are using a Logitech game pad, you must first press and hold the right index finger button before the robot will respond to the left toggle stick. This button is called the “dead man” switch since the robot will stop moving if you release it.
您可以编辑joystick_teleop.launch文件来更改线性和角速度的比例系数。 您也可以将dead man开关切换到其他按钮。 要找出与每个按钮相对应的数字,请尝试jstest程序:
You can edit the joystick_teleop.launch file to change the scale factors for linear and angular speed. You can also map the dead man switch to a different button. To find out the numbers corresponding to each button, try the jstest program:
sudo apt-get install joystick
jstest /dev/input/js0
然后按各种按钮,然后查看屏幕底部的数字,看哪一个从“关闭”变为“打开”。 键入Ctrl-C退出测试屏幕。
Then press various buttons and look at the numbers at the bottom of the screen to see which one turns from “off” to “on”. Type Ctrl-C to exit the test screen.
7.10.3 Using the ArbotiX Controller GUI (使用ArbotiX Controller GUI)
这部分无法复制,只能截图,而且单词不完整,只能这样子了先:
注:
arbotix_gui
命令我这里报错。新手,不会解决。
只翻译下面这段比较完整的:
为了移动你的机器人(真实的或者模拟的),使用鼠标点击并按住红点,然后按您希望机器人移动的方向来移动红点。 注意不要将其移得太远,因为机器人的速度受距原点的距离控制。 如果您使用的是Pi Robot模拟器,则还将看到手臂关节的控件,如下所示:
要移动在模拟器中的某一个关节,请选中名称旁边的框,然后使用滑块。
To move one of the joints in the simulator, check the box beside the servo name, then use the slider.
7.10.4 TurtleBot Teleoperation Using Interactive Markers (使用交互式的Markers来进行TurtleBot的远程操作)
Turtlebot meta-package包括一个非常酷的交互式标记程序包,它允许您通过拖动RViz中的控件来移动实际的机器人。 turtlebot_interactive_markers教程Wiki页面上提供了有关如何使用它的说明,尽管自Groovy之后该页面尚未更新。 (一旦出现,请单击页面顶部的Groovy选项卡。)
The Turtlebot meta-package includes a very cool interactive markers package that allows you to move the real robot by dragging controls in RViz . Instructions on how to use it are provided on the turtlebot_interactive_markers tutorials Wiki page, although the page has not been updated since Groovy. (Click on the Groovy tab at the top of the page once it comes up.)
要为ROS Indigo安装软件包,请运行以下命令:
To install the package for ROS Indigo, run the command:
sudo apt-get install ros-indigo-turtlebot-interactive-markers
要使用假的TurtleBot进行尝试,请运行以下命令:
To try it out with the fake TurtleBot, run the following commands:
roslaunch rbx1_bringup fake_turtlebot.launch
使用预先配置的Interactive_markers.rviz配置文件打开RViz:
Bring up RViz with the pre-configured interactive_markers.rviz config file:
rosrun rviz rviz -d `rospack find rbx1_nav`/interactive_markers.rviz
最后,在rbx1_nav包中调用Interactive_markers.launch文件:
Finally, bring up the interactive_markers.launch file in the rbx1_nav package:
roslaunch rbx1_nav interactive_markers.launch
这里启动的时候可能会报turtlebot_bringup找不到的错误以及
ERROR: cannot launch node of type [turtlebot_interactive_markers/turtlebot_marker_server]: turtlebot_interactive_markers
这个错误,这时候直接从github上下载turtlebot的代码就可以了:
cd ~/catkin_ws/src
git clone https://github.com/turtlebot/turtlebot.git
git clone https://github.com/turtlebot/turtlebot_interactions.git
cd ..
catkin_make
编译成功后就可以正常运行
此启动文件是从turtlebot_interactive_markers包复制而来的,并进行了稍微修改以与假TurtleBot一起使用。
This launch file was copied from the turtlebot_interactive_markers package and modified slightly to work with the fake TurtleBot.
返回RViz,单击顶部工具栏上的“交互”按钮。 RViz屏幕应如下所示:
Back in RViz , click on the Interact button along the top tool bar. The RViz screen should look like this:
单击红色箭头以向前或向后移动假机器人,并旋转蓝色环以旋转机器人。
Click on the red arrows to move the fake robot forward or back and rotate the blue annulus to turn the robot.