From 27d8ec10e2ed1b65daa4532506c10af437d0d67a Mon Sep 17 00:00:00 2001 From: Jan Hrncir Date: Fri, 30 Aug 2024 15:18:41 +0200 Subject: [PATCH] added forest hilly levels --- config/unreal_simulator.yaml | 8 ++++++- include/ueds_connector/game_mode_controller.h | 2 ++ .../serialization/serializable_shared.h | 22 ++++++++++++++++++- src/ueds_connector/game_mode_controller.cpp | 18 ++++++++++++++- src/unreal_simulator.cpp | 15 +++++++++++-- 5 files changed, 60 insertions(+), 5 deletions(-) diff --git a/config/unreal_simulator.yaml b/config/unreal_simulator.yaml index a9f3ace..6e88397 100644 --- a/config/unreal_simulator.yaml +++ b/config/unreal_simulator.yaml @@ -27,10 +27,16 @@ ueds_graphics_settings_enum: 0 ueds_world_level_name_enum: 2 -# Only Forest Procedural Generation settings +############ Only Forest Procedural Generation settings ############ + # Choose cluttered difficulties from 1 [high] to 10 [low] ueds_forest_density: 6 +# Choose Hilly Level from 1 [totally flat] to 5 [the most hilly] +ueds_forest_hilly_level: 3 + +#################################################################### + sensors: lidar: diff --git a/include/ueds_connector/game_mode_controller.h b/include/ueds_connector/game_mode_controller.h index 4223d12..36fb336 100644 --- a/include/ueds_connector/game_mode_controller.h +++ b/include/ueds_connector/game_mode_controller.h @@ -40,6 +40,8 @@ class GameModeController : public SocketClient { bool SwitchWorldLevel(const Serializable::GameMode::WorldLevelEnum& worldLevelEnum); bool SetForestDensity(const int DensityLevel); + + bool SetForestHillyLevel(const int HillyLevel); }; } // namespace ueds_connector diff --git a/include/ueds_connector/serialization/serializable_shared.h b/include/ueds_connector/serialization/serializable_shared.h index 96fef94..2e5ef53 100644 --- a/include/ueds_connector/serialization/serializable_shared.h +++ b/include/ueds_connector/serialization/serializable_shared.h @@ -879,7 +879,8 @@ enum MessageType : unsigned short get_api_version = 9, set_graphics_settings = 10, switch_world_level = 11, - set_forest_density = 12 + set_forest_density = 12, + set_forest_hilly_level = 13 }; namespace GetDrones @@ -927,6 +928,25 @@ struct Response : public Common::NetworkResponse }; }; // namespace SetForestDensity +namespace SetForestHillyLevel +{ +struct Request : public Common::NetworkRequest +{ + Request() : Common::NetworkRequest(MessageType::set_forest_hilly_level){} + int Hilly_Level; + + template + void serialize(Archive& archive) { + archive(cereal::base_class(this), Hilly_Level); + } +}; +struct Response : public Common::NetworkResponse +{ + Response() : Common::NetworkResponse(static_cast(MessageType::set_forest_hilly_level)){}; + explicit Response(bool _status) : Common::NetworkResponse(MessageType::set_forest_hilly_level, _status){}; +}; +}; // namespace SetForestHilly + namespace SpawnDrone { diff --git a/src/ueds_connector/game_mode_controller.cpp b/src/ueds_connector/game_mode_controller.cpp index 26b2cdc..5080175 100644 --- a/src/ueds_connector/game_mode_controller.cpp +++ b/src/ueds_connector/game_mode_controller.cpp @@ -55,7 +55,7 @@ bool GameModeController::RemoveDrone(const int port) { //} -/* removeDrone() //{ */ +/* SetForestDensity() //{ */ bool GameModeController::SetForestDensity(const int DensityLevel) { @@ -71,6 +71,22 @@ bool GameModeController::SetForestDensity(const int DensityLevel) { //} +/* SetForestHillyLevel() //{ */ + +bool GameModeController::SetForestHillyLevel(const int HillyLevel) { + + Serializable::GameMode::SetForestHillyLevel::Request request{}; + request.Hilly_Level = HillyLevel; + + Serializable::GameMode::SetForestHillyLevel::Response response{}; + const auto status = Request(request, response); + const auto success = status && response.status; + + return success; +} + +//} + /* getCameraCaptureMode() //{ */ std::pair GameModeController::GetCameraCaptureMode() { diff --git a/src/unreal_simulator.cpp b/src/unreal_simulator.cpp index e867d39..c7c116d 100644 --- a/src/unreal_simulator.cpp +++ b/src/unreal_simulator.cpp @@ -244,7 +244,8 @@ class UnrealSimulator : public nodelet::Nodelet { double ueds_fps_ = 0; int ueds_world_level_name_enum_ = 2; int ueds_graphics_settings_enum_ = 0; - int ueds_forest_density_ = 5; + int ueds_forest_density_ = 5; + int ueds_forest_hilly_level_ = 3; std::vector last_rgb_ue_stamp_; std::vector last_rgb_seg_ue_stamp_; @@ -294,6 +295,7 @@ void UnrealSimulator::onInit() { param_loader.loadParam("ueds_graphics_settings_enum", ueds_graphics_settings_enum_); param_loader.loadParam("ueds_world_level_name_enum", ueds_world_level_name_enum_); param_loader.loadParam("ueds_forest_density", ueds_forest_density_); + param_loader.loadParam("ueds_forest_hilly_level", ueds_forest_hilly_level_); param_loader.loadParam("simulation_rate", _simulation_rate_); param_loader.loadParam("realtime_factor", drs_params_.realtime_factor); @@ -456,7 +458,7 @@ void UnrealSimulator::onInit() { ROS_ERROR("[UnrealSimulator]: Graphical Settings was not set succesfully to '%d'", graphicsSettings); } - // | --------------------- These graphical settings influence onle Forest Game World --------------------- | + // | --------------------- These graphical settings influence only Forest Game World --------------------- | res = ueds_game_controller_->SetForestDensity(ueds_forest_density_); if (res) { @@ -465,6 +467,15 @@ void UnrealSimulator::onInit() { ROS_ERROR("[UnrealSimulator]: Forest Density wasn't set succesfully to '%d'", ueds_forest_density_); } + res = ueds_game_controller_->SetForestHillyLevel(ueds_forest_hilly_level_); + if (res) { + ROS_INFO("[UnrealSimulator]: Forest Hilly Level was set succesfully to '%d'", ueds_forest_hilly_level_); + } else { + ROS_ERROR("[UnrealSimulator]: Forest Hilly Level wasn't set succesfully to '%d'", ueds_forest_hilly_level_); + } + + std::this_thread::sleep_for(std::chrono::seconds(1)); + // | --------------------- Spawn the UAVs --------------------- | for (size_t i = 0; i < uav_names.size(); i++) {