在gazebo中对机器人进行控制,并在rviz中同步显示

2023-05-16

在上一篇博客中,我一步一步地建立了在gazebo仿真中能用的xacro文件。但是仿真时的模型是自由摆动的,文末的时候我想对他进行控制,但是篇幅太长,所以新开一篇。
参考ros_control的内容:http://blog.csdn.net/wxflamy/article/details/79228736

先列出xacro文件:

<?xml version="1.0"?>
<robot name="myfirstrobot" xmlns:xacro="http://www.ros.org/wiki/xacro">

  <!-- Constants for robot dimensions -->
  <xacro:property name="PI" value="3.1415926535897931"/>
  <xacro:property name="mass" value="1" /> <!-- arbitrary value for mass -->
  <xacro:property name="width" value="0.1" /> <!-- Square dimensions (widthxwidth) of beams -->
  <xacro:property name="height1" value="4" /> <!-- Link 1 -->
  <xacro:property name="height2" value="2" /> <!-- Link 2 -->
  <xacro:property name="height3" value="1" /> <!-- Link 3 -->

  <!-- ros_control plugin -->
    <gazebo>
        <plugin name="gazebo_ros_control" filename="libgazebo_ros_control.so">
            <robotNamespace>/myfirstrobot</robotNamespace>
      <robotSimType>gazebo_ros_control/DefaultRobotHWSim</robotSimType>
        </plugin>
    </gazebo>

  <!-- Link1 -->
  <gazebo reference="base_link">
    <material>Gazebo/Orange</material>
  </gazebo>

  <!-- Link2 -->
  <gazebo reference="middle_link">
    <mu1>0.2</mu1>
    <mu2>0.2</mu2>
    <material>Gazebo/Blue</material>
  </gazebo>

  <!-- Link3 -->
  <gazebo reference="top_link">
    <mu1>0.2</mu1>
    <mu2>0.2</mu2>
    <material>Gazebo/Orange</material>
  </gazebo>

    <!-- Import Rviz colors -->
  <xacro:include filename="$(find myurdf)/robot/materials.xacro" />

  <!-- Used for fixing robot to Gazebo 'base_link' -->
  <link name="world"/>

  <joint name="fixed" type="fixed">
    <parent link="world"/>
    <child link="base_link"/>
  </joint>

    <!-- Base Link -->
    <link name="base_link">
        <visual>
            <geometry>
                <box size="${width} ${width} ${height1}"/>
            </geometry>
            <origin rpy="0 0 0" xyz="0 0 ${height1/2}"/>
            <material name="blue"/>
        </visual>
        <collision>
            <geometry>
                <cylinder length="${height1}" radius="${width+0.1}"/>
            </geometry>
            <origin rpy="0 0 0" xyz="0 0 ${height1/2}"/>
        </collision>
        <inertial>
      <origin xyz="0 0 ${height1/2}" rpy="0 0 0"/>
      <mass value="${mass}"/>
      <inertia
                ixx="${mass / 12.0 * (width*width + width*width)}" ixy="0.0" ixz="0.0"
            iyy="${mass / 12.0 * (height1*height1 + width*width)}" iyz="0.0"
            izz="${mass / 12.0 * (width*width + height1*height1)}"/>
        </inertial>
    </link>

    <joint name="joint1" type="continuous">
        <parent link="base_link"/>
        <child link="middle_link"/>
        <origin rpy="0 0 0" xyz="0 0 ${height1}"/>
        <axis xyz="0 1 0"/>
    </joint>

    <link name="middle_link">
        <visual>
            <geometry>
                <box size="${width} ${width} ${height2}"/>
            </geometry>
            <origin rpy="0 ${PI/2} 0" xyz="${height2/2} 0 0"/>
            <material name="white"/>
        </visual>
        <collision>
            <geometry>
                <cylinder length="${height2}" radius="${width+0.1}"/>
            </geometry>
            <origin rpy="0 ${PI/2} 0" xyz="${height2/2} 0 0"/>
        </collision>
        <inertial>
      <origin xyz="${height2/2} 0 0" rpy="0 0 0"/>
      <mass value="${mass}"/>
      <inertia
                ixx="${mass / 12.0 * (width*width + height2*height2)}" ixy="0.0" ixz="0.0"
            iyy="${mass / 12.0 * (height2*height2 + width*width)}" iyz="0.0"
            izz="${mass / 12.0 * (width*width + width*width)}"/>       
        </inertial>
    </link>

    <joint name="joint2" type="continuous">
        <parent link="middle_link"/>
        <child link="top_link"/>
        <origin rpy="0 0 0" xyz="${height2} 0 0"/>
        <axis xyz="0 1 0"/>
    </joint>

    <link name="top_link">
        <visual>
            <geometry>
                <box size="${width} ${width} ${height3}"/>
            </geometry>
            <origin rpy="0 ${PI/2} 0" xyz="${height3/2} 0 0"/>
            <material name="orange"/>
        </visual>
        <collision>
            <geometry>
                <cylinder length="${height3}" radius="${width+0.1}"/>
            </geometry>
            <origin rpy="0 ${PI/2} 0" xyz="${height3/2} 0 0"/>
        </collision>
        <inertial>
      <origin xyz="${height3/2} 0 0" rpy="0 0 0"/>
      <mass value="${mass}"/>
      <inertia
                ixx="${mass / 12.0 * (width*width + height3*height3)}" ixy="0.0" ixz="0.0"
            iyy="${mass / 12.0 * (height3*height3 + width*width)}" iyz="0.0"
            izz="${mass / 12.0 * (width*width + width*width)}"/>
        </inertial>
    </link>

    <joint name="end" type="revolute">
        <axis xyz="1 0 0"/>
        <limit effort="1000.0" lower="0.0" upper="0.548" velocity="0.5"/>
        <parent link="top_link"/>
        <child link="end_link"/>
        <origin rpy="0 0 0" xyz="${height3} 0 0"/>
    </joint>

    <link name="end_link">
        <visual>
            <geometry>
                <sphere radius="${width}"/>
            </geometry>
            <material name="white"/>
        </visual>
        <collision>
            <geometry>
                <sphere radius="${width+0.05}"/>
            </geometry>
        </collision>
        <inertial>
      <origin xyz="0 0 0" rpy="0 0 0"/>
      <mass value="${mass}"/>
      <inertia
                ixx="${mass / 12.0 * (width*width + width*width)}" ixy="0.0" ixz="0.0"
            iyy="${mass / 12.0 * (width*width + width*width)}" iyz="0.0"
            izz="${mass / 12.0 * (width*width + width*width)}"/>
        </inertial>
    </link>

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

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

  <transmission name="tran3">
    <type>transmission_interface/SimpleTransmission</type>
    <joint name="end">
      <hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface>
    </joint>
    <actuator name="motor3">
      <hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface>
      <mechanicalReduction>1</mechanicalReduction>
    </actuator>
  </transmission>
