srmainwaring / asv_sim

This package contains plugins and models for the simulation of surface vessels in Gazebo.
GNU General Public License v3.0
14 stars 5 forks source link

Wind Control: add wind system plugin #19

Closed srmainwaring closed 1 year ago

srmainwaring commented 1 year ago

Add a system plugin to set the global wind velocity.

Details

Add a world system plugin that subscribes to a wind topic accepting a msgs::Vector3d representing the true wind velocity. The plugin is specified as:

<plugin filename="asv_sim2-wind-system"
    name="gz::sim::systems::Wind">
    <topic>/wind</topic>
</plugin>

If the <topic> element is not provided the plugin generates the default topic:

/world/<world_name>/wind

To update the wind publish to the topic, for example:

gz topic -t "/wind" -m gz.msgs.Vector3d -p "x: -10"

will set the wind to be 10 m/s from the east (recall Gazebo's world frame is ENU).

Testing

Run the example world:

gz sim -v4 -r anemometer.sdf

Check the anemometer:

gz topic -e -t /anemometer -n 1
header {
  stamp {
    sec: 15
    nsec: 602000000
  }
  data {
    key: "frame_id"
    value: "anemometer::base_link::anemometer"
  }
  data {
    key: "seq"
    value: "15601"
  }
}
x: -9.9999999999994671
y: -3.2679489692100105e-06
z: -5.5125523286750351e-13

Change the wind:

gz topic -t "/wind" -m gz.msgs.Vector3d -p "x: -10"

Console message:

[Dbg] [Wind.cc:205] Wind: -10 0 0

Check the anemometer:

gz topic -e -t /anemometer -n 1
header {
  stamp {
    sec: 195
    nsec: 535000000
  }
  data {
    key: "frame_id"
    value: "anemometer::base_link::anemometer"
  }
  data {
    key: "seq"
    value: "195534"
  }
}
x: -3.2679489692100105e-06
y: 9.9999999999994671
z: -5.5125522202548536e-13

The anemometer is facing north, and sees the wind shift from the north (body frame -x) to the east (body frame +y).