锐单电子商城 , 一站式电子元器件采购平台!
  • 电话:400-990-0325

ROS学习笔记9:gazebo仿真传感器

时间:2022-12-09 17:00:00 1472d光电传感器node传感器model1022传感器h61光电传感器z系列激光传感器

gazebo仿真传感器

  • 一、加载小车模型
    • 1.xacro配置文件
      • 1.1demo05_car_base.urdf.xacro
      • 1.2demo06_camera.urdf.xacro
      • 1.3demo07_lidar.urdf.xacro
      • 1.4head.xcaro
      • 1.5car.urdf.xacro
    • 2.launch启动文件
      • 2.1demo04_control.launch
      • 2.1demo05_sensor.launch
  • 二、获取传感器数据

(自学笔记,持续更新)
创建功能包urdf02_gzebo,添加依赖urdf、xacro、gazebo_ros、gazebo_ros_control、gazebo_plugins。获取环境模型链接。

一、加载小车模型

首先要加载之前搭建的小车模型。以下几个xacro文件在原有的模型基础上增加了惯性矩阵和碰撞检测以及功能仿真模块。

1.xacro配置文件

1.1demo05_car_base.urdf.xacro

<robot name="my_base" xmlns:xacro="http://www.ros.org/wiki/xacro">      <xacro:property name="PI" value="3.1415926"/>      <material name="black">         <color rgba="0.0 0.0 0.0 1.0" />     material>      <xacro:property name="base_footprint_radius" value="0.001" />      <xacro:property name="base_link_radius" value="0.1" />      <xaro:property name="base_link_length" value="0.08" /> 
    <xacro:property name="earth_space" value="0.015" /> 
    <xacro:property name="base_link_m" value="0.5" /> 

    <link name="base_footprint">
      <visual>
        <geometry>
          <sphere radius="${base_footprint_radius}" />
        geometry>
      visual>
    link>

    <link name="base_link">
      <visual>
        <geometry>
          <cylinder radius="${base_link_radius}" length="${base_link_length}" />
        geometry>
        <origin xyz="0 0 0" rpy="0 0 0" />
        <material name="yellow">
          <color rgba="0.5 0.3 0.0 0.5" />
        material>
      visual>
      <collision>
        <geometry>
          <cylinder radius="${base_link_radius}" length="${base_link_length}" />
        geometry>
        <origin xyz="0 0 0" rpy="0 0 0" />
      collision>
      <xacro:cylinder_inertial_matrix m="${base_link_m}" r="${base_link_radius}" h="${base_link_length}" />

    link>


    <joint name="base_link2base_footprint" type="fixed">
      <parent link="base_footprint" />
      <child link="base_link" />
      <origin xyz="0 0 ${earth_space + base_link_length / 2 }" />
    joint>
    <gazebo reference="base_link">
        <material>Gazebo/Yellowmaterial>
    gazebo>


    <xacro:property name="wheel_radius" value="0.0325" />
    <xacro:property name="wheel_length" value="0.015" />
    <xacro:property name="wheel_m" value="0.05" /> 


    <xacro:macro name="add_wheels" params="name flag">
      <link name="${name}_wheel">
        <visual>
          <geometry>
            <cylinder radius="${wheel_radius}" length="${wheel_length}" />
          geometry>
          <origin xyz="0.0 0.0 0.0" rpy="${PI / 2} 0.0 0.0" />
          <material name="black" />
        visual>
        <collision>
          <geometry>
            <cylinder radius="${wheel_radius}" length="${wheel_length}" />
          geometry>
          <origin xyz="0.0 0.0 0.0" rpy="${PI / 2} 0.0 0.0" />
        collision>
        <xacro:cylinder_inertial_matrix m="${wheel_m}" r="${wheel_radius}" h="${wheel_length}" />

      link>

      <joint name="${name}_wheel2base_link" type="continuous">
        <parent link="base_link" />
        <child link="${name}_wheel" />
        <origin xyz="0 ${flag * base_link_radius} ${-(earth_space + base_link_length / 2 - wheel_radius) }" />
        <axis xyz="0 1 0" />
      joint>

      <gazebo reference="${name}_wheel">
        <material>Gazebo/Redmaterial>
      gazebo>

    xacro:macro>
    <xacro:add_wheels name="left" flag="-1" />
    <xacro:add_wheels name="right" flag="1" />

    <xacro:property name="support_wheel_radius" value="0.0075" /> 
    <xacro:property name="support_wheel_m" value="0.03" />

   
    <xacro:macro name="add_support_wheel" params="name flag" >
      <link name="${name}_wheel">
        <visual>
            <geometry>
                <sphere radius="${support_wheel_radius}" />
            geometry>
            <origin xyz="0 0 0" rpy="0 0 0" />
            <material name="black" />
        visual>
        <collision>
            <geometry>
                <sphere radius="${support_wheel_radius}" />
            geometry>
            <origin xyz="0 0 0" rpy="0 0 0" />
        collision>
        <xacro:sphere_inertial_matrix m="${support_wheel_m}" r="${support_wheel_radius}" />
      link>

      <joint name="${name}_wheel2base_link" type="continuous">
          <parent link="base_link" />
          <child link="${name}_wheel" />
          <origin xyz="${flag * (base_link_radius - support_wheel_radius)} 0 ${-(base_link_length / 2 + earth_space / 2)}" />
          <axis xyz="1 1 1" />
      joint>
      <gazebo reference="${name}_wheel">
        <material>Gazebo/Redmaterial>
      gazebo>
    xacro:macro>

    <xacro:add_support_wheel name="front" flag="1" />
    <xacro:add_support_wheel name="back" flag="-1" />
