• Gazebo 控制实例


    运动控制实现流程

    roslaunch urdf02_gazebo demo03_env.launch

    启动gazebo仿真环境 demo03_env.launch

    launch文件

    <launch>
        
        <param name = "robot_description" command = "$(find xacro)/xacro $(find urdf02_gazebo)/urdf/car.urdf.xacro" />
        
        <include file = "$(find gazebo_ros)/launch/empty_world.launch">
            <arg name = "world_name" value = "$(find urdf02_gazebo)/worlds/box_house.world" />
        include>
        
        
        <node pkg = "gazebo_ros" type = "spawn_model" name = "spawn_model" args = "-urdf -model mycar -param robot_description"/>
    launch>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    添加传动装置及控制器 move.xacro

    <robot name="my_car_move" xmlns:xacro="http://wiki.ros.org/xacro">
    
        
        <xacro:macro name="joint_trans" params="joint_name">
            
            <transmission name="${joint_name}_trans">
                <type>transmission_interface/SimpleTransmissiontype>
                <joint name="${joint_name}">
                    <hardwareInterface>hardware_interface/VelocityJointInterfacehardwareInterface>
                joint>
                <actuator name="${joint_name}_motor">
                    <hardwareInterface>hardware_interface/VelocityJointInterfacehardwareInterface>
                    <mechanicalReduction>1mechanicalReduction>
                actuator>
            transmission>
        xacro:macro>
    
        
        <xacro:joint_trans joint_name="left2link" />
        <xacro:joint_trans joint_name="right2link" />
    
        
        <gazebo>
            <plugin name="differential_drive_controller" filename="libgazebo_ros_diff_drive.so">
                <rosDebugLevel>DebugrosDebugLevel>
                <publishWheelTF>truepublishWheelTF>
                <robotNamespace>/robotNamespace>
                <publishTf>1publishTf>
                <publishWheelJointState>truepublishWheelJointState>
                <alwaysOn>truealwaysOn>
                <updateRate>100.0updateRate>
                <legacyMode>truelegacyMode>
                <leftJoint>left2inkleftJoint> 
                <rightJoint>right2linkrightJoint> 
                <wheelSeparation>${base_radius * 2}wheelSeparation> 
                <wheelDiameter>${wheel_radius * 2}wheelDiameter> 
                <broadcastTF>1broadcastTF>
                <wheelTorque>30wheelTorque>
                <wheelAcceleration>1.8wheelAcceleration>
                <commandTopic>cmd_velcommandTopic> 
                <odometryFrame>odomodometryFrame> 
                <odometryTopic>odomodometryTopic> 
                <robotBaseFrame>base_footprintrobotBaseFrame> 
            plugin>
        gazebo>
    robot>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46

    添加xacro集成文件 car.urdf.xacro

    <robot name="mycar" xmlns:xacro="http://wiki.ros.org/xacro">
        
        <xacro:include filename = "head.xacro" />
        
        <xacro:include filename = "demo02_car_base.urdf.xacro" />
        <xacro:include filename = "demo03_car_camera.urdf.xacro" />
        <xacro:include filename = "demo04_car_laser.urdf.xacro" />
        
        <xacro:include filename = "gazebo/move.xacro" />
    robot>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    Rviz 查看里程计消息

    里程计: 机器人相对出发点坐标系的位姿状态(X 坐标 Y 坐标 Z坐标以及朝向)

    启动Rviz demo04_sensor.launch

    <launch>
        
        <node pkg = "rviz" type = "rviz" name = "rviz" args = "-d $(find urdf01_rviz)/config/show_mycar.rviz"/>
    
        
        <node pkg = "joint_state_publisher" type = "joint_state_publisher" name = "joint_state_publisher" />
    
        
        <node pkg = "robot_state_publisher" type = "robot_state_publisher" name = "robot_state_publisher" />
    
    launch>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    source ./devel/setup.bash
    roslaunch urdf02_gazebo demo03_env.launch
    roslaunch urdf02_gazebo demo04_sensor.launch

    添加组件

    雷达 laser.xacro

    <robot name="my_sensors" xmlns:xacro="http://wiki.ros.org/xacro">
    
      
      <gazebo reference="laser">
        <sensor type="ray" name="rplidar">
          <pose>0 0 0 0 0 0pose>
          <visualize>truevisualize>
          <update_rate>5.5update_rate>
          <ray>
            <scan>
              <horizontal>
                <samples>360samples> 
                <resolution>1resolution>>
                <min_angle>-3min_angle>
                <max_angle>3max_angle>
              horizontal>
            scan>
            <range>
              <min>0.10min>
              <max>30.0max>
              <resolution>0.01resolution>
            range>
            <noise>
              <type>gaussiantype>
              <mean>0.0mean>
              <stddev>0.01stddev>
            noise>
          ray>
          <plugin name="gazebo_rplidar" filename="libgazebo_ros_laser.so">
            <topicName>/scantopicName>
            <frameName>laserframeName>
          plugin>
        sensor>
      gazebo>
    robot>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35

    摄像头 camera.xacro

    <robot name="my_sensors" xmlns:xacro="http://wiki.ros.org/xacro">
      
      <gazebo reference="camera">
        
        <sensor type="camera" name="camera_node">
          <update_rate>30.0update_rate> 
          
          <camera name="head">
            <horizontal_fov>1.3962634horizontal_fov>
            <image>
              <width>1280width>
              <height>720height>
              <format>R8G8B8format>
            image>
            <clip>
              <near>0.02near>
              <far>300far>
            clip>
            <noise>
              <type>gaussiantype>
              <mean>0.0mean>
              <stddev>0.007stddev>
            noise>
          camera>
          
          <plugin name="gazebo_camera" filename="libgazebo_ros_camera.so">
            <alwaysOn>truealwaysOn>
            <updateRate>0.0updateRate>
            <cameraName>/cameracameraName>
            <imageTopicName>image_rawimageTopicName>
            <cameraInfoTopicName>camera_infocameraInfoTopicName>
            <frameName>cameraframeName>
            <hackBaseline>0.07hackBaseline>
            <distortionK1>0.0distortionK1>
            <distortionK2>0.0distortionK2>
            <distortionK3>0.0distortionK3>
            <distortionT1>0.0distortionT1>
            <distortionT2>0.0distortionT2>
          plugin>
        sensor>
      gazebo>
    robot>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    rostopic pub -r 10 /cmd_vel 设置参数让机器人转动
    
    • 1
  • 相关阅读:
    【C++】智能指针
    Linux 之前的 Unix 桌面沉浮启示录
    C# 设计模式 行为型模式 之 解释器模式
    1w5字详细介绍分布式系统的那些技术方案
    基于协同过滤算法的电影推荐系统
    区块链技术助力数字碳中和的路径研究
    深化服务成工业品电商角逐新焦点
    【数据结构】C++二叉树的实现(二叉链表),包括初始化,前序、中序、后序、层次遍历,计算节点数、叶子数、高度、宽度,二叉树的复制和销毁
    js异步编程面试题你能答上来几道
    【rust工具链】
  • 原文地址:https://blog.csdn.net/qq_42731062/article/details/126011917