Skip to content

Commit

Permalink
Added weather API, updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sytelus committed Nov 29, 2018
1 parent 8bfbf35 commit b1260c2
Show file tree
Hide file tree
Showing 15 changed files with 169 additions and 11 deletions.
3 changes: 2 additions & 1 deletion AirLib/include/api/RpcLibAdapatorsBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "physics/Environment.hpp"
#include "common/ImageCaptureBase.hpp"
#include "safety/SafetyEval.hpp"
#include "api/WorldSimApiBase.hpp"

#include "common/common_utils/WindowsApisCommonPre.hpp"
#include "rpc/msgpack.hpp"
Expand Down Expand Up @@ -506,6 +507,6 @@ class RpcLibAdapatorsBase {
MSGPACK_ADD_ENUM(msr::airlib::SafetyEval::SafetyViolationType_);
MSGPACK_ADD_ENUM(msr::airlib::SafetyEval::ObsAvoidanceStrategy);
MSGPACK_ADD_ENUM(msr::airlib::ImageCaptureBase::ImageType);

MSGPACK_ADD_ENUM(msr::airlib::WorldSimApiBase::WeatherParameter);

#endif
4 changes: 4 additions & 0 deletions AirLib/include/api/RpcLibClientBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "common/ImageCaptureBase.hpp"
#include "physics/Kinematics.hpp"
#include "physics/Environment.hpp"
#include "api/WorldSimApiBase.hpp"

namespace msr { namespace airlib {

Expand Down Expand Up @@ -39,6 +40,9 @@ class RpcLibClientBase {
void simSetTimeOfDay(bool is_enabled, const string& start_datetime = "", bool is_start_datetime_dst = false,
float celestial_clock_speed = 1, float update_interval_secs = 60, bool move_sun = true);

void simEnableWeather(bool enable);
void simSetWeatherParameter(WorldSimApiBase::WeatherParameter param, float val);

Pose simGetObjectPose(const std::string& object_name) const;
bool simSetObjectPose(const std::string& object_name, const Pose& pose, bool teleport = true);

Expand Down
15 changes: 15 additions & 0 deletions AirLib/include/api/WorldSimApiBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ namespace msr { namespace airlib {

class WorldSimApiBase {
public:
enum class WeatherParameter {
Rain = 0,
Roadwetness = 1,
Snow = 2,
RoadSnow = 3,
MapleLeaf = 4,
RoadLeaf = 5,
Dust = 6,
Fog = 7,
Enabled = 8
};

virtual ~WorldSimApiBase() = default;

virtual bool isPaused() const = 0;
Expand All @@ -21,6 +33,9 @@ class WorldSimApiBase {
virtual void setTimeOfDay(bool is_enabled, const std::string& start_datetime, bool is_start_datetime_dst,
float celestial_clock_speed, float update_interval_secs, bool move_sun) = 0;

virtual void enableWeather(bool enable) = 0;
virtual void setWeatherParameter(WeatherParameter param, float val) = 0;

virtual bool setSegmentationObjectID(const std::string& mesh_name, int object_id, bool is_name_regex = false) = 0;
virtual int getSegmentationObjectID(const std::string& mesh_name) const = 0;

Expand Down
9 changes: 9 additions & 0 deletions AirLib/src/api/RpcLibClientBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,15 @@ void RpcLibClientBase::simContinueForTime(double seconds)
pimpl_->client.call("simContinueForTime", seconds);
}

void RpcLibClientBase::simEnableWeather(bool enable)
{
pimpl_->client.call("simEnableWeather", enable);
}
void RpcLibClientBase::simSetWeatherParameter(WorldSimApiBase::WeatherParameter param, float val)
{
pimpl_->client.call("simSetWeatherParameter", param, val);
}

void RpcLibClientBase::simSetTimeOfDay(bool is_enabled, const string& start_datetime, bool is_start_datetime_dst,
float celestial_clock_speed, float update_interval_secs, bool move_sun)
{
Expand Down
7 changes: 7 additions & 0 deletions AirLib/src/api/RpcLibServerBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ RpcLibServerBase::RpcLibServerBase(ApiProvider* api_provider, const std::string&
celestial_clock_speed, update_interval_secs, move_sun);
});

pimpl_->server.bind("simEnableWeather", [&](bool enable) -> void {
getWorldSimApi()->enableWeather(enable);
});
pimpl_->server.bind("simSetWeatherParameter", [&](WorldSimApiBase::WeatherParameter param, float val) -> void {
getWorldSimApi()->setWeatherParameter(param, val);
});

pimpl_->server.bind("enableApiControl", [&](bool is_enabled, const std::string& vehicle_name) -> void {
getVehicleApi(vehicle_name)->enableApiControl(is_enabled);
});
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Below is summarized list of important changes. This does not include minor/less important changes or bug fixes or documentation update. This list updated every few months. For complete detailed changes, please review [commit history](https://github.com/Microsoft/AirSim/commits/master).

### November, 2018
* Added Weather Effects and [APIs](docs/apis.md#weather-apis)
* Added [Time of Day API](docs/apis.md#time-of-day-api)
* An experimental integration of [AirSim on Unity](https://github.com/Microsoft/AirSim/tree/master/Unity) is now available. Learn more in [Unity blog post](https://blogs.unity3d.com/2018/11/14/airsim-on-unity-experiment-with-autonomous-vehicle-simulation).
* [New environments](https://github.com/Microsoft/AirSim/releases/tag/v1.2.1): Forest, Plains (windmill farm), TalkingHeads (human head simulation), TrapCam (animal detection via camera)
* Highly efficient [NoDisplay view mode](https://github.com/Microsoft/AirSim/blob/master/docs/settings.md#viewmode) to turn off main screen rendering so you can capture images at high rate
Expand Down
6 changes: 6 additions & 0 deletions PythonClient/airsim/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ def confirmConnection(self):
def simSetTimeOfDay(self, is_enabled, start_datetime = "", is_start_datetime_dst = False, celestial_clock_speed = 1, update_interval_secs = 60, move_sun = True):
return self.client.call('simSetTimeOfDay', is_enabled, start_datetime, is_start_datetime_dst, celestial_clock_speed, update_interval_secs, move_sun)

# weather
def simEnableWeather(self, enable):
return self.client.call('simEnableWeather', enable)
def simSetWeatherParameter(self, param, val):
return self.client.call('simSetWeatherParameter', param, val)

# camera control
# simGetImage returns compressed png in array of bytes
# image_type uses one of the ImageType members
Expand Down
11 changes: 11 additions & 0 deletions PythonClient/airsim/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ class LandedState:
Landed = 0
Flying = 1

class WeatherParameter:
Rain = 0
Roadwetness = 1
Snow = 2
RoadSnow = 3
MapleLeaf = 4
RoadLeaf = 5
Dust = 6
Fog = 7
Enabled = 8

class Vector3r(MsgpackMixin):
x_val = 0.0
y_val = 0.0
Expand Down
34 changes: 34 additions & 0 deletions PythonClient/computer_vision/weather.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import setup_path
import airsim


client = airsim.VehicleClient()
client.confirmConnection()

client.simEnableWeather(True)

airsim.wait_key('Press any key to enable rain at 25%')
client.simSetWeatherParameter(airsim.WeatherParameter.Rain, 0.25);

airsim.wait_key('Press any key to enable rain at 75%')
client.simSetWeatherParameter(airsim.WeatherParameter.Rain, 0.75);

airsim.wait_key('Press any key to enable snow at 50%')
client.simSetWeatherParameter(airsim.WeatherParameter.Snow, 0.50);

airsim.wait_key('Press any key to enable maple leaves at 50%')
client.simSetWeatherParameter(airsim.WeatherParameter.MapleLeaf, 0.50);

airsim.wait_key('Press any key to set all effects to 0%')
client.simSetWeatherParameter(airsim.WeatherParameter.Rain, 0.0);
client.simSetWeatherParameter(airsim.WeatherParameter.Snow, 0.0);
client.simSetWeatherParameter(airsim.WeatherParameter.MapleLeaf, 0.0);

airsim.wait_key('Press any key to enable dust at 50%')
client.simSetWeatherParameter(airsim.WeatherParameter.Dust, 0.50);

airsim.wait_key('Press any key to enable fog at 50%')
client.simSetWeatherParameter(airsim.WeatherParameter.Fog, 0.50);

airsim.wait_key('Press any key to disable all weather effects')
client.simEnableWeather(False)
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ Cars in AirSim

## What's New

* Added Weather Effects and [APIs](docs/apis.md#weather-apis)
* Added [Time of Day API](docs/apis.md#time-of-day-api)
* An experimental integration of [AirSim on Unity](https://github.com/Microsoft/AirSim/tree/master/Unity) is now available. Learn more in [Unity blog post](https://blogs.unity3d.com/2018/11/14/airsim-on-unity-experiment-with-autonomous-vehicle-simulation).
* [New environments](https://github.com/Microsoft/AirSim/releases/tag/v1.2.1): Forest, Plains (windmill farm), TalkingHeads (human head simulation), TrapCam (animal detection via camera)
* Highly efficient [NoDisplay view mode](https://microsoft.github.io/AirSim/docs/settings#viewmode) to turn off main screen rendering so you can capture images at high rate
* [Lidar Sensor](https://microsoft.github.io/AirSim/docs/lidar)
* Case Study: [Formula Student Technion Driverless](https://github.com/Microsoft/AirSim/wiki/technion)
* [Multi-Vehicle Capability](https://microsoft.github.io/AirSim/docs/multi_vehicle)
* [ROS publisher](https://github.com/Microsoft/AirSim/pull/1135)
* [Arducopter Solo Support](https://github.com/Microsoft/AirSim/pull/1387)
* AirSim 1.2 is released! **This version has breaking changes in APIs and settings.json.** Please see the [API Upgrade](https://microsoft.github.io/AirSim/docs/upgrade_apis) and [Settings Upgrade](https://microsoft.github.io/AirSim/docs/upgrade_settings) docs.
* We have upgraded to Unreal Engine 4.18 and Visual Studio 2017 (see [upgrade instructions](https://microsoft.github.io/AirSim/docs/unreal_upgrade))

For complete list of changes, view our [Changelog](CHANGELOG.md)

Expand Down Expand Up @@ -81,6 +80,12 @@ Yet another way to use AirSim is the so-called "Computer Vision" mode. In this m

[More details](docs/image_apis.md)

### Weather Effects

Press F10 to see various options available for weather effects. You can also control the weather using [APIs](https://microsoft.github.io/AirSim/docs/apis.md#weather-apis). Press F1 to see other options available.

![record screenshot](docs/images/weather_menu.png)

## Tutorials

- [Video - Setting up AirSim with Pixhawk Tutorial](https://youtu.be/1oY8Qu5maQQ) by Chris Lovett
Expand Down
17 changes: 17 additions & 0 deletions Unreal/Plugins/AirSim/Source/WorldSimApi.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "WorldSimApi.h"
#include "AirBlueprintLib.h"
#include "common/common_utils/Utils.hpp"
#include "Weather/WeatherLib.h"

WorldSimApi::WorldSimApi(ASimModeBase* simmode)
: simmode_(simmode)
Expand Down Expand Up @@ -93,6 +94,21 @@ bool WorldSimApi::setObjectPose(const std::string& object_name, const WorldSimAp
return result;
}

void WorldSimApi::enableWeather(bool enable)
{
UWeatherLib::setWeatherEnabled(simmode_->GetWorld(), enable);
}
void WorldSimApi::setWeatherParameter(WeatherParameter param, float val)
{
unsigned char param_n = static_cast<unsigned char>(msr::airlib::Utils::toNumeric<WeatherParameter>(param));
EWeatherParamScalar param_e = msr::airlib::Utils::toEnum<EWeatherParamScalar>(param_n);

UWeatherLib::setWeatherParamScalar(simmode_->GetWorld(), param_e, val);
}


//------------------------------------------------- Char APIs -----------------------------------------------------------/

void WorldSimApi::charSetFaceExpression(const std::string& expression_name, float value, const std::string& character_name)
{
AAirSimCharacter* character = getAirSimCharacter(character_name);
Expand Down Expand Up @@ -223,4 +239,5 @@ const AAirSimCharacter* WorldSimApi::getAirSimCharacter(const std::string& chara
{
return const_cast<WorldSimApi*>(this)->getAirSimCharacter(character_name);
}
//------------------------------------------------- Char APIs -----------------------------------------------------------/

3 changes: 3 additions & 0 deletions Unreal/Plugins/AirSim/Source/WorldSimApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class WorldSimApi : public msr::airlib::WorldSimApiBase {
virtual void setTimeOfDay(bool is_enabled, const std::string& start_datetime, bool is_start_datetime_dst,
float celestial_clock_speed, float update_interval_secs, bool move_sun);

virtual void enableWeather(bool enable);
virtual void setWeatherParameter(WeatherParameter param, float val);

virtual bool setSegmentationObjectID(const std::string& mesh_name, int object_id, bool is_name_regex = false) override;
virtual int getSegmentationObjectID(const std::string& mesh_name) const override;

Expand Down
54 changes: 48 additions & 6 deletions docs/apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,24 +123,66 @@ for response in responses:
* `simPrintLogMessage`: Prints the specified message in the simulator's window. If message_param is also supplied then its printed next to the message and in that case if this API is called with same message value but different message_param again then previous line is overwritten with new line (instead of API creating new line on display). For example, `simPrintLogMessage("Iteration: ", to_string(i))` keeps updating same line on display when API is called with different values of i. The valid values of severity parameter is 0 to 3 inclusive that corresponds to different colors.
* `simGetObjectPose`, `simSetObjectPose`: Gets and sets the pose of specified object in Unreal environment. Here the object means "actor" in Unreal terminology. They are searched by tag as well as name. Please note that the names shown in UE Editor are *auto-generated* in each run and are not permanent. So if you want to refer to actor by name, you must change its auto-generated name in UE Editor. Alternatively you can add a tag to actor which can be done by clicking on that actor in Unreal Editor and then going to [Tags property](https://answers.unrealengine.com/questions/543807/whats-the-difference-between-tag-and-tag.html), click "+" sign and add some string value. If multiple actors have same tag then the first match is returned. If no matches are found then NaN pose is returned. The returned pose is in NED coordinates in SI units with its origin at Player Start. For `simSetObjectPose`, the specified actor must have [Mobility](https://docs.unrealengine.com/en-us/Engine/Actors/Mobility) set to Movable or otherwise you will get undefined behavior. The `simSetObjectPose` has parameter `teleport` which means object is [moved through other objects](https://www.unrealengine.com/en-US/blog/moving-physical-objects) in its way and it returns true if move was successful


### Image / Computer Vision APIs
AirSim offers comprehensive images APIs to retrieve synchronized images from multiple cameras along with ground truth including depth, disparity, surface normals and vision. You can set the resolution, FOV, motion blur etc parameters in [settings.json](settings.md). There is also API for detecting collision state. See also [complete code](https://github.com/Microsoft/AirSim/tree/master/Examples/DataCollection/StereoImageGenerator.hpp) that generates specified number of stereo images and ground truth depth with normalization to camera plan, computation of disparity image and saving it to [pfm format](pfm.md).

More on [image APIs and Computer Vision mode](image_apis.md).

### Lidar APIs
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).

More on [lidar APIs and settings](lidar.md) and [sensor settings](sensors.md)

### Pause and Continue APIs
AirSim allows to pause and continue the simulation through `pause(is_paused)` API. To pause the simulation call `pause(True)` and to continue the simulation call `pause(False)`. You may have scenario, especially while using reinforcement learning, to run the simulation for specified amount of time and then automatically pause. While simulation is paused, you may then do some expensive computation, send a new command and then again run the simulation for specified amount of time. This can be achieved by API `continueForTime(seconds)`. This API runs the simulation for the specified number of seconds and then pauses the simulation. For example usage, please see [pause_continue_car.py](https://github.com/Microsoft/AirSim/tree/master/PythonClient//car/pause_continue_car.py) and [pause_continue_drone.py](https://github.com/Microsoft/AirSim/tree/master/PythonClient//multirotor/pause_continue_drone.py).


### Collision API
The collision information can be obtained using `simGetCollisionInfo` API. This call returns a struct that has information not only whether collision occurred but also collision position, surface normal, penetration depth and so on.

### Time of Day API
AirSim assumes there exist sky sphere of class `EngineSky/BP_Sky_Sphere` in your environment with [ADirectionalLight actor](https://github.com/Microsoft/AirSim/blob/master/Unreal/Plugins/AirSim/Source/SimMode/SimModeBase.cpp#L156). By default, the position of the sun in the scene doesn't move with time. You can use [settings](settings.md#timeofday) to set up latitude, longitude, date and time which AirSim uses to compute the position of sun in the scene.

You can also use following API call to set the sun position according to given date time:

```
simSetTimeOfDay(self, is_enabled, start_datetime = "", is_start_datetime_dst = False, celestial_clock_speed = 1, update_interval_secs = 60, move_sun = True)
```

The `is_enabled` parameter must be `True` to enable time of day effect. If it is `False` then sun position is reset to its original in the environment.

Other parameters are same as in [settings](settings.md#timeofday).

### Weather APIs
By default all weather effects are disabled. To enable weather effect, first call:

```
simEnableWeather(True)
```

Various weather effects can be enabled by using `simSetWeatherParameter` method which takes `WeatherParameter`, for example,

```
client.simSetWeatherParameter(airsim.WeatherParameter.Rain, 0.25);
```
The second parameter value is from 0 to 1. The first parameter provides following options:

```
class WeatherParameter:
Rain = 0
Roadwetness = 1
Snow = 2
RoadSnow = 3
MapleLeaf = 4
RoadLeaf = 5
Dust = 6
Fog = 7
```

Please note that `Roadwetness`, `RoadSnow` and `RoadLeaf` effects requires adding [materials](https://github.com/Microsoft/AirSim/tree/master/Unreal/Plugins/AirSim/Content/Weather/WeatherFX) to your scene.

Please see [example code](https://github.com/Microsoft/AirSim/blob/master/PythonClient/computer_vision/weather.py) for more details.

### Lidar APIs
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).

More on [lidar APIs and settings](lidar.md) and [sensor settings](sensors.md)

### Multiple Vehicles
AirSim supports multiple vehicles and control them through APIs. Please [Multiple Vehicles](multi_vehicle.md) doc.

Expand Down
Binary file added docs/images/weather_menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit b1260c2

Please sign in to comment.