鱼香ROS社区
    • 版块
    • 最新
    • 未解决
    • 已解决
    • 群组
    • 注册
    • 登录
    紧急通知:禁止一切关于政治&VPN翻墙等话题,发现相关帖子会立马删除封号
    提问前必看的发帖注意事项: 社区问答规则(小鱼个人)更新 | 高质量帖子发布指南

    gazebo小车不动

    已定时 已固定 已锁定 已移动 已解决
    综合问题
    gazebo ros 小车仿真
    2
    4
    798
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • 8212348778
      心中有梦想!
      最后由 编辑

      小车在RViz里面就可以动,在gazebo里面就不能动,不知道为啥,还请大佬多多指教!!!

      <launch>
      
          <!-- 设置launch文件的参数 -->
          <arg name="world_name" value="$(find mrobot_gazebo)/worlds/playground.world"/>
          <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"/>
      
          <!-- 运行gazebo仿真环境 -->
          <include file="$(find gazebo_ros)/launch/empty_world.launch">
              <arg name="world_name" value="$(arg world_name)" />
              <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>
      
          <!-- 加载机器人模型描述参数/urdf/xacro/gazebo/mbot_base_gazebo.xacro -->
          <param name="robot_description" command="$(find xacro)/xacro --inorder '$(find mbot_description)/urdf/xacro/gazebo/mbot_base_gazebo.xacro'" /> 
      
          <!-- 设置GUI参数,显示关节控制插件 -->
          <param name="use_gui" value="$(arg gui)"/>
      
          <node name="arbotix" pkg="arbotix_python" type="arbotix_driver" output="screen">
      	<rosparam file="$(find mbot_description)/config/fake_mbot_arbotix.yaml" command="load" />
      	<param name="sim" value="true"/>
          </node>
      
          <!-- 运行joint_state_publisher节点,发布机器人的关节状态  -->
          <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" ></node> 
      
          <!-- 运行robot_state_publisher节点,发布tf  -->
          <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher"  output="screen" >
              <param name="publish_frequency" type="double" value="50.0" />
          </node>
      
          <!-- 在gazebo中加载机器人模型-->
          <node name="urdf_spawner" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen"
                args="-urdf -model mrobot -param robot_description"/> 
      
          <!-- 运行rviz可视化界面 -->
          <node name="rviz" pkg="rviz" type="rviz" args="-d $(find mbot_description)/config/mbot_arbotix.rviz" required="true" />
      
      
      </launch>
      

      第二段:urdf/xacro/gazebo/mbot_base_gazebo.xacro

      <?xml version="1.0"?>
      <robot name="mbot" xmlns:xacro="http://www.ros.org/wiki/xacro">
      
          <!-- PROPERTY LIST -->
          <xacro:property name="M_PI" value="3.1415926"/>
          <xacro:property name="base_mass"   value="20" /> 
          <xacro:property name="base_radius" value="0.20"/>
          <xacro:property name="base_length" value="0.16"/>
      
          <xacro:property name="wheel_mass" value="2"/>
          <xacro:property name="wheel_radius" value="0.06"/>
          <xacro:property name="wheel_length" value="0.025"/>
          <xacro:property name="wheel_joint_y" value="0.19"/>
          <xacro:property name="wheel_joint_z" value="0.05"/>
      
          <xacro:property name="caster_mass" value="0.5"/>
          <xacro:property name="caster_radius" value="0.015"/> <!-- wheel_radius - ( base_length/2 - wheel_joint_z) -->
          <xacro:property name="caster_joint_x" value="0.18"/>
      
          <!-- Defining the colors used in this robot -->
          <material name="yellow">
              <color rgba="1 0.4 0 1"/>
          </material>
          <material name="black">
              <color rgba="0 0 0 0.95"/>
          </material>
          <material name="gray">
              <color rgba="0.75 0.75 0.75 1"/>
          </material>
      
      
          <!-- Macro for inertia matrix -->
          <xacro:macro name="sphere_inertial_matrix" params="m r">
              <inertial>
                  <mass value="${m}" />
                  <inertia ixx="${2*m*r*r/5}" ixy="0" ixz="0"
                      iyy="${2*m*r*r/5}" iyz="0" 
                      izz="${2*m*r*r/5}" />
              </inertial>
          </xacro:macro>
      
          <xacro:macro name="cylinder_inertial_matrix" params="m r h">
              <inertial>
                  <mass value="${m}" />
                  <inertia ixx="${m*(3*r*r+h*h)/12}" ixy = "0" ixz = "0"
                      iyy="${m*(3*r*r+h*h)/12}" iyz = "0"
                      izz="${m*r*r/2}" /> 
              </inertial>
          </xacro:macro>
      
      
          <!-- Macro for robot wheel -->
          <xacro:macro name="wheel" params="prefix reflect">
              <joint name="base_${prefix}_wheel_joint" type="continuous">
                  <origin xyz="0 ${reflect*wheel_joint_y} ${-wheel_joint_z}" rpy="0 0 0"/>
                  <parent link="base_link"/>
                  <child link="${prefix}_wheel_link"/>
                  <axis xyz="0 1 0"/>
              </joint>
      
              <link name="${prefix}_wheel_link">
                  <visual>
                      <origin xyz=" 0 0 0 " rpy="${M_PI/2} 0 0" />
                      <geometry>
                          <cylinder radius="${wheel_radius}" length = "${wheel_length}"/>
                      </geometry>
                      <material name="gray" />
                  </visual>
      
                  <collision>
                      <origin xyz="0 0 0" rpy="${M_PI/2} 0 0 " />
                      <geometry>
                          <cylinder radius="${wheel_radius}" length="${wheel_length}" />
                      </geometry>
                  </collision>
                  <cylinder_inertial_matrix  m="${wheel_mass}" r="${wheel_radius}" h="${wheel_length}" />
              </link>
      
              <gazebo reference="${prefix}_wheel_link">
                  <material>Gazebo/Gray</material>
              </gazebo>
      
              <!-- Transmission is important to link the joints and the controller -->
              <transmission name="${prefix}_wheel_joint_trans">
                  <type>transmission_interface/SimpleTransmission</type>
                  <joint name="${prefix}_wheel_joint" >
                      <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
                  </joint>
                  <actuator name="${prefix}_wheel_joint_motor">
                      <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
                      <mechanicalReduction>1</mechanicalReduction>
                  </actuator>
              </transmission>
          </xacro:macro>
      
      
          <!-- Macro for robot caster -->
          <xacro:macro name="caster" params="prefix reflect">
              <joint name="${prefix}_caster_joint" type="continuous">
                  <origin xyz="${reflect*caster_joint_x} 0 ${-(base_length/2 + caster_radius)}" rpy="0 0 0" />
                  <parent link="base_link"/>
                  <child link="${prefix}_caster_link" />
                  <axis xyz="0 1 0"/>
              </joint>
      
              <link name="${prefix}_caster_link">
                  <visual>
                      <origin xyz=" 0 0 0 " rpy="0 0 0" />
                      <geometry>
                          <sphere radius="${caster_radius}" />
                      </geometry>
                      <material name="black" />
                  </visual>
      
                  <collision>
                      <origin xyz="0 0 0" rpy="0 0 0 " />
                      <geometry>
                          <sphere radius="${caster_radius}" />
                      </geometry>
                  </collision>
                  <sphere_inertial_matrix  m="${caster_mass}" r="${caster_radius}"  />
              </link>
      
              <gazebo reference="${prefix}_caster_link">
                  <material>Gazebo/Black</material>
              </gazebo>
          </xacro:macro>
      
      
          <xacro:macro name="mbot_base_gazebo">
      	<link name="base_footprint">
                  <visual>
                      <origin xyz=" 0 0 0 " rpy="0 0 0" />
                      <geometry>
                          <box size="0.001 0.001 0.001" />
                      </geometry>
                  </visual>
              </link>
              <gazebo reference="base_footprint">
                  <turnGravityOff>false</turnGravityOff>
              </gazebo>
      
      	<joint name="base_footprint_joint" type="fixed">
                  <origin xyz="0 0 ${base_length/2 + caster_radius*2}" rpy="0 0 0" />
                  <parent link="base_footprint"/>
                  <child link="base_link" />
              </joint>
      
      	<link name="base_link">
                  <visual>
                      <origin xyz=" 0 0 0 " rpy="0 0 0" />
                      <geometry>
                          <cylinder length="${base_length}" radius="${base_radius}" />
                      </geometry>
      		<material name="yellow" />
                  </visual>
                  <collision>
                      <origin xyz="0 0 0" rpy="0 0 0 " />
                      <geometry>
                          <cylinder length="${base_length}" radius="${base_radius}" />
                      </geometry>
                  </collision>
                  <cylinder_inertial_matrix  m="${base_mass}" r="${base_radius}" h="${base_length}" />
              </link>
      
              <gazebo reference="base_link">
                  <material>Gazebo/Blue</material>
              </gazebo>
      
      	<wheel prefix="l" reflect="-1"/>
      	<wheel prefix="r" reflect="1"/>
      
      	<caster prefix="front" reflect="-1"/>
      	<caster prefix="back" reflect="1"/>
          
      
              <!-- controller -->
              <gazebo>
                  <plugin name="differential_drive_controller" filename="libgazebo_ros_diff_drive.so">
                      <rosDebugLevel>Debug</rosDebugLevel>
                      <publishWheelTF>true</publishWheelTF>
                      <robotNamespace>/</robotNamespace>
                      <publishTf>1</publishTf>
                      <publishWheelJointState>true</publishWheelJointState>
                      <alwaysOn>true</alwaysOn>
                      <updateRate>100.0</updateRate>
                      <legacyMode>true</legacyMode>
                      <leftJoint>left_wheel_joint</leftJoint>
                      <rightJoint>right_wheel_joint</rightJoint>
                      <wheelSeparation>${wheel_joint_y*2}</wheelSeparation>
                      <wheelDiameter>${2*wheel_radius}</wheelDiameter>
                      <broadcastTF>1</broadcastTF>
                      <wheelTorque>30</wheelTorque>
                      <wheelAcceleration>1.8</wheelAcceleration>
                      <commandTopic>cmd_vel</commandTopic>
                      <odometryFrame>odom</odometryFrame> 
                      <odometryTopic>odom</odometryTopic> 
                      <robotBaseFrame>base_footprint</robotBaseFrame>
                  </plugin>
              </gazebo> 
      
          </xacro:macro>
      
          <xacro:mbot_base_gazebo/>
      </robot>
      

      eef53aeb-8522-4d8d-a24d-8dcee638c976-image.png

      1 条回复 最后回复 回复 引用 0
      • 16870285121
        -
        最后由 编辑

        朋友,不知道你和我是不是同样的问题,或许可以试试看

        sudo apt install ros-melodic-gazebo-ros-pkgs  ros-melodic-gazebo-msgs  ros-melodic-gazebo-plugins  ros-melodic-gazebo-ros-control
        

        参考

        https://www.freesion.com/article/8223995772/
        
        8212348778 1 条回复 最后回复 回复 引用 0
        • 8212348778
          心中有梦想! @1687028512
          最后由 编辑

          @1687028512 谢谢你呀,我跑了一下例程,例程没问题。应该是我这个代码了问题!!谢谢你

          16870285121 1 条回复 最后回复 回复 引用 0
          • 16870285121
            - @821234877
            最后由 编辑

            @821234877 客气了~多多交流呀😁

            1 条回复 最后回复 回复 引用 0
            • 小鱼小 小鱼 从 中的 社区&开源 移动了该主题
            • 小鱼小 小鱼 将这个主题转为问答主题,在
            • 小鱼小 小鱼 将这个主题标记为已解决,在
            • 第一个帖子
              最后一个帖子
            皖ICP备16016415号-7
            Powered by NodeBB | 鱼香ROS