From 0f645ce9d825bb487f1211b4bf42893beff1c445 Mon Sep 17 00:00:00 2001 From: madratman Date: Sat, 2 May 2020 16:06:41 -0700 Subject: [PATCH] restore carapibase.hpp --- .../include/vehicles/car/api/CarApiBase.hpp | 241 +++++++++--------- 1 file changed, 122 insertions(+), 119 deletions(-) diff --git a/AirLib/include/vehicles/car/api/CarApiBase.hpp b/AirLib/include/vehicles/car/api/CarApiBase.hpp index 75ffa22bb8..1b20728b48 100644 --- a/AirLib/include/vehicles/car/api/CarApiBase.hpp +++ b/AirLib/include/vehicles/car/api/CarApiBase.hpp @@ -12,140 +12,143 @@ #include "sensors/SensorCollection.hpp" #include "sensors/SensorFactory.hpp" -namespace msr { - namespace airlib { - - class CarApiBase : public VehicleApiBase { - public: - struct CarControls { - float throttle = 0; /* 1 to -1 */ - float steering = 0; /* 1 to -1 */ - float brake = 0; /* 1 to -1 */ - bool handbrake = false; - bool is_manual_gear = false; - int manual_gear = 0; - bool gear_immediate = true; - - CarControls() - { - } - CarControls(float throttle_val, float steering_val, float brake_val, bool handbrake_val, - bool is_manual_gear_val, int manual_gear_val, bool gear_immediate_val) - : throttle(throttle_val), steering(steering_val), brake(brake_val), handbrake(handbrake_val), - is_manual_gear(is_manual_gear_val), manual_gear(manual_gear_val), gear_immediate(gear_immediate_val) - { - } - void set_throttle(float throttle_val, bool forward) - { - if (forward) { - is_manual_gear = false; - manual_gear = 0; - throttle = std::abs(throttle_val); - } - else { - is_manual_gear = false; - manual_gear = -1; - throttle = -std::abs(throttle_val); - } - } - }; - - struct CarState { - float speed; - int gear; - float rpm; - float maxrpm; - bool handbrake; - Kinematics::State kinematics_estimated; - uint64_t timestamp; - - CarState(float speed_val, int gear_val, float rpm_val, float maxrpm_val, bool handbrake_val, - const Kinematics::State& kinematics_estimated_val, uint64_t timestamp_val) - : speed(speed_val), gear(gear_val), rpm(rpm_val), maxrpm(maxrpm_val), handbrake(handbrake_val), - kinematics_estimated(kinematics_estimated_val), timestamp(timestamp_val) - { - } - }; - - public: - - // TODO: Temporary constructor for the Unity implementation which does not use the new Sensor Configuration Settings implementation. - //CarApiBase() {} - - CarApiBase(const AirSimSettings::VehicleSetting* vehicle_setting, - std::shared_ptr sensor_factory, - const Kinematics::State& state, const Environment& environment) - { - initialize(vehicle_setting, sensor_factory, state, environment); +namespace msr { namespace airlib { + +class CarApiBase : public VehicleApiBase { +public: + struct CarControls { + float throttle = 0; /* 1 to -1 */ + float steering = 0; /* 1 to -1 */ + float brake = 0; /* 1 to -1 */ + bool handbrake = false; + bool is_manual_gear = false; + int manual_gear = 0; + bool gear_immediate = true; + + CarControls() + { + } + CarControls(float throttle_val, float steering_val, float brake_val, bool handbrake_val, + bool is_manual_gear_val, int manual_gear_val, bool gear_immediate_val) + : throttle(throttle_val), steering(steering_val), brake(brake_val), handbrake(handbrake_val), + is_manual_gear(is_manual_gear_val), manual_gear(manual_gear_val), gear_immediate(gear_immediate_val) + { + } + void set_throttle(float throttle_val, bool forward) + { + if (forward) { + is_manual_gear = false; + manual_gear = 0; + throttle = std::abs(throttle_val); } - - virtual void update() override - { - VehicleApiBase::update(); - - getSensors().update(); + else { + is_manual_gear = false; + manual_gear = -1; + throttle = - std::abs(throttle_val); } + } + }; + + struct CarState { + float speed; + int gear; + float rpm; + float maxrpm; + bool handbrake; + Kinematics::State kinematics_estimated; + uint64_t timestamp; + + CarState() + { + } + + CarState(float speed_val, int gear_val, float rpm_val, float maxrpm_val, bool handbrake_val, + const Kinematics::State& kinematics_estimated_val, uint64_t timestamp_val) + : speed(speed_val), gear(gear_val), rpm(rpm_val), maxrpm(maxrpm_val), handbrake(handbrake_val), + kinematics_estimated(kinematics_estimated_val), timestamp(timestamp_val) + { + } + }; + +public: + + // TODO: Temporary constructor for the Unity implementation which does not use the new Sensor Configuration Settings implementation. + //CarApiBase() {} + + CarApiBase(const AirSimSettings::VehicleSetting* vehicle_setting, + std::shared_ptr sensor_factory, + const Kinematics::State& state, const Environment& environment) + { + initialize(vehicle_setting, sensor_factory, state, environment); + } - void reportState(StateReporter& reporter) override - { - getSensors().reportState(reporter); - } + virtual void update() override + { + VehicleApiBase::update(); - // sensor helpers - virtual const SensorCollection& getSensors() const override - { - return sensors_; - } - - SensorCollection& getSensors() - { - return sensors_; - } + getSensors().update(); + } - void initialize(const AirSimSettings::VehicleSetting* vehicle_setting, - std::shared_ptr sensor_factory, - const Kinematics::State& state, const Environment& environment) - { - sensor_factory_ = sensor_factory; + void reportState(StateReporter& reporter) override + { + getSensors().reportState(reporter); + } - sensor_storage_.clear(); - sensors_.clear(); + // sensor helpers + virtual const SensorCollection& getSensors() const override + { + return sensors_; + } - addSensorsFromSettings(vehicle_setting); + SensorCollection& getSensors() + { + return sensors_; + } - getSensors().initialize(&state, &environment); - } + void initialize(const AirSimSettings::VehicleSetting* vehicle_setting, + std::shared_ptr sensor_factory, + const Kinematics::State& state, const Environment& environment) + { + sensor_factory_ = sensor_factory; - void addSensorsFromSettings(const AirSimSettings::VehicleSetting* vehicle_setting) - { - // use sensors from vehicle settings; if empty list, use default sensors. - // note that the vehicle settings completely override the default sensor "list"; - // there is no piecemeal add/remove/update per sensor. - const std::map>& sensor_settings - = vehicle_setting->sensors.size() > 0 ? vehicle_setting->sensors : AirSimSettings::AirSimSettings::singleton().sensor_defaults; + sensor_storage_.clear(); + sensors_.clear(); + + addSensorsFromSettings(vehicle_setting); - sensor_factory_->createSensorsFromSettings(sensor_settings, sensors_, sensor_storage_); - } + getSensors().initialize(&state, &environment); + } - virtual void setCarControls(const CarControls& controls) = 0; - virtual CarState getCarState() const = 0; - virtual const CarApiBase::CarControls& getCarControls() const = 0; + void addSensorsFromSettings(const AirSimSettings::VehicleSetting* vehicle_setting) + { + // use sensors from vehicle settings; if empty list, use default sensors. + // note that the vehicle settings completely override the default sensor "list"; + // there is no piecemeal add/remove/update per sensor. + const std::map>& sensor_settings + = vehicle_setting->sensors.size() > 0 ? vehicle_setting->sensors : AirSimSettings::AirSimSettings::singleton().sensor_defaults; - virtual ~CarApiBase() = default; + sensor_factory_->createSensorsFromSettings(sensor_settings, sensors_, sensor_storage_); + } - std::shared_ptr sensor_factory_; - SensorCollection sensors_; //maintains sensor type indexed collection of sensors - vector> sensor_storage_; //RAII for created sensors + virtual void setCarControls(const CarControls& controls) = 0; + virtual void updateCarState(const CarState& state) = 0; + virtual const CarState& getCarState() const = 0; + virtual const CarControls& getCarControls() const = 0; - protected: - virtual void resetImplementation() override - { - //reset sensors last after their ground truth has been reset - getSensors().reset(); - } - }; + virtual ~CarApiBase() = default; + std::shared_ptr sensor_factory_; + SensorCollection sensors_; //maintains sensor type indexed collection of sensors + vector> sensor_storage_; //RAII for created sensors +protected: + virtual void resetImplementation() override + { + //reset sensors last after their ground truth has been reset + getSensors().reset(); } -} //namespace +}; + + +}} //namespace #endif \ No newline at end of file