</robot>

上一节的启动文件里没有包含控制信息,现在我们配置一下控制器。新建一个config文件夹保存控制器参数。新建robot_control.yaml文件:

myfirstrobot:
  # 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: 20.0, i: 0.01, d: 10.0}
  joint2_position_controller:
    type: effort_controllers/JointPositionController
    joint: joint2
    pid: {p: 20.0, i: 0.01, d: 10.0}

为joint1和joint2配置了位置控制器。
然后在启动文件中增加控制器相关的启动文件,完整的启动文件为:

<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 myurdf)/robot/robot.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 myurdf)/robot/myfirstrobot.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 myfirstrobot -param robot_description"/>

  <node name="rviz" pkg="rviz" type="rviz" respawn="false" output="screen"
        args="-d $(find myurdf)/launch/xacro.rviz" />

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

  <!-- load the controllers -->
  <node name="controller_spawner" pkg="controller_manager" type="spawner" respawn="false"
    output="screen" ns="/myfirstrobot" args="joint_state_controller
                      joint1_position_controller
                      joint2_position_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="/myfirstrobot/joint_states" />
  </node>
</launch>

控制参数调的不是很好,打开的时候可能会出现一段时间的摆动,然后停止。需要调PID参数,这里我就不调了。

以下命令可以向关节发送控制位置命令

rostopic pub -1 /myfirstrobot/joint1_position_controller/command std_msgs/Float64 "data: 0"
rostopic pub -1 /myfirstrobot/joint2_position_controller/command std_msgs/Float64 "data: 1"

以下命令可以在终端打印出机器人的运行状态

rostopic echo myfirstrobot/joint_states

这里写图片描述

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在gazebo中对机器人进行控制,并在rviz中同步显示 的相关文章

