【 rbx1翻译 第七章、控制移动基座】第三节、用ROS扭转

7.3 Twisting and Turning with ROS (用ROS扭转)

ROS使用“Twist”消息类型(请参见下面的详细信息)来发布要由基本控制器使用的运动命令。 虽然我们基本上可以为话题使用任何名称,但通常将其称为 /cmd_vel,它是“命令速度”的缩写。 基本控制器节点订阅 /cmd_vel话题,并将Twist消息转换为实际上使车轮转动的马达信号。
ROS uses the Twist message type (see details below) for publishing motion commands to be used by the base controller. While we could use almost any name for a topic, it is usually called /cmd_vel which is short for “command velocities”. The base controller node subscribes to the /cmd_vel topic and translates Twist messages into motor signals that actually turn the wheels.

要查看Twist消息的组件,请运行以下命令:
To see the components of a Twist message, run the command:

rosmsg show geometry_msgs/Twist

将输出以下信息:
which will produce the following output:
【 rbx1翻译 第七章、控制移动基座】第三节、用ROS扭转_第1张图片如您所见,Twist消息由两个类型为Vector3的子消息组成,一个用于x,y和z线速度分量,另一个用于x,y和z角速度分量。 线速度以米/秒为单位指定,角速度以弧度/秒为单位。 (1个弧度大约等于57度。)
As you can see, the Twist message is composed of two sub-messages with type Vector3 , one for the x, y and z linear velocity components and another for the x, y and z angular velocity components. Linear velocities are specified in meters per second and angular velocities are given in radians per second. (1 radian equals approximately 57 degrees.)

对于在二维平面(例如地板)中运行的差动驱动机器人,我们仅需要线性x分量和角度z分量。 这是因为这种类型的机器人只能沿其纵轴向前/向后移动,并且只能绕其垂直轴旋转。 换句话说,线性y和z分量始终为零(机器人无法侧向或垂直移动),而角度x和y分量始终为零,因为机器人无法围绕这些轴旋转。 全向机器人也将使用线性y分量,而飞行或水下机器人将使用所有六个分量。
For a differential drive robot operating in a two-dimensional plane (such as the floor), we only need the linear x component and the angular z component. This is because this type of robot can only move forward/backward along its longitudinal axis and rotate only around its vertical axis. In other words, the linear y and z components are always zero (the robot cannot move sideways or vertically) and the angular x and y components are always zero since the robot cannot rotate about these axes. An omni-directional robot would also use the linear y component while a flying or underwater robot would use all six components.

7.3.1 Example Twist Messages ( Twist消息示例 )

假设我们希望机器人以每秒0.1米的速度笔直向前移动。 这将需要Twist消息,其中线性值x = 0.1,y = 0和z = 0,角度值x = 0,y = 0和z = 0。 如果要在命令行上指定此Twist消息,则消息部分将采用以下形式:
Suppose we want the robot to move straight ahead with a speed of 0.1 meters per second. This would require a Twist message with linear values x=0.1, y=0 and z=0, and angular values x=0, y=0 and z=0. If you were to specify this Twist message on the command line, the message part would take the form:

'{linear: {x: 0.1, y: 0, z: 0}, angular: {x: 0, y: 0, z: 0}}'

请注意,我们如何使用花括号来描述子消息,并用冒号和空格(需要空格!)将组件名称与其值分开。尽管这看起来像是很多键入操作,但我们很少会以这种方式控制机器人。 稍后我们将看到,Twist消息将使用其他ROS节点发送到机器人。
Notice how we delineate the sub-messages using braces and separate the component names from their values with a colon and a space (the space is required!) While this might seem like a lot of typing, we will rarely control the robot this way. As we shall see later on, Twist messages will be sent to the robot using other ROS nodes.

要以每秒1.0弧度的角速度逆时针旋转,所需的“Twist”消息将为:
To rotate counterclockwise with an angular velocity of 1.0 radians per second, the required Twist message would be:

'{linear: {x: 0, y: 0, z: 0}, angular: {x: 0, y: 0, z: 1.0}}'

如果我们将这两个消息结合起来,则机器人会向前移动,同时向左转。 产生的Twist消息将是:
If we were to combine these two messages, the robot would move forward while turning toward the left. The resulting Twist message would be:

'{linear: {x: 0.1, y: 0, z: 0}, angular: {x: 0, y: 0, z: 1.0}}'

与线性x值相比,z角值越大,转弯就越紧。
The larger the angular z value compared to the linear x value, the tighter the turn.

这里有一个区分,感觉和万有引力天体运动那里相似:

说白了就是对于一个确切的圆路径,有个公式:V = W * R

  1. 当线速度一定时,角速度越大,圈越小,角速度越小,圈越大
  2. 当角速度一定时,线速度越大,圈越大,线速度越小,圈越小

7.3.2 Monitoring Robot Motion using RViz (使用RViz监视机器人运动)

在尝试各种Twist命令和运动控制脚本时,我们将使用RViz可视化机器人的运动。 回想一下《 RViz用户指南》,我们可以使用“Odometry Display”类型来跟踪机器人沿其路径的各个点的姿势(位置和方向)。 机器人的每个姿势均由指向该点机器人所面对的方向的大箭头指示。 请注意,这些姿势反映了机器人的里程表所报告的内容,有时可能与机器人在现实世界中的位置有所不同(有时存在很大差异)。 但是,如果对机器人进行了良好的校准并在相对坚硬的表面上运行,则里程表数据通常足够好,可以大致了解机器人的工作方式。 此外,在没有现实物理环境的ArbotiX模拟器中运行假机器人时,对应关系将是准确的。
We will use RViz to visualize the robot’s motion as we try out various Twist commands and motion control scripts. Recall from the RViz User’s Guide that we can use the Odometry Display type to track the pose (position and orientation) of the robot at various points along its path. Each pose of the robot is indicated by a large arrow pointing in the direction that the robot was facing at that point. Note that these poses reflect what is reported by the robot’s odometry which could differ—sometimes substantially—from how the robot is positioned in the real world. However, if the robot is well-calibrated and operating on a relatively hard surface, the odometry data is usually good enough to get a rough idea of how the robot is doing. Furthermore, when running a fake robot in the ArbotiX simulator where there is no physics, the correspondence will be exact.

让我们使用ArbotiX模拟器尝试几个示例。 首先,使用以下命令启动假的TurtleBot:
Let’s try a couple of examples using the ArbotiX simulator. First, fire up the fake TurtleBot using the command:

roslaunch rbx1_bringup fake_turtlebot.launch

在另一个终端中,使用已包含在里程表显示中的配置文件打开RViz:
In another terminal, bring up RViz with the included configuration file that is already set up with the Odometry display:

rosrun rviz rviz -d `rospack find rbx1_nav`/sim.rviz

最后,打开另一个终端窗口,并通过发布以下Twist消息来设置机器人沿顺时针方向移动:
Finally, bring up yet another terminal window and set the robot moving in a clockwise circle by publishing the following Twist message:

rostopic pub -r 10 /cmd_vel geometry_msgs/Twist '{linear: {x: 0.1, y: 0, z: 0}, angular: {x: 0, y: 0, z: -0.5}}'

我们使用-r参数以10Hz的频率连续发布Twist消息。 一些机器人(如TurtleBot)要求不断发布运动命令,否则机器人将停止:这是一个很好的安全功能。 尽管在运行ArbotiX模拟器时不需要此参数,但也不会造成任何影响。
We use the -r parameter to publish the Twist message continually at 10Hz. Some robots like the TurtleBot require the movement command to be continually published or the robot will stop: a nice safety feature. While this parameter is not necessary when running the ArbotiX simulator, it doesn’t hurt either.

如果一切正常,则RViz中的结果应如下所示:
If everything is working OK, the result in RViz should look something like this:
【 rbx1翻译 第七章、控制移动基座】第三节、用ROS扭转_第2张图片
请注意,我们已将里程表显示的“保留”字段设置为100,这表示我们想在最旧的箭头落下之前显示最新的100个箭头。 位置公差(以米为单位)和角度公差(以弧度为单位)使您可以控制新箭头的显示频率。
Note that we have set the Keep field to 100 for the Odometry Display which indicates that we want to display up to the last 100 arrows before the oldest one drops off. The Position Tolerance (in meters) and Angle Tolerance (in radians) allow you to control how often a new arrow will be displayed.

任何时候,如果想清除箭头,请单击“重置”按钮,或取消选中“里程表”显示旁边的复选框,然后再次选中。 要关闭所有箭头,请取消选中该复选框。
To clear the arrows at any point, either click the Reset button or un-check the checkbox beside the Odometry display, then check it again. To turn off the arrows altogether, leave the checkbox un-checked.

要阻止机器人旋转,请在同一终端窗口中输入Ctrl-C,然后发布空的Twist消息:
To stop the robot from rotating, type Ctrl-C in the same terminal window, then publish the empty Twist message:

rostopic pub -1 /cmd_vel geometry_msgs/Twist '{}'

现在让我们尝试第二个例子。 首先,通过单击RViz中的“重置”按钮清除里程计箭头。 以下命令对(用分号分隔)将首先使机器人直行约3秒钟【 publishing and latching message for 3.0 seconds(发布和锁定消息需要3.0秒)】(“ -1”选项表示“发布一次”),然后无限期地沿逆时针方向继续:
Now let’s try a second example. First clear the odometry arrows by clicking the Reset button in RViz . The following pair of commands (separated by a semi-colon) will first move the robot straight for about 3 seconds (the " -1 " option means “publish once”), then continue indefinitely in a counter-clockwise circle:

rostopic pub -1 /cmd_vel geometry_msgs/Twist '{linear: {x: 0.2, y: 0, z: 0}, angular: {x: 0, y: 0, z: 0}}'; rostopic pub -r 10 /cmd_vel geometry_msgs/Twist '{linear: {x: 0.2, y: 0, z: 0}, angular: {x: 0, y: 0, z: 0.5}}'

要停止机器人,请在同一终端窗口中输入Ctrl-C并发布空的Twist消息:
To stop the robot, type Ctrl-C in the same terminal window and publish the empty Twist message:

rostopic pub -1 /cmd_vel geometry_msgs/Twist '{}'

在实际的机器人上尝试一些Twist消息之前,我们必须花一些时间谈论校准。
Before we try out some Twist messages on a real robot, we have to spend a few moments talking about calibration.

你可能感兴趣的:(ROS机器人学习,rbx1书籍)