ROS生成新的小乌龟(rosservice call /spawn)

命令

rosservice call /spawn "x: 3.0
y: 3.0
theta: 0.0
name: 'tt2'"

提示:执行后自动退出

解释:

  • x,y:设置新的小乌龟的位置。

    • x 为0,出现在左侧,值越大越靠近右侧
    • y 为0,出现在底部,值越大越靠近顶部
  • theta:设置小乌龟头的朝向。没找到解释

    • 0:向右
    • 1.5:向上
    • 3:向左
    • 4.7:向下
  • name:设置小乌龟名字,如果不指定,默认以 turtle+序号自动曾1 来生成,即:第一个海龟名字是 turtle1,第二个海龟名字是 turtle2。。。。
    注意:不要重名,否则报错。

例子

启动roscore

打开一个新终端,使用以下命令启动roscore:

roscore

打开小海龟仿真器

打开一个新终端(之前的终端不能关闭),使用以下命令打开小海龟仿真器

rosrun turtlesim turtlesim_node

提示:默认有一个小海龟,该海龟默认名字是 turtle1,其他功能可通过该名字对海龟进行控制

启动键盘控制小海龟移动

打开一个新终端(之前的终端不能关闭),使用以下命令启动键盘控制小海龟移动的节点:

rosrun turtlesim turtle_teleop_key

使用方向键控制小海龟移动

左下角生成乌龟

rosservice call /spawn "x: 1
y: 1
theta: 0.0
name: 'tt2'"

左上角生成乌龟

rosservice call /spawn "x: 1
y: 10
theta: 0.0
name: 'tt2'"

右上角生成乌龟

rosservice call /spawn "x: 10
y: 10
theta: 0.0
name: 'tt2'"

右下角生成乌龟

rosservice call /spawn "x: 10
y: 1
theta: 0.0
name: 'tt2'"

原文出处:/show_1GWm6EWPdZI.html