学习ROS Control

点此下载源码
参考网页:Tutorial: ROS Control
通过使用控制器驱动机器人的关节,为MoveIt!等规划器提供一个准确的ROS接口。将使用ros_control包。

ros_control 与 Gazebo的数据流图

在Gazebo中进行控制器的仿真,可以利用ros_control和简单的Gazebo插件来实现。各相关组件的关系参考下图

前期准备

参考Using URDF in Gazebo建立一个RRBot机器人模型。
主要教程目录参考如下
学习ROS Control_第1张图片
学习ROS Control_第2张图片

使用

向URDF文件添加传动机构

将驱动器与关节相连接。

<robot>
  ...
  <transmission name="tran1">
    <type>transmission_interface/SimpleTransmissiontype>
    <joint name="joint1">
      <hardwareInterface>hardware_interface/EffortJointInterfacehardwareInterface>
    joint>
    <actuator name="motor1">
      <hardwareInterface>hardware_interface/EffortJointInterfacehardwareInterface>
      <mechanicalReduction>1mechanicalReduction>
    actuator>
  transmission>

  <transmission name="tran2">
    <type>transmission_interface/SimpleTransmissiontype>
    <joint name="joint2">
      <hardwareInterface>hardware_interface/EffortJointInterfacehardwareInterface>
    joint>
    <actuator name="motor2">
      <hardwareInterface>hardware_interface/EffortJointInterfacehardwareInterface>
      <mechanicalReduction>1mechanicalReduction>
    actuator>
  transmission>

robot>

添加gazebo_ros_control插件

<robot>

  
  <gazebo>
    <plugin name="gazebo_ros_control" filename="libgazebo_ros_control.so">
      <robotNamespace>/rrbotrobotNamespace>
      <robotSimType>gazebo_ros_control/DefaultRobotHWSimrobotSimType>
    plugin>
  gazebo>

robot>

创建.yaml配置文件

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}

创建启动文件

<launch>

  
  <rosparam file="$(find rrbot_control)/config/rrbot_control.yaml" command="load"/>

  
  <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"/>

  
  <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>

使用启动文件开启控制器

开始RRBot机器人仿真

roslaunch rrbot_gazebo rrbot_world.launch

加载两关节控制器

roslaunch rrbot_control rrbot_control.launch

使用service手动调用控制器

rosservice call /rrbot/controller_manager/load_controller "name: 'joint1_position_controller'"
rosservice call /rrbot/controller_manager/load_controller "name: 'joint2_position_controller'"

启动控制器

rosservice call /rrbot/controller_manager/switch_controller "{start_controllers: ['joint1_position_controller','joint2_position_controller'], stop_controllers: [], strictness: 2}"

停止控制器

rosservice call /rrbot/controller_manager/switch_controller "{start_controllers: [], stop_controllers: ['joint1_position_controller','joint2_position_controller'], strictness: 2}"

手动发送命令

rostopic pub -1 /rrbot/joint1_position_controller/command std_msgs/Float64 "data: 1.5"
rostopic pub -1 /rrbot/joint2_position_controller/command std_msgs/Float64 "data: 1.0"

使用rqt工具

rosrun rqt_gui rqt_gui

已经配置好的一个RQT

roslaunch rrbot_control rrbot_rqt.launch

与RVIZ建立连接

rosrun rviz rviz

添加“RobotModel”


这里写图片描述

你可能感兴趣的:(ROS)