Skip to content

Commit d1b4c6d

Browse files
committed
Add documentation, example script for setWind API
1 parent b15af94 commit d1b4c6d

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import setup_path
2+
import airsim
3+
import time
4+
5+
client = airsim.MultirotorClient()
6+
client.confirmConnection()
7+
client.enableApiControl(True)
8+
9+
client.armDisarm(True)
10+
11+
# Set wind to (20,0,0) in NED (forward direction)
12+
print("Setting wind to (20,0,0)")
13+
wind = airsim.Vector3r(20, 0, 0)
14+
client.simSetWind(wind)
15+
16+
# Takeoff or hover
17+
landed = client.getMultirotorState().landed_state
18+
if landed == airsim.LandedState.Landed:
19+
print("taking off...")
20+
client.takeoffAsync().join()
21+
else:
22+
print("already flying...")
23+
client.hoverAsync().join()
24+
25+
time.sleep(5)
26+
27+
# Set wind to (0,25,0) in NED (towards right)
28+
print("Setting wind to (0,25,0)")
29+
wind = airsim.Vector3r(0, 25, 0)
30+
client.simSetWind(wind)
31+
32+
time.sleep(5)
33+
34+
# Set wind to 0
35+
print("Resetting wind to (0,0,0)")
36+
wind = airsim.Vector3r(0, 0, 0)
37+
client.simSetWind(wind)

docs/apis.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,20 @@ This API works alongwith toggling Recording using R button, therefore if it's en
193193

194194
Note that this will only save the data as specfied in the settings. For full freedom in storing data such as certain sensor information, or in a different format or layout, use the other APIs to fetch the data and save as desired.
195195

196+
### Wind API
197+
198+
Wind can be changed during simulation using `simSetWind()`. Wind is specified in World frame, NED direction and m/s values
199+
200+
E.g. To set 20m/s wind in North (forward) direction -
201+
202+
```python
203+
# Set wind to (20,0,0) in NED (forward direction)
204+
wind = airsim.Vector3r(20, 0, 0)
205+
client.simSetWind(wind)
206+
```
207+
208+
Also see example script in [set_wind.py](https://github.com/Microsoft/AirSim/blob/master/PythonClient/multirotor/set_wind.py)
209+
196210
### Lidar APIs
197211
AirSim offers API to retrieve point cloud data from Lidar sensors on vehicles. You can set the number of channels, points per second, horizontal and vertical FOV, etc parameters in [settings.json](settings.md).
198212

docs/settings.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Below are complete list of settings available along with their default values. I
4545
"PhysicsEngineName": "",
4646
"SpeedUnitFactor": 1.0,
4747
"SpeedUnitLabel": "m/s",
48+
"Wind": { "X": 0, "Y": 0, "Z": 0 },
4849
"Recording": {
4950
"RecordOnMove": false,
5051
"RecordInterval": 0.05,
@@ -222,6 +223,10 @@ The `InitMethod` determines how object IDs are initialized at startup to generat
222223

223224
If `MeshNamingMethod` is "" or "OwnerName" then we use mesh's owner name to generate random hash as object IDs. If it is "StaticMeshName" then we use static mesh's name to generate random hash as object IDs. Note that it is not possible to tell individual instances of the same static mesh apart this way, but the names are often more intuitive.
224225

226+
## Wind Settings
227+
228+
This setting specifies the wind speed in World frame, in NED direction. Values are in m/s. By default, speed is 0, i.e. no wind.
229+
225230
## Camera Settings
226231
The `CameraDefaults` element at root level specifies defaults used for all cameras. These defaults can be overridden for individual camera in `Cameras` element inside `Vehicles` as described later.
227232

0 commit comments

Comments
 (0)