gazebo中添加gps模块

首先,需下载一个功能包hector gazebo plugins。Hector _ gazebo _ plugins 提供了来自 Hector 团队的 gazebo 插件。目前,它包含一个6瓦差分驱动插件,一个 IMU 传感器插件,一个地球磁场传感器插件,一个 GPS 传感器插件和一个声纳测距插件。

安装hector_gazebo_plugins

sudo apt-get install ros-melodic-hector-gazebo-plugins

添加gps的xacro文件

导入gps的物体描述xacro文件;即gps的物体描述代码与功能配置代码,需连接在一起。原因:如果是传感器的功能配置plugin标签,则必须在gazebo标签内的sensor标签下,否则不起作用。而该gps的配置gazebo标签内没有sensor标签,若想plugin标签起作用,就得紧接在物体描述代码后,而不能分成两个单独得文件。

<robot name="gps" xmlns:xacro="http://wiki.ros.org/xacro">  
    <xacro:property name="gps_offset_x" value="0" />
    <xacro:property name="gps_offset_y" value="0" />
    <xacro:property name="gps_offset_z" value="0.0075" />
    <xacro:property name="gps_size"     value="0.005" />
    <xacro:property name="gps_m" value="0.01" /> 
  
    <link name="gps">
        <visual>
            <origin rpy="0 0 0" xyz="0 0 0" />
            <geometry>
                    <box size="${gps_size} ${gps_size} ${gps_size}"/>
            </geometry>      
            <material name= "red" >
              <color rgba="1.0 0.0 0.0 1.0" />
            </material>
        </visual>
        <collision>
            <geometry>
                <box size="${gps_size} ${gps_size} ${gps_size}" />
            </geometry>
            <origin xyz="0.0 0.0 0" rpy="0.0 0.0 0.0" />
        </collision>
        <xacro:Box_inertial_matrix m = "${gps_m}" l = "${gps_size}" w = "${gps_size}" h = "${gps_size}"/>
    </link>

    <joint name="gps2imu" type="fixed">
        <origin xyz="${gps_offset_x} ${gps_offset_y} ${gps_offset_z}" rpy="0 0 0" />
        <parent link="imu"/>
        <child link="gps"/>
    </joint>

    <gazebo reference="gps">
        <material>Gazebo/Green</material>
    </gazebo>

        <gazebo>
            <plugin name="gazebo_ros_gps" filename="libhector_gazebo_ros_gps.so">
                <updateRate>4.0</updateRate>
                <bodyName>gps</bodyName>
                <frameId>gps</frameId>
                <topicName>fix</topicName>
                <velocityTopicName>fix_velocity</velocityTopicName>
                <referenceLatitude>-30.06022459407145675</referenceLatitude>
                <referenceLongitude>-51.173913575780311191</referenceLongitude>
                <referenceHeading>90</referenceHeading>
                <referenceAltitude>10</referenceAltitude>
                <offset>0 0 0</offset>
                <drift>0.001 0.001 0.001</drift>
                <gaussianNoise>0.05 0.05 0.05</gaussianNoise>
                <velocityDrift>0.001 0.001 0.001</velocityDrift>
                <velocityGaussianNoise>0.5 0.5 0.5</velocityGaussianNoise>
            </plugin>
        </gazebo>

</robot>

集成xacro文件

<robot name="mycar" xmlns:xacro="http://wiki.ros.org/xacro">

        <xacro:include filename="head.xacro"/>
  
        <xacro:include filename="gazebo_carbase.xacro"/>
        <xacro:include filename="gazebo_imu.xacro"/>
        <xacro:include filename="gazebo_rplidar.xacro"/>
        <xacro:include filename="gazebo_gps.xacro"/>

        <xacro:include filename="move.xacro"/>
        <xacro:include filename="sensor_rplidar.xacro"/>  
        <xacro:include filename="sensor_imu.xacro"/>  
   
</robot>
最后修改:2023 年 11 月 11 日
如果觉得我的文章对你有用,请随意赞赏