gazebo机器人pid动态调节

使用gazebo进行仿真的方法

写此篇为了记录犯下的错误以及更正的办法,前路漫漫偶尔也要回头看看。

准备工作

首先要有一个urdf模型描述文件。生成的办法可以是手动添加也可以使用solidworks插件直接导出。针对导出的urdf文件进行简要的修改,包括邮件地址和作者信息。(可以不做)

  1. 使用$ roslaunch moveit_setup_assistant setup_assistant.launch打开moveit配置助手,按照步骤提示添加碰撞矩阵、虚拟关节(可选,如果要将模型固定在空中的某个位置要添加一个固定类型的关节child_link选择base_link,parent frame 选择world(自己命名,需要在urdf中添加这个link:<link name="world" /> <joint name="fixed" type="fixed" > <parent link="world" /> <child link="base_link"/> </joint>))、规划组、初始pose,等等。生成urdf并将绿色的部分更新到urdf文件。我的做法是将urdf备份并重命名为.xacro文件,方便后边更改然后把更新的部分在两边都添加(默认生成的文件有使用urdf的)
    以下为部分自动生成的部分(省略6个关节):
    <transmission name="trans_joint1"> <type>transmission_interface/SimpleTransmission</type> <joint name="joint1"> <hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface> </joint> <actuator name="joint1_motor"> <hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface> <mechanicalReduction>1</mechanicalReduction> </actuator> </transmission> <gazebo> <plugin name="gazebo_ros_control" filename="libgazebo_ros_control.so"> <robotNamespace>/</robotNamespace> </plugin> </gazebo>
  2. 关键点在于要使用的<hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface>我尝试使用了PositionJointInterface但是会有无法加载控制器pid的错误出现,使用这个接口问题就解决了。
  3. 建立控制器配置文件:controller.yaml,叫啥无所谓,只要包含时名字写对就行。文件内容如下:
/arm:
 # 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:指名的关节名字要和urdf/xacro文件中的关节名字一致。使用pid参数可以先随意指定后边可以动态调节。

type: effort_controllers/JointPositionController

指定的effort_controllers是输出类型是effort,输入类型为jointposition。输出类型要和urdf<hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface>中一样。目前测试这样的组合不报错。

  1. 建立控制器启动文件:controller.launch:其实就是包含一下刚才的yaml文件,使用controller_spawner把控制器启动参数就是yaml文件中的名字列表,启动robot_state_publisher完成坐标的广播。这里arm是我的模型名字。
<launch>

  <!-- Load joint controller configurations from YAML file to parameter server -->
  <rosparam file="$(find arm_control)/config/arm_control.yaml" command="load"/>
 
 <!--加载gazebo的控制器-->
<!--<rosparam file="$(find arm_moveit_config)/config/controllers_gazebo.yaml" command="load"/>-->

  <!-- load the controllers -->
  <node name="controller_spawner" pkg="controller_manager" type="spawner" respawn="false"
    output="screen" ns="/arm" args="joint1_position_controller joint2_position_controller joint3_position_controller joint4_position_controller joint5_position_controller joint6_position_controller joint7_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" ns="/arm" >
    <remap from="/joint_states" to="/arm/joint_states" />
  </node>



  
</launch>
  1. 编写gazebo启动文件:
    启动一个空世界,加载模型到参数服务器,然后生成模型。注意检查包含的launch文件不要重复生成模型、控制器。
    urdf_spawner的参数可以指定模型生成的初始位置,如果模型和地面相交会出现鬼畜一样的抖动,此时请将 -z设置一个大于0的数值注意单位是m。
<launch>

  <!-- these are the arguments you can pass this launch file, for example paused:=true -->
  <arg name="paused" default="false"/>
  <arg name="use_sim_time" default="true"/>
  <arg name="gui" default="true"/>
  <arg name="headless" default="false"/>
  <arg name="debug" default="false"/>

  <!-- We resume the logic in empty_world.launch, changing only the name of the world to be launched -->
  <include file="$(find gazebo_ros)/launch/empty_world.launch">
    <!-- <arg name="world_name" value="$(find arm_gazebo)/worlds/rrbot.world"/> -->
    <arg name="debug" value="$(arg debug)" />
    <arg name="gui" value="$(arg gui)" />
    <arg name="paused" value="$(arg paused)"/>
    <arg name="use_sim_time" value="$(arg use_sim_time)"/>
    <arg name="headless" value="$(arg headless)"/>
  </include>

  <!-- Load the URDF into the ROS Parameter Server -->
  <param name="robot_description"
    command="$(find xacro)/xacro --inorder '$(find arm_description)/urdf/arm_description.xacro'" />

  <!-- Run a python script to the send a service call to gazebo_ros to spawn a URDF robot -->
  <node name="urdf_spawner" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen"
    args="-urdf -model arm -param robot_description -x 0 -y 0 -z 0.5"/>

   <!--ros_control arm launch file -->
  <!--<include file="$(find arm_control)/launch/arm_control.launch" />-->
<!--重复包含了arm_control.launch-->
</launch>
  1. 先启动gazebo,然后启动控制器。如果没有报错可以进入下一步pid动态调节。控制器偶尔会有启动失败可以尝试重新启动,没有指定pid_gain之类的错误请检查前边的配置。
  2. 使用rqt_gui后续步骤就和gazebo官网上的指导一样了。指定发布关节指令:/jointx_command然后打开动态调参插件,有pid选项可以使用就算是小小的成功。
  • 3
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值