随机推荐

  • PDU短信发送与接收格式分析

    一 PDU发送和接收格式分析 PDU是大多数手机短信通讯的核心 xff0c 仅有少数手机只支持Text模式 PDU模式比起Text模式可以提供能为强大的功能 xff0c 但其编码较Text模式困难 无论哪种模式 xff0c 我们都可以通过A
  • ucos OSTimeDly

    来源 xff1a http blog sina com cn s blog 5f9b3de40100e182 html OSTimeDly 在Task中 xff0c 一般执行一段时间之后调用OSTimeDly推迟一段时间再继续运行 xff0
  • WinCE中断结构分析

    以前写的原创博文 xff0c 这里放一份 前一段时间研究了一下WinCE下的中断结构 xff0c 整理了一下 xff0c 希望与大家讨论 最下面有PDF版本下载 xff0c 便于保存 Windows Embedded CE 中断结构分析 关
  • Google chrome 中文版下载

    Google release了自己的浏览器Chrome xff0c 大家可以试试看 xff0c 我觉得还不错 xff0c 对Web2 0的支持还好 xff0c 不知道安全性如何 我发现看tudou和youku等视频有问题 内存占用太大了 x
  • (下载)WinCE注册表编辑器(PC端)

    可以在PC上通过ActiveSync来查看 xff0c 修改device端的注册表 xff0c 方便调试 http download csdn net source 749005 注 xff1a 本人提供的下载均不要资源点
  • (下载)WinCE镜像传输工具ESHELL

    WinCE镜像传输工具ESHELL 使用这个可以不用装PB也可以传输镜像 xff0c 其实就是一个TFTP的传输 xff0c 适用于CE5 xff0c CE6 http download csdn net source 835336 不用资
  • I/O的控制方式——查询,中断,dma

    早期 xff0c I O串行 xff0c 查询方式 发展 xff0c I O并行 xff0c 两种方式其一是中断方式 xff0c 其二是dma方式 xff0c 使得外部设备能直接与主存储器信息交换 xff0c 减轻了cpu的工作量 技术继续
  • 关于WinCE下MC55使用Unimodem进行GPRS拨号,拨上出现断开连接,检查波特率的问题的另一种可能情况

    http www armce com bbs thread 59 1 1 html
  • WinCE上BINFS实现详解

    作者 wwfiney 64 ARMCE 网上不少介绍三星24x0系列的BIN FS启动方式实现 xff0c 有些内容上描述的不是非常全面 下面就WinCE6上的BINFS实现 xff0c 从基本原理 到修改BSP xff0c 再到如何烧录启
  • i.MX27支持8GBSDHC卡驱动修改

    最近需要给mx27加上SDHC驱动 以支持SDHC的SD卡 网上许多关于2440支持SDHC的文章 xff0c 借鉴很多 xff0c 但是由于MX27驱动的特殊结构 xff0c 需要做更多改动 xff0c 详细如下 xff1a 平台 xff
  • /etc/init.d/rcS文件详解

    我使用的简单rcS文件内容如下 最后的IP地址设定非常重要 xff0c 一定要跟服务器的地址再同一个网段 xff0c 不然会出现无法连接错误 nfs server 192 168 0 102 not responding still try
  • CAN通讯的byte序和bit序

    听别人说起CAN通讯协议的时候总说到Intel格式和motorola格式的时候 Intel格式如何 xff0c Motorola格式又如何 xff1f 觉得很有必要搞懂这些知识 xff0c 也看了相关资料 xff0c 可直到今天还没明白 真
  • ROS学习笔记(一):创建工作空间和功能包

    所有的ROS程序 xff0c 包括我们自己开发的程序 xff0c 都被组织成功能包 xff0c 而ROS的功能包被存放在称之为工作空间的目录下 因此 xff0c 在我们写程序之前 xff0c 第一步是创建一个工作空间以容纳我们的功能包 其实
  • PHP活动报名小程序系统源码 带后台管理程序

    活动报名小程序源码 xff0c 基于thinkphp开发的报名小程序源码 xff0c 带有后台管理 xff0c 用户发布活动信息 报名可以后台管理 xff0c 基本都还是可以的 不过需要注意的是 xff0c 用户注册部分是发送手机短信 xf
  • NVIDIA Jetson Xavier NX部署VINS-fusion-GPU

    组内大佬师兄今天抽出时间总结了一篇博客 xff0c 主要内容是 xff1a 把在阿木P450无人机上 xff0c 对自带的NVIDIA Jetson Xavier NX边缘计算机部署VINS fusion GPU教程 xff0c 并进行实验
  • 接口策略路由配置(通过流策略技术实现)

    策略路由 xff1a xff08 先于路由表 xff0c 且不会生成路由表 xff09 策略路由和路由策略都可以影响数据包的转发过程 xff0c 但他们对数据包的影响方式是不同的 本地策略路由 xff1a 仅对本机 下发的报文进行处理 xf
  • Mac Xcode崩溃 (打开ios项目引起崩溃)

    bug xff1a 每次打开此工程都会导致Xcode崩溃 其他工程没有问题 解决办法 xff1a 1 确定本地跟服务器没有需要更新和提交的代码 2 把本地工程移到废纸篓 3 从新check out工程 4 新工程完美运行 xff08 这样没
  • Mac上VScode使用clang-format格式化c++代码

    一 安装 需要安装插件c c 43 43 xff0c 不推荐使用clang format这个插件 xff0c 毕竟c c 43 43 里面已经支持了clang format格式化操作 安装这个clang format插件也有一个好处 xff
  • C#解决串口通信中接收数据时延迟处理与缓存处理的方法

    C 解决串口通信中接收数据时延迟处理与缓存处理的方法 时间 2011 1 21 14 04 29 来源 www cnblogs com 作者 杨少宁 利用串口进行通信 xff0c 当发送方 xff08 A xff09 将数据写入串口后 xf
  • 在gazebo中对机器人进行控制,并在rviz中同步显示

    在上一篇博客中 xff0c 我一步一步地建立了在gazebo仿真中能用的xacro文件 但是仿真时的模型是自由摆动的 xff0c 文末的时候我想对他进行控制 xff0c 但是篇幅太长 xff0c 所以新开一篇 参考ros control的内