diff --git a/LibCarla/source/carla/client/World.cpp b/LibCarla/source/carla/client/World.cpp index cdda8a513..f6beac4e8 100644 --- a/LibCarla/source/carla/client/World.cpp +++ b/LibCarla/source/carla/client/World.cpp @@ -90,6 +90,15 @@ namespace client { void World::SetWeather(const rpc::WeatherParameters &weather) { _episode.Lock()->SetWeatherParameters(weather); } + + float World::GetIMUISensorGravity() const { + return _episode.Lock()->GetIMUISensorGravity(); + } + + void World::SetIMUISensorGravity(float NewIMUISensorGravity) { + _episode.Lock()->SetIMUISensorGravity(NewIMUISensorGravity); + } + WorldSnapshot World::GetSnapshot() const { return _episode.Lock()->GetWorldSnapshot(); diff --git a/LibCarla/source/carla/client/World.h b/LibCarla/source/carla/client/World.h index d8ba32e3e..0d2b2374c 100644 --- a/LibCarla/source/carla/client/World.h +++ b/LibCarla/source/carla/client/World.h @@ -94,6 +94,12 @@ namespace client { /// Change the weather in the simulation. void SetWeather(const rpc::WeatherParameters &weather); + /// Get Gravity value used for IMUI Sensor accelerometer calculation + float GetIMUISensorGravity() const; + + /// Set Gravity value used for IMUI Sensor accelerometer calculation + void SetIMUISensorGravity(float NewIMUISensorGravity); + /// Return a snapshot of the world at this moment. WorldSnapshot GetSnapshot() const; diff --git a/LibCarla/source/carla/client/detail/Client.cpp b/LibCarla/source/carla/client/detail/Client.cpp index edb148517..1ef96bb31 100644 --- a/LibCarla/source/carla/client/detail/Client.cpp +++ b/LibCarla/source/carla/client/detail/Client.cpp @@ -266,6 +266,14 @@ namespace detail { void Client::SetWeatherParameters(const rpc::WeatherParameters &weather) { _pimpl->AsyncCall("set_weather_parameters", weather); } + + float Client::GetIMUISensorGravity() { + return _pimpl->CallAndWait("get_imui_gravity"); + } + + void Client::SetIMUISensorGravity(float NewIMUISensorGravity) { + _pimpl->AsyncCall("set_imui_gravity", NewIMUISensorGravity); + } std::vector Client::GetActorsById( const std::vector &ids) { diff --git a/LibCarla/source/carla/client/detail/Client.h b/LibCarla/source/carla/client/detail/Client.h index 0eff68b6e..c609e9377 100644 --- a/LibCarla/source/carla/client/detail/Client.h +++ b/LibCarla/source/carla/client/detail/Client.h @@ -148,6 +148,10 @@ namespace detail { rpc::WeatherParameters GetWeatherParameters(); void SetWeatherParameters(const rpc::WeatherParameters &weather); + + float GetIMUISensorGravity(); + + void SetIMUISensorGravity( float NewIMUISensorGravity ); std::vector GetActorsById(const std::vector &ids); diff --git a/LibCarla/source/carla/client/detail/Simulator.h b/LibCarla/source/carla/client/detail/Simulator.h index 5f8a2ec06..e4c2bcb7b 100644 --- a/LibCarla/source/carla/client/detail/Simulator.h +++ b/LibCarla/source/carla/client/detail/Simulator.h @@ -250,7 +250,7 @@ namespace detail { } uint64_t SetEpisodeSettings(const rpc::EpisodeSettings &settings); - + rpc::WeatherParameters GetWeatherParameters() { return _client.GetWeatherParameters(); } @@ -259,6 +259,14 @@ namespace detail { _client.SetWeatherParameters(weather); } + float GetIMUISensorGravity() { + return _client.GetIMUISensorGravity(); + } + + void SetIMUISensorGravity(float NewIMUISensorGravity) { + _client.SetIMUISensorGravity(NewIMUISensorGravity); + } + rpc::VehiclePhysicsControl GetVehiclePhysicsControl(const Vehicle &vehicle) const { return _client.GetVehiclePhysicsControl(vehicle.GetId()); } diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.h index d0d6bc084..4b6ea68d4 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.h @@ -111,7 +111,11 @@ public: const carla::rpc::MaterialParameter& TextureParam); TArray GetNamesOfAllActors(); - + + // Gravitational acceleration. Default is earth one, which is approximately 9.81 m/s^2 + UPROPERTY(BlueprintReadOnly, EditAnywhere, Category="Sensor Gravity") + float IMUISensorGravity = 9.81f; + protected: void InitGame(const FString &MapName, const FString &Options, FString &ErrorMessage) override; @@ -176,8 +180,9 @@ private: UPROPERTY() ATrafficLightManager* TrafficLightManager = nullptr; + UPROPERTY() ALargeMapManager* LMManager = nullptr; - + FDelegateHandle OnEpisodeSettingsChangeHandle; boost::optional Map; diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/InertialMeasurementUnit.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/InertialMeasurementUnit.cpp index a2f4838d9..bffecb8d4 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/InertialMeasurementUnit.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/InertialMeasurementUnit.cpp @@ -104,8 +104,8 @@ carla::geom::Vector3D AInertialMeasurementUnit::ComputeAccelerometer( { // Used to convert from UE4's cm to meters constexpr float TO_METERS = 1e-2; - // Earth's gravitational acceleration is approximately 9.81 m/s^2 - constexpr float GRAVITY = 9.81f; + // Gravity set by gamemode + const float GRAVITY = UCarlaStatics::GetGameMode(GetWorld())->IMUISensorGravity; // 2nd derivative of the polynomic (quadratic) interpolation // using the point in current time and two previous steps: diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp index 7d06f0f81..a579771ae 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp @@ -664,6 +664,31 @@ void FCarlaServer::FPimpl::BindActions() Weather->ApplyWeather(weather); return R::Success(); }; + + // -- IMUI Gravity --------------------------------------------------------- + + BIND_SYNC(get_imui_gravity) << [this]() -> R + { + REQUIRE_CARLA_EPISODE(); + ACarlaGameModeBase* GameMode = UCarlaStatics::GetGameMode(Episode->GetWorld()); + if (GameMode == nullptr) + { + RESPOND_ERROR("get_imui_gravity error: unable to get carla gamemode"); + } + return GameMode->IMUISensorGravity; + }; + + BIND_SYNC(set_imui_gravity) << [this](float newimuigravity) -> R + { + REQUIRE_CARLA_EPISODE(); + ACarlaGameModeBase* GameMode = UCarlaStatics::GetGameMode(Episode->GetWorld()); + if (GameMode == nullptr) + { + RESPOND_ERROR("get_imui_gravity error: unable to get carla gamemode"); + } + GameMode->IMUISensorGravity = newimuigravity; + return R::Success(); + }; // ~~ Actor operations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~