Skip to content

Commit

Permalink
protect against bad settings file (microsoft#485), other minor updates(
Browse files Browse the repository at this point in the history
  • Loading branch information
sytelus committed Sep 29, 2017
1 parent 550e76d commit e4f3829
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Our goal is to develop AirSim as a platform for AI research to experiment with d
* We now have the [car model](docs/using_car.md).
* New built-in flight controller called [simple_flight](simple_flight.md) that "just works" without any additional setup. It is also now *default*.
* AirSim now also generates [depth as well as disparity impages](image_apis.md) that is in camera plan.
* We also have official Linux build now! If you have been using AirSim with PX4, you might want to read the [release notes](release_notes.md).
* We also have official Linux build now! If you have been using AirSim with PX4, you might want to read the [release notes](docs/release_notes.md).
* No need to build the code. Just download [our binaries](https://github.com/Microsoft/AirSim/releases) and you are good to go!

## How to Get It
Expand Down
4 changes: 2 additions & 2 deletions Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ void ASimHUD::initializeSettings()
Settings& settings = Settings::loadJSonString("{}");
//write some settings in new file otherwise the string "null" is written if all settigs are empty
settings.setString("SeeDocsAt", "https://github.com/Microsoft/AirSim/blob/master/docs/settings.md");
settings.setDouble("SettingdVersion", 1.0);
settings.setDouble("SettingsVersion", 1.0);

if (!file_found) {
std::string json_content;
Expand All @@ -286,7 +286,7 @@ void ASimHUD::initializeSettings()
#ifdef _WIN32
json_content = settings.saveJSonString();
#else
json_content = "{ \"SettingdVersion\": 1, \"SeeDocsAt\": \"https://github.com/Microsoft/AirSim/blob/master/docs/settings.md\"}";
json_content = "{ \"SettingsVersion\": 1, \"SeeDocsAt\": \"https://github.com/Microsoft/AirSim/blob/master/docs/settings.md\"}";
#endif
json_fstring = FString(json_content.c_str());
FFileHelper::SaveStringToFile(json_fstring, *settings_filename);
Expand Down
27 changes: 23 additions & 4 deletions Unreal/Plugins/AirSim/Source/SimMode/SimModeBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ void ASimModeBase::BeginPlay()

UAirBlueprintLib::LogMessage(TEXT("Press F1 to see help"), TEXT(""), LogDebugLevel::Informational);

readSettings();
try {
readSettings();
}
catch (std::exception& ex) {
UAirBlueprintLib::LogMessageString("Error occured while reading the Settings: ", ex.what(), LogDebugLevel::Failure);
}
}

void ASimModeBase::setStencilIDs()
Expand Down Expand Up @@ -51,19 +56,33 @@ void ASimModeBase::EndPlay(const EEndPlayReason::Type EndPlayReason)

void ASimModeBase::readSettings()
{
//set defaults in case exception occurs
is_record_ui_visible = false;
initial_view_mode = ECameraDirectorMode::CAMERA_DIRECTOR_MODE_FLY_WITH_ME;
enable_rpc = false;
api_server_address = "";
default_vehicle_config = "";
physics_engine_name = "";
usage_scenario = "";
enable_collision_passthrough = false;
clock_type = "";


typedef msr::airlib::Settings Settings;

Settings& settings = Settings::singleton();

settings_version_actual = settings.getFloat("SettingdVersion", 0);
//we had spelling mistake so we are currently supporting SettingsVersion or SettingdVersion :(
settings_version_actual = settings.getFloat("SettingsVersion", settings.getFloat("SettingdVersion", 0));

if (settings_version_actual < settings_version_minimum) {
if ((settings.size() == 1 &&
((settings.getString("SeeDocsAt", "") != "") || settings.getString("see_docs_at", "") != ""))
|| (settings.size() == 0)) {
//no warnings because we have default settings
}
else {
UAirBlueprintLib::LogMessageString("Your settings file is of old version and possibly not compatible!","", LogDebugLevel::Failure);
UAirBlueprintLib::LogMessageString("Your settings file does not have SettingsVersion element."," This probably means you have old format settings file.", LogDebugLevel::Failure);
UAirBlueprintLib::LogMessageString("Please look at new settings and update your settings.json: ","https://git.io/v9mYY", LogDebugLevel::Failure);
}
}
Expand Down Expand Up @@ -104,7 +123,7 @@ void ASimModeBase::readSettings()
initial_view_mode = ECameraDirectorMode::CAMERA_DIRECTOR_MODE_GROUND_OBSERVER;
else if (view_mode_string == "SpringArmChase")
initial_view_mode = ECameraDirectorMode::CAMERA_DIRECTOR_MODE_SPRINGARM_CHASE;
else
else
UAirBlueprintLib::LogMessage("ViewMode setting is not recognized: ", view_mode_string.c_str(), LogDebugLevel::Failure);

physics_engine_name = settings.getString("PhysicsEngineName", "");
Expand Down
10 changes: 5 additions & 5 deletions docs/apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ First make sure you have below in [settings.json](settings.md). This is because

```
{
"SettingdVersion": 1.0,
"SettingsVersion": 1.0,
"SimMode": "Car"
}
```
Expand All @@ -63,12 +63,12 @@ int main()
controls.throttle = 1;
client.setCarControls(controls);
std::cout << "Press Enter to activate handbreak" << std::endl; std::cin.get();
controls.handbreak = true;
std::cout << "Press Enter to activate handbrake" << std::endl; std::cin.get();
controls.handbrake = true;
client.setCarControls(controls);
std::cout << "Press Enter to take turn and drive backward" << std::endl; std::cin.get();
controls.handbreak = false;
controls.handbrake = false;
controls.throttle = -1;
controls.steering = 1;
client.setCarControls(controls);
Expand All @@ -91,7 +91,7 @@ More on [image APIs and Computer Vision mode](image_apis.md).
### APIs for Car
Car has followings APIs available:

* `setCarControls`: This allows you to set throttle, steering, handbreak and auto or manual gear.
* `setCarControls`: This allows you to set throttle, steering, handbrake and auto or manual gear.
* `getCarState`: This retrieves the state information including speed, current gear, velocity vector, position and orientation.
* [Image APIs](image_apis.md).

Expand Down
2 changes: 1 addition & 1 deletion docs/image_apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ To active this mode, edit [settings.json](settings.json) that you can find in yo

```
{
"SettingdVersion": 1.0,
"SettingsVersion": 1.0,
"UsageScenario": "ComputerVision"
}
```
Expand Down
2 changes: 1 addition & 1 deletion docs/px4_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ For this you will need one of the supported device listed above. For manual flig
8. In [AirSim settings](settings.md) file, specify PX4 for your vehicle config like this:
```
{
"SettingdVersion": 1.0,
"SettingsVersion": 1.0,
"DefaultVehicleConfig": "Pixhawk"
}
```
Expand Down
4 changes: 2 additions & 2 deletions docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The default is to use multirotor. To use car simple set `"SimMode": "Car"` like

```
{
"SettingdVersion": 1.0,
"SettingsVersion": 1.0,
"SimMode": "Car"
}
```
Expand All @@ -21,7 +21,7 @@ To choose multirotor, set `"SimMode": ""`.
## Available Settings and Their Defaults
Below are complete list of settings available along with their default values. If any of the settings is missing from json file, then below default value is assumed. Please note that if setting has default value then its actual value may be chosen based on other settings. For example, ViewMode setting will have value "FlyWithMe" for drones and "SpringArmChase" for cars.

**WARNING:** Do not copy below in your settings.json. We stronly recommand leaving out any settings that you want to have default values from settings.json. Only copy settings that you want to *change* from default.
**WARNING:** Do not copy paste all of below in your settings.json. We stronly recommand leaving out any settings that you want to have default values from settings.json. Only copy settings that you want to *change* from default. Only required element is `"SettingsVersion": 1.0`.

````
{
Expand Down
4 changes: 2 additions & 2 deletions docs/using_car.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ By default vehicle type used in AirSim is multirotor. If you want to use car ins

```
{
"SettingdVersion": 1.0,
"SettingsVersion": 1.0,
"SimMode": "Car"
}
```

Now when you restart AirSim, you should see the car spawned automatically.

## Manual Driving
Please use the keyboard arrow keys to drive manually. Spacebar for the handbreak. In manual drive mode, gears are set in "auto".
Please use the keyboard arrow keys to drive manually. Spacebar for the handbrake. In manual drive mode, gears are set in "auto".

## Using APIs
You can control the car, get state and images by calling APIs in variety of client languages including C++ and Python. Please see [APIs doc](apis.md) for more details.
Expand Down

0 comments on commit e4f3829

Please sign in to comment.