ArduPilot / ardupilot_gazebo

Plugins and models for vehicle simulation in Gazebo Sim with ArduPilot SITL controllers
GNU Lesser General Public License v3.0
82 stars 78 forks source link

Anemometer: add wind sensor #48

Closed srmainwaring closed 1 year ago

srmainwaring commented 1 year ago

Add support for an anemometer sensor.

Details

The existing SITL-JSON schema includes a windVane element that expects the apparent wind speed and direction.

The direction is the angle radians from the forward direction using the FRD frame convention. Angles should be in the range [-PI, PI]. The speed is measured in m/s.

windVane {
  direction: 0.0,
  speed: 0.0 
}

Populating windVane data is enabled by including an <anemometer> element in the plugin definition. The element should contain the scoped name of an anemometer sensor. For example:

<plugin name="ArduPilotPlugin"
  filename="ArduPilotPlugin">
  <fdm_addr>127.0.0.1</fdm_addr>
  <fdm_port_in>9002</fdm_port_in>
  <connectionTimeoutMaxCount>5</connectionTimeoutMaxCount>
  <lock_step>1</lock_step>
  <modelXYZToAirplaneXForwardZDown>0 0 0 3.141593 0 0</modelXYZToAirplaneXForwardZDown>
  <gazeboXYZToNED>0 0 0 3.141593 0 0</gazeboXYZToNED>
  <imuName>imu_link::imu_sensor</imuName>
  <anemometer>anemometer_link::anemometer</anemometer>
</plugin>

where the link is specified as:

<link name='anemometer_link'>
  <inertial>
    <pose>0 0 0 0 0 0</pose>
    <mass>0.15</mass>
    <inertia>
      <ixx>0.00001</ixx>
      <ixy>0</ixy>
      <ixz>0</ixz>
      <iyy>0.00002</iyy>
      <iyz>0</iyz>
      <izz>0.00002</izz>
    </inertia>
  </inertial>
  <sensor name="anemometer" type="custom" gz:type="anemometer">
    <always_on>1</always_on>
    <update_rate>30</update_rate>
    <gz:anemometer>
      <noise type="gaussian">
        <mean>0.2</mean>
        <stddev>0.1</stddev>
      </noise>
    </gz:anemometer>
  </sensor>
</link>

The anemometer is a third party Gazebo custom sensor. The only requirement for the ArduPilot plugin is that the sensor publishes a msg::Vector3d to the sensor topic:

/world/<world_name>/model/<model_name>/link/<link_name>/sensor/<sensor_name>/anemometer

The sensor system is enabled by including a system plugin associated with the <world> element. For example:

<plugin filename="asv_sim2-anemometer-system"
    name="gz::sim::systems::Anemometer">
</plugin>

loads the system from the library asv_sim. Other implementations of an anemometer sensor may be loaded by substituting the corresponding library name and alias.

Testing

Ensure tests/worlds is added to GZ_SIM_RESOURCE_PATH

Gazebo

gz sim -v4 -r test_anemometer.sdf

SITL

sim_vehicle.py -D -v Rover -f JSON -/-console -/-map
MANUAL> param set WNDVN_TYPE 11
MANUAL> param set WNDVN_SPEED_TYPE 11
MANUAL> param set WNDVN_SPEED_OFS 0
MANUAL> module load sail

Figure: anemometer pointing north.

anemometer_north

Figure: anemometer pointing east.

anemometer_east

Figure: anemometer pointing south.

anemometer_south

Figure: anemometer pointing west.

anemometer_west