robot>

1.2demo06_camera.urdf.xacro

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

    <xacro:property name="camera_length" value="0.01" /> 
    <xacro:property name="camera_width" value="0.025" />
    <xacro:property name="camera_height" value="0.025" /> 
    <xacro:property name="camera_x" value="0.08" /> 
    <xacro:property name="camera_y" value="0.0" /> 
    <xacro:property name="camera_z" value="${base_link_length / 2 + camera_height / 2}" /> 
    <xacro:property name="camera_m" value="0.01" /> 

    <link name="camera">
        <visual>
            <geometry>
                <box size="${camera_length} ${camera_width} ${camera_height}" />
            geometry>
            <origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" />
            <material name="black" />
        visual>
        <collision>
            <geometry>
                <box size="${camera_length} ${camera_width} ${camera_height}" />
            geometry>
            <origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" />
        collision>
        <xacro:Box_inertial_matrix m="${camera_m}" l="${camera_length}" w="${camera_width}" h="${camera_height}" />
    link>

    <joint name="camera2base_link" type="fixed">
        <parent link="base_link" />
        <child link="camera" />
        <origin xyz="${camera_x} ${camera_y} ${camera_z}" />
    joint>
    <gazebo reference="camera">
        <material>Gazebo/Bluematerial>
    gazebo>
robot>

1.3demo07_lidar.urdf.xacro

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


    <xacro:property name="support_length" value="0.15" /> 
    <xacro:property name="support_radius" value="0.01" /> 
    <xacro:property name="support_x" value="0.0" /> 
    <xacro:property name="support_y" value="0.0" /> 
    <xacro:property name="support_z" value="${base_link_length / 2 + support_length / 2}" /> 
    <xacro:property name="support_m" value="0.02" /> 

    <link name="support">
        <visual>
            <geometry>
                <cylinder radius="${support_radius}" length="${support_length}" />
            geometry>
            <origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" />
            <material name="red">
                <color rgba="0.8 0.2 0.0 0.8" />
            material>
        visual>

        <collision>
            <geometry>
                <cylinder radius="${support_radius}" length 

相关文章