gazebo仿真与ros控制器学习

gazebo是一个功能强大的模拟器,尤其适合机器人的运动和控制模拟,但也存在很多bug

官方学习地址:http://gazebosim.org/tutorials

包括了所有的教程,从初级中级到高级,也可以按照分类进行学习

这里主要讲与ros控制器相关的知识。

相关地址:http://gazebosim.org/tutorials/?tut=ros_control

这张图我也是理解了一个大概:其中很多内容难免有些晦涩。

gazebo模拟器和真实机器人的主要区别就在硬件接口定义这里,因为我只是用到了gazebo模拟器,所以真实情况不会涉及,如有需要请自行搜索相关资料。

在urdf机器人模型中需要定义transmission和joint等,并添加gazebo_ros_control插件,详见

type里面:the type of transmission. Currently only "transmission_interface/SimpleTransmission

<hardwareInterface>硬件接口这里模拟器所以是EffortJointInterface,可以实现基于功率的位置速度控制器,此外还有JointStateInterface,VelocityJointInterface ,使用方法未知

官方的实例

 <transmission name="tran1">
    <type>transmission_interface/SimpleTransmission</type>
    <joint name="joint1">
      <hardwareInterface>EffortJointInterface</hardwareInterface>
    </joint>
    <actuator name="motor1">
      <hardwareInterface>EffortJointInterface</hardwareInterface>
      <mechanicalReduction>1</mechanicalReduction>
    </actuator>
  </transmission>

  <transmission name="tran2">
    <type>transmission_interface/SimpleTransmission</type>
    <joint name="joint2">
      <hardwareInterface>EffortJointInterface</hardwareInterface>
    </joint>
    <actuator name="motor2">
      <hardwareInterface>EffortJointInterface</hardwareInterface>
      <mechanicalReduction>1</mechanicalReduction>
    </actuator>
  </transmission>

此外还需要一个.yaml文件,用于加载控制器参数,比如pid以及速度加速度限制位置限制等

rrbot:
  # Publish all joint states -----------------------------------
  joint_state_controller:
    type: joint_state_controller/JointStateController
    publish_rate: 50  

  # Position Controllers ---------------------------------------
  joint1_position_controller:
    type: effort_controllers/JointPositionController
    joint: joint1
    pid: {p: 100.0, i: 0.01, d: 10.0}
  joint2_position_controller:
    type: effort_controllers/JointPositionController
    joint: joint2
    pid: {p: 100.0, i: 0.01, d: 10.0}

注意其中joint名字和type类型对应transmission

定义的是位置控制器

下面是launch文件

<launch>

  <!-- Load joint controller configurations from YAML file to parameter server -->
  <rosparam file="$(find rrbot_control)/config/rrbot_control.yaml" command="load"/>

  <!-- load the controllers -->
  <node name="controller_spawner" pkg="controller_manager" type="spawner" respawn="false"
    output="screen" ns="/rrbot" args="joint1_position_controller joint2_position_controller joint_state_controller"/>

  <!-- convert joint states to TF transforms for rviz, etc -->
  <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher"
    respawn="false" output="screen">
    <remap from="/joint_states" to="/rrbot/joint_states" />
  </node>

</launch>

这里的robot_state_publisher订阅了关节信息用于发布机器人状态

可以通过rosrun rqt_gui rqt_gui来查看所有topic是否正常发布。

通过指令可以控制ros_controller位置:

rostopic pub /pxdx/joint1_position_controller/command std_msgs/Float64 "data: 0.9"
rostopic pub /pxdx/joint2_position_controller/command std_msgs/Float64 "data: 0.9"

或者通过cmd_vel指令来控制运动

 rosrun teleop_twist_keyboard teleop_twist_keyboard.py /cmd_vel:=/pxdx/cmd_vel

发布joint_state topic的两种方式:

.方式一:.yaml文件中加载joint_state_controller,launch文件中添加joint_state_controller,但是只能发布带有transmission的joint

.方式二:通过gazebo插件可以发布所有添加的joint

<gazebo>
    <plugin filename="libgazebo_ros_control.so" name="ros_control">
    </plugin>
    <plugin name="joint_state_publisher" filename="libgazebo_ros_joint_state_publisher.so">
      <jointName>
          bh_j11_joint, bh_j12_joint, bh_j13_joint, bh_j21_joint, bh_j22_joint, bh_j23_joint,
          bh_j32_joint, bh_j33_joint, elbow_joint, shoulder_lift_joint, shoulder_pan_joint,
          wrist_1_joint, wrist_2_joint, wrist_3_joint
      </jointName>
      <updateRate>50</updateRate>
      <alwaysOn>true</alwaysOn>
    </plugin>
  </gazebo>

目前看两种并不冲突。

猜你喜欢

转载自blog.csdn.net/li4692625/article/details/112798542
今日推荐