From ca0615918dc95aff8ed214fcff23c6b545a2657f Mon Sep 17 00:00:00 2001 From: Rajat Singhal Date: Mon, 27 Jul 2020 01:53:38 +0530 Subject: [PATCH] Fix Recording when no vehicles are specified Also change all occurrences of simmode strings to fixed variables --- AirLib/include/common/AirSimSettings.hpp | 38 +++++++++++++++++------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/AirLib/include/common/AirSimSettings.hpp b/AirLib/include/common/AirSimSettings.hpp index 52fd87087b..386af4890d 100644 --- a/AirLib/include/common/AirSimSettings.hpp +++ b/AirLib/include/common/AirSimSettings.hpp @@ -35,6 +35,10 @@ struct AirSimSettings { static constexpr char const * kVehicleInertialFrame = "VehicleInertialFrame"; static constexpr char const * kSensorLocalFrame = "SensorLocalFrame"; + static constexpr char const * kSimModeTypeMultirotor = "Multirotor"; + static constexpr char const * kSimModeTypeCar = "Car"; + static constexpr char const * kSimModeTypeComputerVision = "ComputerVision"; + struct SubwindowSetting { int window_index; ImageType image_type; @@ -521,7 +525,7 @@ struct AirSimSettings { physics_engine_name = settings_json.getString("PhysicsEngineName", ""); if (physics_engine_name == "") { - if (simmode_name == "Multirotor") + if (simmode_name == kSimModeTypeMultirotor) physics_engine_name = "FastPhysicsEngine"; else physics_engine_name = "PhysX"; //this value is only informational for now @@ -538,9 +542,9 @@ struct AirSimSettings { std::string view_mode_string = settings_json.getString("ViewMode", ""); if (view_mode_string == "") { - if (simmode_name == "Multirotor") + if (simmode_name == kSimModeTypeMultirotor) view_mode_string = "FlyWithMe"; - else if (simmode_name == "ComputerVision") + else if (simmode_name == kSimModeTypeComputerVision) view_mode_string = "Fpv"; else view_mode_string = "SpringArmChase"; @@ -571,12 +575,24 @@ struct AirSimSettings { Settings rc_json; if (settings_json.getChild("RC", rc_json)) { rc_setting.remote_control_id = rc_json.getInt("RemoteControlID", - simmode_name == "Multirotor" ? 0 : -1); + simmode_name == kSimModeTypeMultirotor ? 0 : -1); rc_setting.allow_api_when_disconnected = rc_json.getBool("AllowAPIWhenDisconnected", rc_setting.allow_api_when_disconnected); } } + // Get name of the default vehicle created for the specfifc simmode + // Based on initializeVehicleSettings() (#L803) + static std::string getDefaultVehicleName(const std::string& simmode_name) + { + if (simmode_name == kSimModeTypeMultirotor) + return "SimpleFlight"; + else if (simmode_name == kSimModeTypeCar) + return "PhysXCar"; + else + return "ComputerVision"; + } + static std::string getCameraName(const Settings& settings_json) { return settings_json.getString("CameraName", @@ -611,13 +627,15 @@ struct AirSimSettings { for (size_t child_index = 0; child_index < req_cameras_settings.size(); ++child_index) { Settings req_camera_settings; + std::string default_vehicle_name = getDefaultVehicleName(simmode_name); + if (req_cameras_settings.getChild(child_index, req_camera_settings)) { std::string camera_name = getCameraName(req_camera_settings); ImageType image_type = Utils::toEnum( req_camera_settings.getInt("ImageType", 0)); bool compress = req_camera_settings.getBool("Compress", true); bool pixels_as_float = req_camera_settings.getBool("PixelsAsFloat", false); - std::string vehicle_name = req_camera_settings.getString("VehicleName", ""); + std::string vehicle_name = req_camera_settings.getString("VehicleName", default_vehicle_name); recording_setting.requests[vehicle_name].push_back(ImageCaptureBase::ImageRequest( camera_name, image_type, pixels_as_float, compress)); @@ -1105,7 +1123,7 @@ struct AirSimSettings { } if (std::isnan(camera_director.follow_distance)) { - if (simmode_name == "Car") + if (simmode_name == kSimModeTypeCar) camera_director.follow_distance = -8; else camera_director.follow_distance = -3; @@ -1115,7 +1133,7 @@ struct AirSimSettings { if (std::isnan(camera_director.position.y())) camera_director.position.y() = 0; if (std::isnan(camera_director.position.z())) { - if (simmode_name == "Car") + if (simmode_name == kSimModeTypeCar) camera_director.position.z() = -4; else camera_director.position.z() = -2; @@ -1131,7 +1149,7 @@ struct AirSimSettings { clock_type = "ScalableClock"; //override if multirotor simmode with simple_flight - if (simmode_name == "Multirotor") { + if (simmode_name == kSimModeTypeMultirotor) { //TODO: this won't work if simple_flight and PX4 is combined together! //for multirotors we select steppable fixed interval clock unless we have @@ -1301,13 +1319,13 @@ struct AirSimSettings { static void createDefaultSensorSettings(const std::string& simmode_name, std::map>& sensors) { - if (simmode_name == "Multirotor") { + if (simmode_name == kSimModeTypeMultirotor) { sensors["imu"] = createSensorSetting(SensorBase::SensorType::Imu, "imu", true); sensors["magnetometer"] = createSensorSetting(SensorBase::SensorType::Magnetometer, "magnetometer", true); sensors["gps"] = createSensorSetting(SensorBase::SensorType::Gps, "gps", true); sensors["barometer"] = createSensorSetting(SensorBase::SensorType::Barometer, "barometer", true); } - else if (simmode_name == "Car") { + else if (simmode_name == kSimModeTypeCar) { sensors["gps"] = createSensorSetting(SensorBase::SensorType::Gps, "gps", true); } else {