在凉亭模拟的世界中订阅sdf模型的子链接

时间:2018-06-22 17:24:03

标签: python publish-subscribe ros

我有在Gazebo中模拟的Baxter机器人(Baxter SDK urdf)和操纵杆模型(简单的sdk文件)。需要记录的是在凉亭中显示的操纵杆的俯仰和横滚的位置。

(我无法在Gazebo中记录世界日志,因为Baxter SDK使用Gazebo版本2,并且该功能在该处无法正常工作。)

操纵杆的sdf如下:

<?xml version="1.0" ?>
<sdf version='1.4'>
  <model name='joystick'>
    <link name='joystick_base'>
      <pose>0 0 0 0 -0 0</pose>
      <inertial>
        <pose>0 0 0.75 0 -0 0</pose>
        <mass>0.01</mass>
        <inertia>
          <ixx>0.0001</ixx>
          <ixy>0</ixy>
          <ixz>0</ixz>
          <iyy>0.0001</iyy>
          <iyz>0</iyz>
          <izz>0.0001</izz>
        </inertia>
      </inertial>
      <collision name='joystick_base_collision'>
        <pose>0 -0 0.77 0 -0 0</pose>
        <geometry>
          <box>
            <size>0.07 0.07 0.04</size>
          </box>
        </geometry>
      </collision>
      <visual name='joystick_base_visual'>
        <pose>0 -0 0.775 0 -0 0</pose>
        <geometry>
          <box>
            <size>0.07 0.07 0.05</size>
          </box>
        </geometry>
      </visual>
      <velocity_decay>
        <linear>0</linear>
        <angular>0</angular>
      </velocity_decay>
    </link>
    <link name='link_roll'>
      <pose>0 0 0.05 0 -0 0</pose>
      <inertial>
        <pose>0 -0 0.75 0 -0 0</pose>
        <mass>0.01</mass>
        <inertia>
          <ixx>0.0002</ixx>
          <ixy>0</ixy>
          <ixz>0</ixz>
          <iyy>0.0002</iyy>
          <iyz>0</iyz>
          <izz>0.0002</izz>
        </inertia>
      </inertial>
      <velocity_decay>
        <linear>0</linear>
        <angular>0</angular>
      </velocity_decay>
    </link>
    <joint name='joint_roll' type='revolute'>
      <child>link_roll</child>
      <parent>joystick_base</parent>
      <axis>
        <xyz>0 1 0</xyz>
        <limit>
          <lower>-1.2</lower>
          <upper>1.2</upper>
          <effort>15</effort>
          <velocity>4</velocity>
        </limit>
        <dynamics>
          <damping>0.7</damping>
        </dynamics>
      </axis>
    </joint>
    <link name='joystick'>
      <pose>0 0 0.05 0 -0 0</pose>
      <inertial>
        <pose>0 -0 0.75 0 -0 0</pose>
        <mass>0.01</mass>
        <inertia>
          <ixx>0.0002</ixx>
          <ixy>0</ixy>
          <ixz>0</ixz>
          <iyy>0.0002</iyy>
          <iyz>0</iyz>
          <izz>0.0002</izz>
        </inertia>
      </inertial>
      <collision name='joystick_collision'>
        <pose>0 -0 0.835 0 -0 0</pose>
        <geometry>
          <cylinder>
            <length>0.17</length>
            <radius>0.01</radius>
          </cylinder>
        </geometry>
      </collision>
      <visual name='joystick_visual'>
        <pose>0 -0 0.835 0 -0 0</pose>
        <geometry>
          <cylinder>
            <length>0.17</length>
            <radius>0.01</radius>
          </cylinder>
        </geometry>
      </visual>
      <velocity_decay>
        <linear>0</linear>
        <angular>0</angular>
      </velocity_decay>
    </link>
    <joint name='joint_pitch' type='revolute'>
      <child>joystick</child>
      <parent>link_roll</parent>
      <axis>
        <xyz>1 0 0</xyz>
        <limit>
          <lower>-1.2</lower>
          <upper>1.2</upper>
          <effort>15</effort>
          <velocity>4</velocity>
        </limit>
        <dynamics>
          <damping>0.7</damping>
        </dynamics>
      </axis>
    </joint>
  </model>
</sdf>

我想订阅'joint_pitch''joint_roll'来接收它们的值,例如像这样:

from geometry_msgs.msg import Pose, PoseStamped
model_coordinates = rospy.ServiceProxy('/gazebo/get_model_state', GetModelState)
resp_coordinates = model_coordinates('joystick', 'joint_roll')
print(str(resp_coordinates.axis.position.x))

任何想法如何使它真正起作用?

1 个答案:

答案 0 :(得分:0)

如果您想知道当前的关节属性(位置和速率),只需请求凉亭服务/gazebo/get_joint_properties。 您只需要按照here的说明编写python服务客户端,或者也可以先尝试通过rqt_service_caller获取信息。