<?xml version="1.0"?>
<robot name="mycar">

  <link name="base_footprint">
    <origin xyz="0 0 0" rpy="0 0 0" />
  </link>
  <link name="base_link">
  </link>
  <joint name="base_joint" type="fixed">
    <parent link="base_footprint" />
    <child link="base_link" />
    <origin xyz="0 0.0 -0.09" rpy="0 0 0" />
  </joint>
  <link name="chassis_link">
    <inertial>
      <origin xyz="0.0374140021041951 -0.000373005187591258 -0.0771282894414029" rpy="0 0 0" />
      <mass value="12" />
      <inertia ixx="2.0833333333333335"
        ixy="0" ixz="0"
        iyy="11.979166666666668" iyz="0"
        izz="11.979166666666668" />
    </inertial>
    <visual>
      <origin xyz="0 0 0" rpy="0 0 0" />
      <geometry>
        <box size="0.276 0.164 0.08" />
      </geometry>
      <material name="base_color">
        <color rgba="0.4 0.039 0.039 1" />
      </material>
    </visual>
    <collision>
      <origin rpy="0 0 0" xyz="0 0 0.07" />
      <geometry>
        <box size="0.276 0.164 0.08" />
      </geometry>
    </collision>
  </link>
  <joint name="chassis_joint" type="fixed">
    <parent link="base_link" />
    <child link="chassis_link" />
    <origin xyz="0 0.0 0.1555" rpy="0 0 0" />
  </joint>
  <link name="borad_link">
    <inertial>
      <origin xyz="0 0 0" rpy="0 0 0" />
      <mass value="12" />
      <inertia ixx="2.0833333333333335"
        ixy="0" ixz="0"
        iyy="11.979166666666668" iyz="0"
        izz="11.979166666666668" />
    </inertial>
    <visual>
      <geometry>
        <box size="0.200 0.164 0.07" />
      </geometry>
      <origin rpy="0 0 0" xyz="0 0 0" />
      <material name="rgba(246,152,152,1)">
        <color rgba="0.9647058823529412 0.596078431372549 0.596078431372549 1" />
      </material>
    </visual>
    <collision>
      <origin rpy="0 0 0" xyz="0 0 0.0" />
      <geometry>
        <box size="0.200 0.164 0.07" />
      </geometry>
    </collision>
  </link>
  <joint name="board_joint" type="fixed">
    <parent link="chassis_link" />
    <child link="borad_link" />
    <origin rpy="0 0 0" xyz="0 0 0.075" />
  </joint>
  <link name="fr_left_steer_link">
    <inertial>
      <origin xyz="0 0 0" rpy="0 0 0" />
      <mass value="0.01" />
      <inertia
        ixx="9.880333333333333E-5"
        ixy="0" ixz="0"
        iyy="9.880333333333333E-5"
        iyz="0" izz="9.8E-5" />
    </inertial>
  </link>
  <joint name="fr_left_steer_joint" type="revolute">
    <origin xyz="0.0715 0.0945 -0.03" rpy="0 0 0" />
    <parent link="chassis_link" />
    <child link="fr_left_steer_link" />
    <axis xyz="0 0 1" />
    <limit upper="0.6" lower="-0.6" effort="-1.0" velocity="-20.0" />
  </joint>

  <link name="fr_left_wheel_link">
    <inertial>
      <origin xyz="0 0 0" rpy="0 0 0" />
      <mass value="1.5" />
      <inertia
        ixx="0.02964"
        ixy="0" ixz="0"
        iyy="0.02964"
        iyz="0" izz="0.0294" />
    </inertial>
    <visual>
      <origin xyz="0 0 0" rpy="0 0 0" />
      <geometry>
        <cylinder length="0.025" radius="0.03" />
      </geometry>
      <material name="">
        <color rgba="0.223529411764706 0.223529411764706 0.223529411764706 1" />
      </material>
    </visual>
    <collision>
      <origin xyz="0 0 0" rpy="0 0 0" />
      <geometry>
        <cylinder length="0.025" radius="0.03" />
      </geometry>
    </collision>
  </link>
  <joint name="fr_left_wheel_joint" type="continuous">
    <origin xyz="0 0 0" rpy="1.5708 0 0" />
    <parent link="fr_left_steer_link" />
    <child link="fr_left_wheel_link" />
    <axis xyz="0 0 -1" />
     <dynamics friction="0.2" damping="0.12" />
    <limit lower="-3.14159" upper="3.14159" effort="100" velocity="-200" />
  </joint>
  <link name="fr_right_steer_link">
    <inertial>
      <origin xyz="0 0 0" rpy="0 0 0" />
      <mass value="0.01" />
      <inertia
        ixx="9.880333333333333E-5"
        ixy="0" ixz="0"
        iyy="9.880333333333333E-5"
        iyz="0" izz="9.8E-5" />
    </inertial>
  </link>
  <joint name="fr_right_steer_joint" type="revolute">
    <origin xyz="0.0715 -0.0945 -0.03" rpy="0 0 0" />
    <parent link="chassis_link" />
    <child link="fr_right_steer_link" />
    <axis xyz="0 0 1" />
    <limit upper="0.6" lower="-0.6" effort="-1.0" velocity="-20.0" />
  </joint>
  <link name="fr_right_wheel_link">
    <inertial>
      <origin xyz="0 0 0" rpy="0 0 0" />
      <mass value="1.5" />
      <inertia
        ixx="0.02964"
        ixy="0" ixz="0"
        iyy="0.02964"
        iyz="0" izz="0.0294" />
    </inertial>
    <visual>
      <origin xyz="0 0 0" rpy="0 0 0" />
      <geometry>
        <cylinder length="0.025" radius="0.03" />
      </geometry>
      <material name="">
        <color rgba="0.223529411764706 0.223529411764706 0.223529411764706 1" />
      </material>
    </visual>
    <collision>
      <origin xyz="0 0 0" rpy="0 0 0" />
      <geometry>
        <cylinder length="0.025" radius="0.03" />
      </geometry>
    </collision>
  </link>
  <joint name="fr_right_wheel_joint" type="continuous">
    <origin xyz="0 0 0" rpy="-1.5708 0 0" />
    <parent link="fr_right_steer_link" />
    <child link="fr_right_wheel_link" />
    <axis xyz="0 0 1" />
     <dynamics friction="0.2" damping="0.12" />
    <limit lower="-3.14159" upper="3.14159" effort="100" velocity="-200" />
  </joint>


  <link name="re_left_wheel_link">
    <inertial>
      <origin xyz="0 0 0" rpy="0 0 0" />
      <mass value="1.5" />
      <inertia
        ixx="0.02964"
        ixy="0" ixz="0"
        iyy="0.02964"
        iyz="0" izz="0.0294" />
    </inertial>
    <visual>
      <origin xyz="0 0 0" rpy="0 0 0" />
      <geometry>
        <cylinder length="0.025" radius="0.03" />
      </geometry>
      <material name="">
        <color rgba="0.37647 0.37647 0.37647 1" />
      </material>
    </visual>
    <collision>
      <origin xyz="0 0 0" rpy="0 0 0" />
      <geometry>
        <cylinder length="0.025" radius="0.03" />
      </geometry>
    </collision>
  </link>
  <joint name="re_left_wheel_joint" type="continuous">
    <origin xyz="-0.0715 0.0945 -0.03" rpy="1.5708 0 0" />
    <parent link="chassis_link" />
    <child link="re_left_wheel_link" />
    <axis xyz="0 0 -1" />
     <dynamics friction="0.2" damping="0.12" />
    <limit lower="-3.14159" upper="3.14159" effort="100" velocity="-200" />
  </joint>
  <link name="re_right_wheel_link">
    <inertial>
      <origin xyz="0 0 0" rpy="0 0 0" />
      <mass value="1.5" />
      <inertia
        ixx="0.02964"
        ixy="0" ixz="0"
        iyy="0.02964"
        iyz="0" izz="0.0294" />
    </inertial>
    <visual>
      <origin xyz="0 0 0" rpy="0 0 0" />
      <geometry>
        <cylinder length="0.025" radius="0.03" />
      </geometry>
      <material name="">
        <color rgba="0.37647 0.37647 0.37647 1" />
      </material>
    </visual>
    <collision>
      <origin xyz="0 0 0" rpy="0 0 0" />
      <geometry>
        <cylinder length="0.025" radius="0.03" />
      </geometry>
    </collision>
  </link>
  <joint name="re_right_wheel_joint" type="continuous">
    <origin xyz="-0.0715 -0.0945 -0.03" rpy="-1.5708 0 0" />
    <parent link="chassis_link" />
    <child link="re_right_wheel_link" />
    <axis xyz="0 0 1" />
     <dynamics friction="0.2" damping="0.1" />
    <limit lower="-3.14159" upper="3.14159" effort="100" velocity="-200" />
  </joint>


  <link name="virtual_steer_link">
    <visual>
      <origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" />
      <geometry>
        <box size="0.01 0.01 0.01" />
      </geometry>
      <material name="">
        <color rgba="1.0 1.0 0.0 1" />
      </material>
    </visual>
    <inertial>
      <origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" />
      <mass value="0.001" />
      <inertia ixx="0.0" ixy="0.0" ixz="0.0" iyy="0.0" iyz="0.0" izz="0.0" />
    </inertial>
  </link>
  <joint name="virtual_steering_wheel_joint" type="revolute">
    <origin xyz="0.0715 0.0 0.0" rpy="0.0 0.0 0.0" />
    <parent link="chassis_link" />
    <child link="virtual_steer_link" />
    <axis xyz="-1 0 0" />
    <limit lower="-3" upper="3" effort="200" velocity="20" />
  </joint>
  <!-- **************************** -->
  <!-- 激光雷达 -->
  <link name="laser_link">
    <visual>
      <geometry>
        <cylinder radius="0.025" length="0.05" />
      </geometry>
      <origin rpy="0 0 0" xyz="0.04 0 0" />
      <material name="rgba(255,255,255,1)">
        <color rgba="1 1 1 1" />
      </material>
    </visual>
  </link>

  <joint name="laser_joint" type="fixed">
    <parent link="borad_link" />
    <child link="laser_link" />
    <origin rpy="0 0 0" xyz="0.045 0 0.065" />
  </joint>

  <!-- IMU -->
  <link name="imu_link">
    <visual>
      <geometry>
        <box size="0.02 0.02 0.02" />
      </geometry>
      <origin rpy="0 0 0" xyz="0 0 -0.01" />
      <material name="">
        <color rgba="1 1 1 1" />
      </material>
    </visual>
  </link>

  <joint name="imu_joint" type="fixed">
    <parent link="borad_link" />
    <child link="imu_link" />
    <origin rpy="0 0 0" xyz="0 0 0.045" />
  </joint>

  <!-- ackerman -->

  <gazebo>
    <plugin name="gazebo_ros_ackermann_drive" filename="libgazebo_ros_ackermann_drive.so">

      <ros>
        <namespace>/</namespace>
        <remapping>cmd_vel:=cmd_vel</remapping>
        <remapping>odom:=odom</remapping>
        <remapping>distance:=distance</remapping>
      </ros>
      <update_rate>30.0</update_rate>
      <front_left_joint>fr_left_wheel_joint</front_left_joint>
      <front_right_joint>fr_right_wheel_joint</front_right_joint>
      <rear_left_joint>re_left_wheel_joint</rear_left_joint>
      <rear_right_joint>re_right_wheel_joint</rear_right_joint>
      <left_steering_joint>fr_left_steer_joint</left_steering_joint>
      <right_steering_joint>fr_right_steer_joint</right_steering_joint>
      <steering_wheel_joint>virtual_steering_wheel_joint</steering_wheel_joint>
      <max_steer>0.583972</max_steer>
      <max_steering_angle>1.570796</max_steering_angle>
      <max_speed>4</max_speed>


      <left_steering_pid_gain>600 0 6</left_steering_pid_gain>
      <left_steering_i_range>0 0</left_steering_i_range>
      <right_steering_pid_gain>600 0 6</right_steering_pid_gain>
      <right_steering_i_range>0 0</right_steering_i_range>
      <linear_velocity_pid_gain>800 0 0</linear_velocity_pid_gain>
      <linear_velocity_i_range>0 0</linear_velocity_i_range>
      <odometry_frame>odom</odometry_frame>
      <robot_base_frame>base_footprint</robot_base_frame>
      <publish_odom>true</publish_odom>
      <publish_odom_tf>true</publish_odom_tf>

    </plugin>


    <plugin name="gazebo_ros_joint_state_publisher"
      filename="libgazebo_ros_joint_state_publisher.so">
      <update_rate>100</update_rate>
      <joint_name>fr_right_steer_joint</joint_name>
      <joint_name>fr_right_wheel_joint</joint_name>
      <joint_name>fr_left_steer_joint</joint_name>
      <joint_name>fr_left_wheel_joint</joint_name>
      <joint_name>re_right_wheel_joint</joint_name>
      <joint_name>re_left_wheel_joint</joint_name>
      <joint_name>virtual_steering_wheel_joint</joint_name>
    </plugin>
  </gazebo>


  <gazebo reference="imu_link">
    <sensor name="imu_sensor" type="imu">
      <plugin filename="libgazebo_ros_imu_sensor.so" name="imu_plugin">
        <ros>
          <namespace>/</namespace>
          <remapping>~/out:=imu</remapping>
        </ros>
        <initial_orientation_as_reference>false</initial_orientation_as_reference>
      </plugin>
      <always_on>true</always_on>
      <update_rate>100</update_rate>
      <visualize>true</visualize>
      <imu>
        <angular_velocity>
          <x>
            <noise type="gaussian">
              <mean>0.0</mean>
              <stddev>2e-4</stddev>
              <bias_mean>0.0000075</bias_mean>
              <bias_stddev>0.0000008</bias_stddev>
            </noise>
          </x>
          <y>
            <noise type="gaussian">
              <mean>0.0</mean>
              <stddev>2e-4</stddev>
              <bias_mean>0.0000075</bias_mean>
              <bias_stddev>0.0000008</bias_stddev>
            </noise>
          </y>
          <z>
            <noise type="gaussian">
              <mean>0.0</mean>
              <stddev>2e-4</stddev>
              <bias_mean>0.0000075</bias_mean>
              <bias_stddev>0.0000008</bias_stddev>
            </noise>
          </z>
        </angular_velocity>
        <linear_acceleration>
          <x>
            <noise type="gaussian">
              <mean>0.0</mean>
              <stddev>1.7e-2</stddev>
              <bias_mean>0.1</bias_mean>
              <bias_stddev>0.001</bias_stddev>
            </noise>
          </x>
          <y>
            <noise type="gaussian">
              <mean>0.0</mean>
              <stddev>1.7e-2</stddev>
              <bias_mean>0.1</bias_mean>
              <bias_stddev>0.001</bias_stddev>
            </noise>
          </y>
          <z>
            <noise type="gaussian">
              <mean>0.0</mean>
              <stddev>1.7e-2</stddev>
              <bias_mean>0.1</bias_mean>
              <bias_stddev>0.001</bias_stddev>
            </noise>
          </z>
        </linear_acceleration>
      </imu>
    </sensor>
  </gazebo>

  <gazebo reference="laser_link">
    <sensor name="laser_sensor" type="ray">
      <always_on>true</always_on>
      <visualize>true</visualize>
      <update_rate>5</update_rate>
      <pose>0 0 0.075 0 0 0</pose>
      <ray>
        <scan>
          <horizontal>
            <samples>360</samples>
            <resolution>1.000000</resolution>
            <min_angle>0.000000</min_angle>
            <max_angle>6.280000</max_angle>
          </horizontal>
        </scan>
        <range>
          <min>0.120000</min>
          <max>3.5</max>
          <resolution>0.015000</resolution>
        </range>
        <noise>
          <type>gaussian</type>
          <mean>0.0</mean>
          <stddev>0.01</stddev>
        </noise>
      </ray>

      <plugin name="laserscan" filename="libgazebo_ros_ray_sensor.so">
        <ros>

          <remapping>~/out:=scan</remapping>
        </ros>
        <output_type>sensor_msgs/LaserScan</output_type>
        <frame_name>laser_link</frame_name>
      </plugin>
    </sensor>
  </gazebo>
</robot>