diff --git a/config/unreal_simulator.yaml b/config/unreal_simulator.yaml index 4c09b33..ffb27dc 100644 --- a/config/unreal_simulator.yaml +++ b/config/unreal_simulator.yaml @@ -10,6 +10,21 @@ dynamic_rtf: true # TODO describe collisions: true +# 0 - LOW +# 1 - MEDIUM +# 2 - HIGH +# 4 - EPIC +# 5 - CINEMATIC +ueds_graphics_settings_enum: 0 + +# 0 - VALLEY, +# 1 - FOREST, +# 2 - INFINITE_FOREST, +# 3 - WAREHOUSE, +# 4 - CAVE, +# 5 - ERDING_AIRBASE +ueds_world_level_name_enum: 2 + sensors: lidar: diff --git a/include/ueds_connector/game_mode_controller.h b/include/ueds_connector/game_mode_controller.h index 0e5a947..dc6d0f3 100644 --- a/include/ueds_connector/game_mode_controller.h +++ b/include/ueds_connector/game_mode_controller.h @@ -36,6 +36,8 @@ class GameModeController : public SocketClient { std::pair GetTime(); bool SetGraphicsSettings(const Serializable::GameMode::GraphicsSettingsEnum& graphicsSettings); + + bool SwitchWorldLevel(const Serializable::GameMode::WorldLevelEnum& worldLevelEnum); }; } // namespace ueds_connector diff --git a/include/ueds_connector/serialization/serializable_shared.h b/include/ueds_connector/serialization/serializable_shared.h index cd57c71..02a6ca7 100644 --- a/include/ueds_connector/serialization/serializable_shared.h +++ b/include/ueds_connector/serialization/serializable_shared.h @@ -1023,7 +1023,7 @@ namespace SetGraphicsSettings template void serialize(Archive& archive) { archive(cereal::base_class(this), graphicsSettings); - } + } }; struct Response : public Common::NetworkResponse @@ -1034,6 +1034,37 @@ namespace SetGraphicsSettings }// namespace SetGraphicsSettings +enum WorldLevelEnum : unsigned short +{ + VALLEY, + FOREST, + INFINITE_FOREST, + WAREHOUSE, + CAVE, + ERDING_AIRBASE +}; + +namespace SwitchWorldLevel +{ + struct Request : public Common::NetworkRequest + { + Request() : Common::NetworkRequest(MessageType::switch_world_level){}; + + WorldLevelEnum worldLevelEnum; + + template + void serialize(Archive& archive) { + archive(cereal::base_class(this), worldLevelEnum); + } + }; + + struct Response : public Common::NetworkResponse + { + Response() : Common::NetworkResponse(static_cast(MessageType::switch_world_level)){}; + explicit Response(bool _status) : Common::NetworkResponse(MessageType::switch_world_level, _status){}; + }; +}// namespace SwitchWorldLevel + namespace GetFps { struct Request : public Common::NetworkRequest diff --git a/src/ueds_connector/game_mode_controller.cpp b/src/ueds_connector/game_mode_controller.cpp index 9d55955..50c0c74 100644 --- a/src/ueds_connector/game_mode_controller.cpp +++ b/src/ueds_connector/game_mode_controller.cpp @@ -105,6 +105,20 @@ bool GameModeController::SetGraphicsSettings(const Serializable::GameMode::Graph } //} +/* SwitchWorldLevel() {*/ +bool GameModeController::SwitchWorldLevel(const Serializable::GameMode::WorldLevelEnum& worldLevelEnum){ + + Serializable::GameMode::SwitchWorldLevel::Request request{}; + request.worldLevelEnum = static_cast(worldLevelEnum); + + Serializable::GameMode::SwitchWorldLevel::Response response{}; + const auto status = Request(request, response); + const auto success = status && response.status; + + return success; +} +//} + /* getFps() //{ */ std::pair GameModeController::GetFps() { diff --git a/src/unreal_simulator.cpp b/src/unreal_simulator.cpp index ba04604..193fbb4 100644 --- a/src/unreal_simulator.cpp +++ b/src/unreal_simulator.cpp @@ -242,6 +242,8 @@ class UnrealSimulator : public nodelet::Nodelet { std::mutex mutex_wall_time_offset_; double ueds_fps_ = 0; + int ueds_world_level_name_enum_ = 2U; + int ueds_graphics_settings_enum_ = 0U; std::vector last_rgb_ue_stamp_; std::vector last_rgb_seg_ue_stamp_; @@ -288,6 +290,9 @@ void UnrealSimulator::onInit() { param_loader.addYamlFileFromParam("config"); param_loader.addYamlFileFromParam("config_uavs"); + 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("simulation_rate", _simulation_rate_); param_loader.loadParam("realtime_factor", drs_params_.realtime_factor); param_loader.loadParam("dynamic_rtf", drs_params_.dynamic_rtf); @@ -406,7 +411,41 @@ void UnrealSimulator::onInit() { ros::shutdown(); } - Serializable::GameMode::GraphicsSettingsEnum graphicsSettings = Serializable::GameMode::GraphicsSettingsEnum::LOW; + // | --------------------- Set graphical settings and choose World Level --------------------- | + + Serializable::GameMode::WorldLevelEnum worldLevelEnum = Serializable::GameMode::WorldLevelEnum(ueds_world_level_name_enum_); + res = ueds_game_controller_->SwitchWorldLevel(worldLevelEnum); + if(res){ + ROS_INFO("[UnrealSimulator] World was switched succesfully."); + }else{ + ROS_ERROR("[UnrealSimulator] World was not switched succesfully."); + } + + res = ueds_game_controller_->Disconnect(); + if(res){ + ROS_INFO("[UnrealSimulator] ueds_game_controller_ was Disconnected succesfully."); + }else{ + ROS_ERROR("[UnrealSimulator] ueds_game_controller_ was not Disconnected succesfully."); + } + + ROS_WARN("SLEEP START"); + //ros::Duration(1.0).sleep(); + std::this_thread::sleep_for(std::chrono::seconds(1)); + ROS_WARN("SLEEP STOP"); + + //ueds_game_controller_ = std::make_unique(LOCALHOST, 8000); + while (true) { + bool connect_result = ueds_game_controller_->Connect(); + if (connect_result != 1) { + ROS_ERROR("[UnrealSimulator]: Error connecting to Unreal's game mode controller, connect_result was %d", connect_result); + } else { + break; + } + //ros::Duration(1.0).sleep(); + std::this_thread::sleep_for(std::chrono::seconds(1)); + } + + Serializable::GameMode::GraphicsSettingsEnum graphicsSettings = Serializable::GameMode::GraphicsSettingsEnum(ueds_graphics_settings_enum_); res = ueds_game_controller_->SetGraphicsSettings(graphicsSettings); if(res){ @@ -421,6 +460,7 @@ void UnrealSimulator::onInit() { const std::string uav_name = uav_names[i]; + ROS_INFO("[UnrealSimulator]: %s spawning .......", uav_name.c_str()); const auto [resSpawn, port] = ueds_game_controller_->SpawnDrone(); if (!resSpawn) { diff --git a/tmux/one_drone/session.yml b/tmux/one_drone/session.yml index 0e108a7..00f652f 100644 --- a/tmux/one_drone/session.yml +++ b/tmux/one_drone/session.yml @@ -5,7 +5,7 @@ socket_name: mrs attach: false tmux_options: -f /etc/ctu-mrs/tmux.conf # you can modify these -pre_window: export UAV_NAME=uav1; export RUN_TYPE=simulation; export UAV_TYPE=x500 #; source ~/workspace/devel/setup.bash +pre_window: export UAV_NAME=uav1; export RUN_TYPE=simulation; export UAV_TYPE=x500; source ~/workspace/devel/setup.bash startup_window: goto windows: - roscore: