From 722ae28eaa13ffbab8ec7f123257956284c14551 Mon Sep 17 00:00:00 2001 From: sanatd33 Date: Sun, 10 Mar 2024 22:03:30 -0400 Subject: [PATCH 1/6] Removed thirds, added communication-based heuristic --- rj_msgs/CMakeLists.txt | 17 +- rj_msgs/msg/AgentRequest.msg | 11 +- rj_msgs/msg/AgentResponseVariant.msg | 6 +- rj_msgs/request/SeekerRequest.msg | 9 + .../agent/communication/acknowledge.hpp | 32 +- .../communication/ball_in_transit_request.hpp | 46 +-- .../agent/communication/communication.cpp | 219 ++++++----- .../agent/communication/communication.hpp | 370 +++++++++--------- .../communication/incoming_ball_request.hpp | 43 +- .../agent/communication/join_wall_request.hpp | 40 +- .../communication/join_wall_response.hpp | 40 +- .../communication/leave_wall_request.hpp | 40 +- .../communication/leave_wall_response.hpp | 40 +- .../agent/communication/pass_request.hpp | 44 +-- .../agent/communication/pass_response.hpp | 38 +- .../agent/communication/position_request.hpp | 34 +- .../agent/communication/position_response.hpp | 40 +- .../communication/reset_scorer_request.hpp | 34 +- .../agent/communication/scorer_request.hpp | 45 ++- .../agent/communication/scorer_response.hpp | 46 ++- .../agent/communication/seeker_request.hpp | 55 +++ .../agent/communication/test_request.hpp | 32 +- .../agent/communication/test_response.hpp | 38 +- .../strategy/agent/position/offense.cpp | 31 +- .../strategy/agent/position/offense.hpp | 5 + .../soccer/strategy/agent/position/seeker.cpp | 44 +-- .../soccer/strategy/agent/position/seeker.hpp | 16 +- 27 files changed, 744 insertions(+), 671 deletions(-) create mode 100644 rj_msgs/request/SeekerRequest.msg create mode 100644 soccer/src/soccer/strategy/agent/communication/seeker_request.hpp diff --git a/rj_msgs/CMakeLists.txt b/rj_msgs/CMakeLists.txt index 9e987316516..793439482fd 100644 --- a/rj_msgs/CMakeLists.txt +++ b/rj_msgs/CMakeLists.txt @@ -59,23 +59,24 @@ rosidl_generate_interfaces( msg/AgentResponseVariant.msg # Agent Request Messages - request/ResetScorerRequest.msg - request/PositionRequest.msg + request/LeaveWallRequest.msg + request/PassRequest.msg + request/SeekerRequest.msg request/TestRequest.msg request/BallInTransitRequest.msg + request/JoinWallRequest.msg request/ScorerRequest.msg request/IncomingBallRequest.msg - request/PassRequest.msg - request/LeaveWallRequest.msg - request/JoinWallRequest.msg + request/ResetScorerRequest.msg + request/PositionRequest.msg # Agent Response Messages response/LeaveWallResponse.msg - response/Acknowledge.msg - response/PassResponse.msg + response/ScorerResponse.msg response/JoinWallResponse.msg + response/Acknowledge.msg response/PositionResponse.msg - response/ScorerResponse.msg + response/PassResponse.msg response/TestResponse.msg # Services diff --git a/rj_msgs/msg/AgentRequest.msg b/rj_msgs/msg/AgentRequest.msg index 69c8a152580..3f3a71f43e6 100644 --- a/rj_msgs/msg/AgentRequest.msg +++ b/rj_msgs/msg/AgentRequest.msg @@ -3,12 +3,13 @@ # 2 -> PositionResponse # 3 -> PassResponse # ACKNOWLEDGE REQUEST DOES NOT (AND SHOULD NOT) EXIST -ResetScorerRequest[<=1] reset_scorer_request -PositionRequest[<=1] position_request +LeaveWallRequest[<=1] leave_wall_request +PassRequest[<=1] pass_request +SeekerRequest[<=1] seeker_request TestRequest[<=1] test_request BallInTransitRequest[<=1] ball_in_transit_request +JoinWallRequest[<=1] join_wall_request ScorerRequest[<=1] scorer_request IncomingBallRequest[<=1] incoming_ball_request -PassRequest[<=1] pass_request -LeaveWallRequest[<=1] leave_wall_request -JoinWallRequest[<=1] join_wall_request \ No newline at end of file +ResetScorerRequest[<=1] reset_scorer_request +PositionRequest[<=1] position_request \ No newline at end of file diff --git a/rj_msgs/msg/AgentResponseVariant.msg b/rj_msgs/msg/AgentResponseVariant.msg index c4fc9c33705..ae5186a4896 100644 --- a/rj_msgs/msg/AgentResponseVariant.msg +++ b/rj_msgs/msg/AgentResponseVariant.msg @@ -1,7 +1,7 @@ LeaveWallResponse[<=1] leave_wall_response -Acknowledge[<=1] acknowledge -PassResponse[<=1] pass_response +ScorerResponse[<=1] scorer_response JoinWallResponse[<=1] join_wall_response +Acknowledge[<=1] acknowledge PositionResponse[<=1] position_response -ScorerResponse[<=1] scorer_response +PassResponse[<=1] pass_response TestResponse[<=1] test_response \ No newline at end of file diff --git a/rj_msgs/request/SeekerRequest.msg b/rj_msgs/request/SeekerRequest.msg new file mode 100644 index 00000000000..855095403af --- /dev/null +++ b/rj_msgs/request/SeekerRequest.msg @@ -0,0 +1,9 @@ +# /** +# * @brief request sent by an agent to one or many agents indicating +# * that it would like to seek +# */ +uint32 request_uid +uint8 robot_id +float64 seeking_point_x +float64 seeking_point_y +bool adding \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/acknowledge.hpp b/soccer/src/soccer/strategy/agent/communication/acknowledge.hpp index fc98f6264ae..220b81a5f05 100644 --- a/soccer/src/soccer/strategy/agent/communication/acknowledge.hpp +++ b/soccer/src/soccer/strategy/agent/communication/acknowledge.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -7,37 +7,37 @@ #include #include - #include "rj_msgs/msg/acknowledge.hpp" namespace strategy::communication { struct Acknowledge { - uint32_t response_uid; + uint32_t response_uid; }; bool operator==(const Acknowledge& a, const Acknowledge& b); void generate_uid(Acknowledge& response); -} // namespace strategy::communication +} namespace rj_convert { template <> struct RosConverter { - static rj_msgs::msg::Acknowledge to_ros(const strategy::communication::Acknowledge& from) { - rj_msgs::msg::Acknowledge result; - result.response_uid = from.response_uid; - return result; - } - - static strategy::communication::Acknowledge from_ros(const rj_msgs::msg::Acknowledge& from) { - return strategy::communication::Acknowledge{ - from.response_uid, - }; - } + static rj_msgs::msg::Acknowledge to_ros(const strategy::communication::Acknowledge& from) { + rj_msgs::msg::Acknowledge result; + result.response_uid = from.response_uid; + return result; + } + + static strategy::communication::Acknowledge from_ros(const rj_msgs::msg::Acknowledge& from) { + return strategy::communication::Acknowledge{ + from.response_uid, + }; + } + }; ASSOCIATE_CPP_ROS(strategy::communication::Acknowledge, rj_msgs::msg::Acknowledge); -} // namespace rj_convert \ No newline at end of file +} \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/ball_in_transit_request.hpp b/soccer/src/soccer/strategy/agent/communication/ball_in_transit_request.hpp index 5438935e41b..e8656a1a9b6 100644 --- a/soccer/src/soccer/strategy/agent/communication/ball_in_transit_request.hpp +++ b/soccer/src/soccer/strategy/agent/communication/ball_in_transit_request.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -7,44 +7,40 @@ #include #include - #include "rj_msgs/msg/ball_in_transit_request.hpp" namespace strategy::communication { struct BallInTransitRequest { - uint32_t request_uid; - uint8_t from_robot_id; + uint32_t request_uid; + uint8_t from_robot_id; }; bool operator==(const BallInTransitRequest& a, const BallInTransitRequest& b); void generate_uid(BallInTransitRequest& request); -} // namespace strategy::communication +} namespace rj_convert { template <> -struct RosConverter { - static rj_msgs::msg::BallInTransitRequest to_ros( - const strategy::communication::BallInTransitRequest& from) { - rj_msgs::msg::BallInTransitRequest result; - result.request_uid = from.request_uid; - result.from_robot_id = from.from_robot_id; - return result; - } - - static strategy::communication::BallInTransitRequest from_ros( - const rj_msgs::msg::BallInTransitRequest& from) { - return strategy::communication::BallInTransitRequest{ - from.request_uid, - from.from_robot_id, - }; - } +struct RosConverter { + static rj_msgs::msg::BallInTransitRequest to_ros(const strategy::communication::BallInTransitRequest& from) { + rj_msgs::msg::BallInTransitRequest result; + result.request_uid = from.request_uid; + result.from_robot_id = from.from_robot_id; + return result; + } + + static strategy::communication::BallInTransitRequest from_ros(const rj_msgs::msg::BallInTransitRequest& from) { + return strategy::communication::BallInTransitRequest{ + from.request_uid, + from.from_robot_id, + }; + } + }; -ASSOCIATE_CPP_ROS(strategy::communication::BallInTransitRequest, - rj_msgs::msg::BallInTransitRequest); +ASSOCIATE_CPP_ROS(strategy::communication::BallInTransitRequest, rj_msgs::msg::BallInTransitRequest); -} // namespace rj_convert \ No newline at end of file +} \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/communication.cpp b/soccer/src/soccer/strategy/agent/communication/communication.cpp index c840fb56456..272d77ce214 100644 --- a/soccer/src/soccer/strategy/agent/communication/communication.cpp +++ b/soccer/src/soccer/strategy/agent/communication/communication.cpp @@ -8,184 +8,195 @@ u_int32_t request_uid = 0; std::mutex response_uid_mutex; u_int32_t response_uid = 0; -bool operator==(const ResetScorerRequest& a, const ResetScorerRequest& b) { - return a.request_uid == b.request_uid; +bool operator==(const LeaveWallRequest& a, const LeaveWallRequest& b) { + return a.request_uid == b.request_uid; } -bool operator==(const PositionRequest& a, const PositionRequest& b) { - return a.request_uid == b.request_uid; +bool operator==(const PassRequest& a, const PassRequest& b) { + return a.request_uid == b.request_uid; +} + +bool operator==(const SeekerRequest& a, const SeekerRequest& b) { + return a.request_uid == b.request_uid; } bool operator==(const TestRequest& a, const TestRequest& b) { - return a.request_uid == b.request_uid; + return a.request_uid == b.request_uid; } bool operator==(const BallInTransitRequest& a, const BallInTransitRequest& b) { - return a.request_uid == b.request_uid; + return a.request_uid == b.request_uid; } -bool operator==(const ScorerRequest& a, const ScorerRequest& b) { - return a.request_uid == b.request_uid; +bool operator==(const JoinWallRequest& a, const JoinWallRequest& b) { + return a.request_uid == b.request_uid; } -bool operator==(const IncomingBallRequest& a, const IncomingBallRequest& b) { - return a.request_uid == b.request_uid; +bool operator==(const ScorerRequest& a, const ScorerRequest& b) { + return a.request_uid == b.request_uid; } -bool operator==(const PassRequest& a, const PassRequest& b) { - return a.request_uid == b.request_uid; +bool operator==(const IncomingBallRequest& a, const IncomingBallRequest& b) { + return a.request_uid == b.request_uid; } -bool operator==(const LeaveWallRequest& a, const LeaveWallRequest& b) { - return a.request_uid == b.request_uid; +bool operator==(const ResetScorerRequest& a, const ResetScorerRequest& b) { + return a.request_uid == b.request_uid; } -bool operator==(const JoinWallRequest& a, const JoinWallRequest& b) { - return a.request_uid == b.request_uid; +bool operator==(const PositionRequest& a, const PositionRequest& b) { + return a.request_uid == b.request_uid; } bool operator==(const LeaveWallResponse& a, const LeaveWallResponse& b) { - return a.response_uid == b.response_uid; + return a.response_uid == b.response_uid; } -bool operator==(const Acknowledge& a, const Acknowledge& b) { - return a.response_uid == b.response_uid; +bool operator==(const ScorerResponse& a, const ScorerResponse& b) { + return a.response_uid == b.response_uid; } -bool operator==(const PassResponse& a, const PassResponse& b) { - return a.response_uid == b.response_uid; +bool operator==(const JoinWallResponse& a, const JoinWallResponse& b) { + return a.response_uid == b.response_uid; } -bool operator==(const JoinWallResponse& a, const JoinWallResponse& b) { - return a.response_uid == b.response_uid; +bool operator==(const Acknowledge& a, const Acknowledge& b) { + return a.response_uid == b.response_uid; } bool operator==(const PositionResponse& a, const PositionResponse& b) { - return a.response_uid == b.response_uid; + return a.response_uid == b.response_uid; } -bool operator==(const ScorerResponse& a, const ScorerResponse& b) { - return a.response_uid == b.response_uid; +bool operator==(const PassResponse& a, const PassResponse& b) { + return a.response_uid == b.response_uid; } bool operator==(const TestResponse& a, const TestResponse& b) { - return a.response_uid == b.response_uid; + return a.response_uid == b.response_uid; } bool operator==(const AgentResponse& a, const AgentResponse& b) { - return (a.associated_request == b.associated_request) && (a.response == b.response); + return (a.associated_request == b.associated_request) && (a.response == b.response); } -void generate_uid(ResetScorerRequest& request) { - request_uid_mutex.lock(); - request.request_uid = request_uid; - request_uid++; - request_uid_mutex.unlock(); +void generate_uid(LeaveWallRequest& request) { + request_uid_mutex.lock(); + request.request_uid = request_uid; + request_uid++; + request_uid_mutex.unlock(); } -void generate_uid(PositionRequest& request) { - request_uid_mutex.lock(); - request.request_uid = request_uid; - request_uid++; - request_uid_mutex.unlock(); +void generate_uid(PassRequest& request) { + request_uid_mutex.lock(); + request.request_uid = request_uid; + request_uid++; + request_uid_mutex.unlock(); +} + +void generate_uid(SeekerRequest& request) { + request_uid_mutex.lock(); + request.request_uid = request_uid; + request_uid++; + request_uid_mutex.unlock(); } void generate_uid(TestRequest& request) { - request_uid_mutex.lock(); - request.request_uid = request_uid; - request_uid++; - request_uid_mutex.unlock(); + request_uid_mutex.lock(); + request.request_uid = request_uid; + request_uid++; + request_uid_mutex.unlock(); } void generate_uid(BallInTransitRequest& request) { - request_uid_mutex.lock(); - request.request_uid = request_uid; - request_uid++; - request_uid_mutex.unlock(); + request_uid_mutex.lock(); + request.request_uid = request_uid; + request_uid++; + request_uid_mutex.unlock(); } -void generate_uid(ScorerRequest& request) { - request_uid_mutex.lock(); - request.request_uid = request_uid; - request_uid++; - request_uid_mutex.unlock(); +void generate_uid(JoinWallRequest& request) { + request_uid_mutex.lock(); + request.request_uid = request_uid; + request_uid++; + request_uid_mutex.unlock(); } -void generate_uid(IncomingBallRequest& request) { - request_uid_mutex.lock(); - request.request_uid = request_uid; - request_uid++; - request_uid_mutex.unlock(); +void generate_uid(ScorerRequest& request) { + request_uid_mutex.lock(); + request.request_uid = request_uid; + request_uid++; + request_uid_mutex.unlock(); } -void generate_uid(PassRequest& request) { - request_uid_mutex.lock(); - request.request_uid = request_uid; - request_uid++; - request_uid_mutex.unlock(); +void generate_uid(IncomingBallRequest& request) { + request_uid_mutex.lock(); + request.request_uid = request_uid; + request_uid++; + request_uid_mutex.unlock(); } -void generate_uid(LeaveWallRequest& request) { - request_uid_mutex.lock(); - request.request_uid = request_uid; - request_uid++; - request_uid_mutex.unlock(); +void generate_uid(ResetScorerRequest& request) { + request_uid_mutex.lock(); + request.request_uid = request_uid; + request_uid++; + request_uid_mutex.unlock(); } -void generate_uid(JoinWallRequest& request) { - request_uid_mutex.lock(); - request.request_uid = request_uid; - request_uid++; - request_uid_mutex.unlock(); +void generate_uid(PositionRequest& request) { + request_uid_mutex.lock(); + request.request_uid = request_uid; + request_uid++; + request_uid_mutex.unlock(); } void generate_uid(LeaveWallResponse& response) { - response_uid_mutex.lock(); - response.response_uid = response_uid; - response_uid++; - response_uid_mutex.unlock(); + response_uid_mutex.lock(); + response.response_uid = response_uid; + response_uid++; + response_uid_mutex.unlock(); } -void generate_uid(Acknowledge& response) { - response_uid_mutex.lock(); - response.response_uid = response_uid; - response_uid++; - response_uid_mutex.unlock(); +void generate_uid(ScorerResponse& response) { + response_uid_mutex.lock(); + response.response_uid = response_uid; + response_uid++; + response_uid_mutex.unlock(); } -void generate_uid(PassResponse& response) { - response_uid_mutex.lock(); - response.response_uid = response_uid; - response_uid++; - response_uid_mutex.unlock(); +void generate_uid(JoinWallResponse& response) { + response_uid_mutex.lock(); + response.response_uid = response_uid; + response_uid++; + response_uid_mutex.unlock(); } -void generate_uid(JoinWallResponse& response) { - response_uid_mutex.lock(); - response.response_uid = response_uid; - response_uid++; - response_uid_mutex.unlock(); +void generate_uid(Acknowledge& response) { + response_uid_mutex.lock(); + response.response_uid = response_uid; + response_uid++; + response_uid_mutex.unlock(); } void generate_uid(PositionResponse& response) { - response_uid_mutex.lock(); - response.response_uid = response_uid; - response_uid++; - response_uid_mutex.unlock(); + response_uid_mutex.lock(); + response.response_uid = response_uid; + response_uid++; + response_uid_mutex.unlock(); } -void generate_uid(ScorerResponse& response) { - response_uid_mutex.lock(); - response.response_uid = response_uid; - response_uid++; - response_uid_mutex.unlock(); +void generate_uid(PassResponse& response) { + response_uid_mutex.lock(); + response.response_uid = response_uid; + response_uid++; + response_uid_mutex.unlock(); } void generate_uid(TestResponse& response) { - response_uid_mutex.lock(); - response.response_uid = response_uid; - response_uid++; - response_uid_mutex.unlock(); + response_uid_mutex.lock(); + response.response_uid = response_uid; + response_uid++; + response_uid_mutex.unlock(); } -} // namespace strategy::communication \ No newline at end of file +} \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/communication.hpp b/soccer/src/soccer/strategy/agent/communication/communication.hpp index 4f32a12a52d..1f0d5491b51 100644 --- a/soccer/src/soccer/strategy/agent/communication/communication.hpp +++ b/soccer/src/soccer/strategy/agent/communication/communication.hpp @@ -8,245 +8,231 @@ #include #include -#include "acknowledge.hpp" -#include "ball_in_transit_request.hpp" -#include "incoming_ball_request.hpp" -#include "join_wall_request.hpp" -#include "join_wall_response.hpp" -#include "leave_wall_request.hpp" -#include "leave_wall_response.hpp" -#include "pass_request.hpp" -#include "pass_response.hpp" -#include "position_request.hpp" -#include "position_response.hpp" -#include "reset_scorer_request.hpp" #include "rj_msgs/msg/agent_request.hpp" #include "rj_msgs/msg/agent_response.hpp" #include "rj_msgs/msg/agent_response_variant.hpp" +#include "leave_wall_request.hpp" +#include "pass_request.hpp" +#include "seeker_request.hpp" +#include "test_request.hpp" +#include "ball_in_transit_request.hpp" +#include "join_wall_request.hpp" #include "scorer_request.hpp" +#include "incoming_ball_request.hpp" +#include "reset_scorer_request.hpp" +#include "position_request.hpp" +#include "leave_wall_response.hpp" #include "scorer_response.hpp" -#include "test_request.hpp" +#include "join_wall_response.hpp" +#include "acknowledge.hpp" +#include "position_response.hpp" +#include "pass_response.hpp" #include "test_response.hpp" namespace strategy::communication { /** - * @brief a conglomeration of the different request types. - */ -using AgentRequest = std::variant; +* @brief a conglomeration of the different request types. +*/ +using AgentRequest = std::variant; /** - * @brief a conglomeration of the different response types. - */ -using AgentResponseVariant = - std::variant; +* @brief a conglomeration of the different response types. +*/ +using AgentResponseVariant = std::variant; /** - * @brief response message that is sent from the receiver of the request to the - * sender of the request with an accompanying response. - * - * The agent response is the actual thing that gets sent from a receiver back - * to the sender. - * - */ +* @brief response message that is sent from the receiver of the request to the +* sender of the request with an accompanying response. +* +* The agent response is the actual thing that gets sent from a receiver back +* to the sender. +* +*/ struct AgentResponse { - AgentRequest associated_request; - AgentResponseVariant response; + AgentRequest associated_request; + AgentResponseVariant response; }; bool operator==(const AgentResponse& a, const AgentResponse& b); /** - * @brief Wraps a communication request by giving the intended destination of the - * communication. - * - * positions will create this and send it to their agent action client which will - * send out the request according to their specifications. - * - */ +* @brief Wraps a communication request by giving the intended destination of the +* communication. +* +* positions will create this and send it to their agent action client which will +* send out the request according to their specifications. +* +*/ struct PosAgentRequestWrapper { - AgentRequest request; - std::vector target_agents; - bool broadcast; - bool urgent; + AgentRequest request; + std::vector target_agents; + bool broadcast; + bool urgent; }; /** - * @brief Wraps a communication response to ensure symmetry for agent-to-agent - * communication. - * - * this wrapper is placed on agent responses to promote symmetry across the request - * response system to make understanding easier. All this struct does is make explicit - * that this response is going from the position to the agent. - * - */ +* @brief Wraps a communication response to ensure symmetry for agent-to-agent +* communication. +* +* this wrapper is placed on agent responses to promote symmetry across the request +* response system to make understanding easier. All this struct does is make explicit +* that this response is going from the position to the agent. +* +*/ struct PosAgentResponseWrapper { - AgentResponseVariant response; + AgentResponseVariant response; }; /** - * @brief Wraps a communication request to ensure symmetry for agent-to-agent - * communication. - * - * Like the PosAgentResponseWrapper, this struct does nothing other than make the request - * response system more symmetrical and (hopefully) more easy to understand. All this struct - * does is make it explicit that this request is being passed from the agent to the agent to - * the position. - * - */ +* @brief Wraps a communication request to ensure symmetry for agent-to-agent +* communication. +* +* Like the PosAgentResponseWrapper, this struct does nothing other than make the request +* response system more symmetrical and (hopefully) more easy to understand. All this struct +* does is make it explicit that this request is being passed from the agent to the agent to +* the position. +* +*/ struct AgentPosRequestWrapper { - AgentRequest request; + AgentRequest request; }; /** - * @brief Wraps a communication response by giving the robot the communication is from. - * - * the AgentPosResponseWrapper is the actual thing being passed from the agent to the position - * once either the timeout period was reached or enough responses were received. Ideally, the - * contents of this wrapper should contain all of the non-message specific fields that a position - * will need to handle a response. - * - */ +* @brief Wraps a communication response by giving the robot the communication is from. +* +* the AgentPosResponseWrapper is the actual thing being passed from the agent to the position +* once either the timeout period was reached or enough responses were received. Ideally, the +* contents of this wrapper should contain all of the non-message specific fields that a position +* will need to handle a response. +* +*/ struct AgentPosResponseWrapper { - AgentRequest associated_request; - std::vector to_robot_ids; - std::vector received_robot_ids; - bool broadcast; - bool urgent; - RJ::Time created; - std::vector responses; + AgentRequest associated_request; + std::vector to_robot_ids; + std::vector received_robot_ids; + bool broadcast; + bool urgent; + RJ::Time created; + std::vector responses; }; -} // namespace strategy::communication +} namespace rj_convert { template <> struct RosConverter { - static rj_msgs::msg::AgentRequest to_ros(const strategy::communication::AgentRequest& from) { - rj_msgs::msg::AgentRequest result; - if (const auto* reset_scorer_request = - std::get_if(&from)) { - result.reset_scorer_request.emplace_back(convert_to_ros(*reset_scorer_request)); - } else if (const auto* position_request = - std::get_if(&from)) { - result.position_request.emplace_back(convert_to_ros(*position_request)); - } else if (const auto* test_request = - std::get_if(&from)) { - result.test_request.emplace_back(convert_to_ros(*test_request)); - } else if (const auto* ball_in_transit_request = - std::get_if(&from)) { - result.ball_in_transit_request.emplace_back(convert_to_ros(*ball_in_transit_request)); - } else if (const auto* scorer_request = - std::get_if(&from)) { - result.scorer_request.emplace_back(convert_to_ros(*scorer_request)); - } else if (const auto* incoming_ball_request = - std::get_if(&from)) { - result.incoming_ball_request.emplace_back(convert_to_ros(*incoming_ball_request)); - } else if (const auto* pass_request = - std::get_if(&from)) { - result.pass_request.emplace_back(convert_to_ros(*pass_request)); - } else if (const auto* leave_wall_request = - std::get_if(&from)) { - result.leave_wall_request.emplace_back(convert_to_ros(*leave_wall_request)); - } else if (const auto* join_wall_request = - std::get_if(&from)) { - result.join_wall_request.emplace_back(convert_to_ros(*join_wall_request)); - } else { - throw std::runtime_error("Invalid variant of AgentRequest"); - } - return result; - } - - static strategy::communication::AgentRequest from_ros(const rj_msgs::msg::AgentRequest& from) { - strategy::communication::AgentRequest result; - if (!from.reset_scorer_request.empty()) { - result = convert_from_ros(from.reset_scorer_request.front()); - } else if (!from.position_request.empty()) { - result = convert_from_ros(from.position_request.front()); - } else if (!from.test_request.empty()) { - result = convert_from_ros(from.test_request.front()); - } else if (!from.ball_in_transit_request.empty()) { - result = convert_from_ros(from.ball_in_transit_request.front()); - } else if (!from.scorer_request.empty()) { - result = convert_from_ros(from.scorer_request.front()); - } else if (!from.incoming_ball_request.empty()) { - result = convert_from_ros(from.incoming_ball_request.front()); - } else if (!from.pass_request.empty()) { - result = convert_from_ros(from.pass_request.front()); - } else if (!from.leave_wall_request.empty()) { - result = convert_from_ros(from.leave_wall_request.front()); - } else if (!from.join_wall_request.empty()) { - result = convert_from_ros(from.join_wall_request.front()); - } else { - throw std::runtime_error("Invalid variant of AgentRequest"); - } - return result; - } + static rj_msgs::msg::AgentRequest to_ros(const strategy::communication::AgentRequest& from) { + rj_msgs::msg::AgentRequest result; + if (const auto* leave_wall_request = std::get_if(&from)) { + result.leave_wall_request.emplace_back(convert_to_ros(*leave_wall_request)); + } else if (const auto* pass_request = std::get_if(&from)) { + result.pass_request.emplace_back(convert_to_ros(*pass_request)); + } else if (const auto* seeker_request = std::get_if(&from)) { + result.seeker_request.emplace_back(convert_to_ros(*seeker_request)); + } else if (const auto* test_request = std::get_if(&from)) { + result.test_request.emplace_back(convert_to_ros(*test_request)); + } else if (const auto* ball_in_transit_request = std::get_if(&from)) { + result.ball_in_transit_request.emplace_back(convert_to_ros(*ball_in_transit_request)); + } else if (const auto* join_wall_request = std::get_if(&from)) { + result.join_wall_request.emplace_back(convert_to_ros(*join_wall_request)); + } else if (const auto* scorer_request = std::get_if(&from)) { + result.scorer_request.emplace_back(convert_to_ros(*scorer_request)); + } else if (const auto* incoming_ball_request = std::get_if(&from)) { + result.incoming_ball_request.emplace_back(convert_to_ros(*incoming_ball_request)); + } else if (const auto* reset_scorer_request = std::get_if(&from)) { + result.reset_scorer_request.emplace_back(convert_to_ros(*reset_scorer_request)); + } else if (const auto* position_request = std::get_if(&from)) { + result.position_request.emplace_back(convert_to_ros(*position_request)); + } else { + throw std::runtime_error("Invalid variant of AgentRequest"); + } + return result; + } + + static strategy::communication::AgentRequest from_ros(const rj_msgs::msg::AgentRequest& from) { + strategy::communication::AgentRequest result; + if (!from.leave_wall_request.empty()) { + result = convert_from_ros(from.leave_wall_request.front()); + } else if (!from.pass_request.empty()) { + result = convert_from_ros(from.pass_request.front()); + } else if (!from.seeker_request.empty()) { + result = convert_from_ros(from.seeker_request.front()); + } else if (!from.test_request.empty()) { + result = convert_from_ros(from.test_request.front()); + } else if (!from.ball_in_transit_request.empty()) { + result = convert_from_ros(from.ball_in_transit_request.front()); + } else if (!from.join_wall_request.empty()) { + result = convert_from_ros(from.join_wall_request.front()); + } else if (!from.scorer_request.empty()) { + result = convert_from_ros(from.scorer_request.front()); + } else if (!from.incoming_ball_request.empty()) { + result = convert_from_ros(from.incoming_ball_request.front()); + } else if (!from.reset_scorer_request.empty()) { + result = convert_from_ros(from.reset_scorer_request.front()); + } else if (!from.position_request.empty()) { + result = convert_from_ros(from.position_request.front()); + } else { + throw std::runtime_error("Invalid variant of AgentRequest"); + } + return result; + } + }; ASSOCIATE_CPP_ROS(strategy::communication::AgentRequest, rj_msgs::msg::AgentRequest); template <> struct RosConverter { - static rj_msgs::msg::AgentResponse to_ros(const strategy::communication::AgentResponse& from) { - rj_msgs::msg::AgentResponse result; - result.associated_request = convert_to_ros(from.associated_request); - if (const auto* leave_wall_response = - std::get_if(&(from.response))) { - result.response.leave_wall_response.emplace_back(convert_to_ros(*leave_wall_response)); - } else if (const auto* acknowledge = - std::get_if(&(from.response))) { - result.response.acknowledge.emplace_back(convert_to_ros(*acknowledge)); - } else if (const auto* pass_response = - std::get_if(&(from.response))) { - result.response.pass_response.emplace_back(convert_to_ros(*pass_response)); - } else if (const auto* join_wall_response = - std::get_if(&(from.response))) { - result.response.join_wall_response.emplace_back(convert_to_ros(*join_wall_response)); - } else if (const auto* position_response = - std::get_if(&(from.response))) { - result.response.position_response.emplace_back(convert_to_ros(*position_response)); - } else if (const auto* scorer_response = - std::get_if(&(from.response))) { - result.response.scorer_response.emplace_back(convert_to_ros(*scorer_response)); - } else if (const auto* test_response = - std::get_if(&(from.response))) { - result.response.test_response.emplace_back(convert_to_ros(*test_response)); - } else { - throw std::runtime_error("Invalid variant of AgentResponse"); - } - return result; - } - - static strategy::communication::AgentResponse from_ros( - const rj_msgs::msg::AgentResponse& from) { - strategy::communication::AgentResponse result; - result.associated_request = convert_from_ros(from.associated_request); - if (!from.response.leave_wall_response.empty()) { - result.response = convert_from_ros(from.response.leave_wall_response.front()); - } else if (!from.response.acknowledge.empty()) { - result.response = convert_from_ros(from.response.acknowledge.front()); - } else if (!from.response.pass_response.empty()) { - result.response = convert_from_ros(from.response.pass_response.front()); - } else if (!from.response.join_wall_response.empty()) { - result.response = convert_from_ros(from.response.join_wall_response.front()); - } else if (!from.response.position_response.empty()) { - result.response = convert_from_ros(from.response.position_response.front()); - } else if (!from.response.scorer_response.empty()) { - result.response = convert_from_ros(from.response.scorer_response.front()); - } else if (!from.response.test_response.empty()) { - result.response = convert_from_ros(from.response.test_response.front()); - } else { - throw std::runtime_error("Invalid variant of AgentResponse"); - } - return result; - } + static rj_msgs::msg::AgentResponse to_ros(const strategy::communication::AgentResponse& from) { + rj_msgs::msg::AgentResponse result; + result.associated_request = convert_to_ros(from.associated_request); + if (const auto* leave_wall_response = std::get_if(&(from.response))) { + result.response.leave_wall_response.emplace_back(convert_to_ros(*leave_wall_response)); + } else if (const auto* scorer_response = std::get_if(&(from.response))) { + result.response.scorer_response.emplace_back(convert_to_ros(*scorer_response)); + } else if (const auto* join_wall_response = std::get_if(&(from.response))) { + result.response.join_wall_response.emplace_back(convert_to_ros(*join_wall_response)); + } else if (const auto* acknowledge = std::get_if(&(from.response))) { + result.response.acknowledge.emplace_back(convert_to_ros(*acknowledge)); + } else if (const auto* position_response = std::get_if(&(from.response))) { + result.response.position_response.emplace_back(convert_to_ros(*position_response)); + } else if (const auto* pass_response = std::get_if(&(from.response))) { + result.response.pass_response.emplace_back(convert_to_ros(*pass_response)); + } else if (const auto* test_response = std::get_if(&(from.response))) { + result.response.test_response.emplace_back(convert_to_ros(*test_response)); + } else { + throw std::runtime_error("Invalid variant of AgentResponse"); + } + return result; + } + + static strategy::communication::AgentResponse from_ros(const rj_msgs::msg::AgentResponse& from) { + strategy::communication::AgentResponse result; + result.associated_request = convert_from_ros(from.associated_request); + if (!from.response.leave_wall_response.empty()) { + result.response = convert_from_ros(from.response.leave_wall_response.front()); + } else if (!from.response.scorer_response.empty()) { + result.response = convert_from_ros(from.response.scorer_response.front()); + } else if (!from.response.join_wall_response.empty()) { + result.response = convert_from_ros(from.response.join_wall_response.front()); + } else if (!from.response.acknowledge.empty()) { + result.response = convert_from_ros(from.response.acknowledge.front()); + } else if (!from.response.position_response.empty()) { + result.response = convert_from_ros(from.response.position_response.front()); + } else if (!from.response.pass_response.empty()) { + result.response = convert_from_ros(from.response.pass_response.front()); + } else if (!from.response.test_response.empty()) { + result.response = convert_from_ros(from.response.test_response.front()); + } else { + throw std::runtime_error("Invalid variant of AgentResponse"); + } + return result; + } + }; ASSOCIATE_CPP_ROS(strategy::communication::AgentResponse, rj_msgs::msg::AgentResponse); -} // namespace rj_convert \ No newline at end of file +} \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/incoming_ball_request.hpp b/soccer/src/soccer/strategy/agent/communication/incoming_ball_request.hpp index 24ec11366c6..124a4fded83 100644 --- a/soccer/src/soccer/strategy/agent/communication/incoming_ball_request.hpp +++ b/soccer/src/soccer/strategy/agent/communication/incoming_ball_request.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -7,43 +7,40 @@ #include #include - #include "rj_msgs/msg/incoming_ball_request.hpp" namespace strategy::communication { struct IncomingBallRequest { - uint32_t request_uid; - uint8_t from_robot_id; + uint32_t request_uid; + uint8_t from_robot_id; }; bool operator==(const IncomingBallRequest& a, const IncomingBallRequest& b); void generate_uid(IncomingBallRequest& request); -} // namespace strategy::communication +} namespace rj_convert { template <> -struct RosConverter { - static rj_msgs::msg::IncomingBallRequest to_ros( - const strategy::communication::IncomingBallRequest& from) { - rj_msgs::msg::IncomingBallRequest result; - result.request_uid = from.request_uid; - result.from_robot_id = from.from_robot_id; - return result; - } - - static strategy::communication::IncomingBallRequest from_ros( - const rj_msgs::msg::IncomingBallRequest& from) { - return strategy::communication::IncomingBallRequest{ - from.request_uid, - from.from_robot_id, - }; - } +struct RosConverter { + static rj_msgs::msg::IncomingBallRequest to_ros(const strategy::communication::IncomingBallRequest& from) { + rj_msgs::msg::IncomingBallRequest result; + result.request_uid = from.request_uid; + result.from_robot_id = from.from_robot_id; + return result; + } + + static strategy::communication::IncomingBallRequest from_ros(const rj_msgs::msg::IncomingBallRequest& from) { + return strategy::communication::IncomingBallRequest{ + from.request_uid, + from.from_robot_id, + }; + } + }; ASSOCIATE_CPP_ROS(strategy::communication::IncomingBallRequest, rj_msgs::msg::IncomingBallRequest); -} // namespace rj_convert \ No newline at end of file +} \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/join_wall_request.hpp b/soccer/src/soccer/strategy/agent/communication/join_wall_request.hpp index eb45b69e4d3..c8ba299419b 100644 --- a/soccer/src/soccer/strategy/agent/communication/join_wall_request.hpp +++ b/soccer/src/soccer/strategy/agent/communication/join_wall_request.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -7,42 +7,40 @@ #include #include - #include "rj_msgs/msg/join_wall_request.hpp" namespace strategy::communication { struct JoinWallRequest { - uint32_t request_uid; - uint8_t robot_id; + uint32_t request_uid; + uint8_t robot_id; }; bool operator==(const JoinWallRequest& a, const JoinWallRequest& b); void generate_uid(JoinWallRequest& request); -} // namespace strategy::communication +} namespace rj_convert { template <> struct RosConverter { - static rj_msgs::msg::JoinWallRequest to_ros( - const strategy::communication::JoinWallRequest& from) { - rj_msgs::msg::JoinWallRequest result; - result.request_uid = from.request_uid; - result.robot_id = from.robot_id; - return result; - } - - static strategy::communication::JoinWallRequest from_ros( - const rj_msgs::msg::JoinWallRequest& from) { - return strategy::communication::JoinWallRequest{ - from.request_uid, - from.robot_id, - }; - } + static rj_msgs::msg::JoinWallRequest to_ros(const strategy::communication::JoinWallRequest& from) { + rj_msgs::msg::JoinWallRequest result; + result.request_uid = from.request_uid; + result.robot_id = from.robot_id; + return result; + } + + static strategy::communication::JoinWallRequest from_ros(const rj_msgs::msg::JoinWallRequest& from) { + return strategy::communication::JoinWallRequest{ + from.request_uid, + from.robot_id, + }; + } + }; ASSOCIATE_CPP_ROS(strategy::communication::JoinWallRequest, rj_msgs::msg::JoinWallRequest); -} // namespace rj_convert \ No newline at end of file +} \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/join_wall_response.hpp b/soccer/src/soccer/strategy/agent/communication/join_wall_response.hpp index d69e52b67b5..8e86bd0c6bb 100644 --- a/soccer/src/soccer/strategy/agent/communication/join_wall_response.hpp +++ b/soccer/src/soccer/strategy/agent/communication/join_wall_response.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -7,42 +7,40 @@ #include #include - #include "rj_msgs/msg/join_wall_response.hpp" namespace strategy::communication { struct JoinWallResponse { - uint32_t response_uid; - uint8_t robot_id; + uint32_t response_uid; + uint8_t robot_id; }; bool operator==(const JoinWallResponse& a, const JoinWallResponse& b); void generate_uid(JoinWallResponse& response); -} // namespace strategy::communication +} namespace rj_convert { template <> struct RosConverter { - static rj_msgs::msg::JoinWallResponse to_ros( - const strategy::communication::JoinWallResponse& from) { - rj_msgs::msg::JoinWallResponse result; - result.response_uid = from.response_uid; - result.robot_id = from.robot_id; - return result; - } - - static strategy::communication::JoinWallResponse from_ros( - const rj_msgs::msg::JoinWallResponse& from) { - return strategy::communication::JoinWallResponse{ - from.response_uid, - from.robot_id, - }; - } + static rj_msgs::msg::JoinWallResponse to_ros(const strategy::communication::JoinWallResponse& from) { + rj_msgs::msg::JoinWallResponse result; + result.response_uid = from.response_uid; + result.robot_id = from.robot_id; + return result; + } + + static strategy::communication::JoinWallResponse from_ros(const rj_msgs::msg::JoinWallResponse& from) { + return strategy::communication::JoinWallResponse{ + from.response_uid, + from.robot_id, + }; + } + }; ASSOCIATE_CPP_ROS(strategy::communication::JoinWallResponse, rj_msgs::msg::JoinWallResponse); -} // namespace rj_convert \ No newline at end of file +} \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/leave_wall_request.hpp b/soccer/src/soccer/strategy/agent/communication/leave_wall_request.hpp index 51218590f16..6b67d9b6942 100644 --- a/soccer/src/soccer/strategy/agent/communication/leave_wall_request.hpp +++ b/soccer/src/soccer/strategy/agent/communication/leave_wall_request.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -7,42 +7,40 @@ #include #include - #include "rj_msgs/msg/leave_wall_request.hpp" namespace strategy::communication { struct LeaveWallRequest { - uint32_t request_uid; - uint8_t robot_id; + uint32_t request_uid; + uint8_t robot_id; }; bool operator==(const LeaveWallRequest& a, const LeaveWallRequest& b); void generate_uid(LeaveWallRequest& request); -} // namespace strategy::communication +} namespace rj_convert { template <> struct RosConverter { - static rj_msgs::msg::LeaveWallRequest to_ros( - const strategy::communication::LeaveWallRequest& from) { - rj_msgs::msg::LeaveWallRequest result; - result.request_uid = from.request_uid; - result.robot_id = from.robot_id; - return result; - } - - static strategy::communication::LeaveWallRequest from_ros( - const rj_msgs::msg::LeaveWallRequest& from) { - return strategy::communication::LeaveWallRequest{ - from.request_uid, - from.robot_id, - }; - } + static rj_msgs::msg::LeaveWallRequest to_ros(const strategy::communication::LeaveWallRequest& from) { + rj_msgs::msg::LeaveWallRequest result; + result.request_uid = from.request_uid; + result.robot_id = from.robot_id; + return result; + } + + static strategy::communication::LeaveWallRequest from_ros(const rj_msgs::msg::LeaveWallRequest& from) { + return strategy::communication::LeaveWallRequest{ + from.request_uid, + from.robot_id, + }; + } + }; ASSOCIATE_CPP_ROS(strategy::communication::LeaveWallRequest, rj_msgs::msg::LeaveWallRequest); -} // namespace rj_convert \ No newline at end of file +} \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/leave_wall_response.hpp b/soccer/src/soccer/strategy/agent/communication/leave_wall_response.hpp index 7510e24e952..4a5c26ce6f8 100644 --- a/soccer/src/soccer/strategy/agent/communication/leave_wall_response.hpp +++ b/soccer/src/soccer/strategy/agent/communication/leave_wall_response.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -7,42 +7,40 @@ #include #include - #include "rj_msgs/msg/leave_wall_response.hpp" namespace strategy::communication { struct LeaveWallResponse { - uint32_t response_uid; - uint8_t robot_id; + uint32_t response_uid; + uint8_t robot_id; }; bool operator==(const LeaveWallResponse& a, const LeaveWallResponse& b); void generate_uid(LeaveWallResponse& response); -} // namespace strategy::communication +} namespace rj_convert { template <> struct RosConverter { - static rj_msgs::msg::LeaveWallResponse to_ros( - const strategy::communication::LeaveWallResponse& from) { - rj_msgs::msg::LeaveWallResponse result; - result.response_uid = from.response_uid; - result.robot_id = from.robot_id; - return result; - } - - static strategy::communication::LeaveWallResponse from_ros( - const rj_msgs::msg::LeaveWallResponse& from) { - return strategy::communication::LeaveWallResponse{ - from.response_uid, - from.robot_id, - }; - } + static rj_msgs::msg::LeaveWallResponse to_ros(const strategy::communication::LeaveWallResponse& from) { + rj_msgs::msg::LeaveWallResponse result; + result.response_uid = from.response_uid; + result.robot_id = from.robot_id; + return result; + } + + static strategy::communication::LeaveWallResponse from_ros(const rj_msgs::msg::LeaveWallResponse& from) { + return strategy::communication::LeaveWallResponse{ + from.response_uid, + from.robot_id, + }; + } + }; ASSOCIATE_CPP_ROS(strategy::communication::LeaveWallResponse, rj_msgs::msg::LeaveWallResponse); -} // namespace rj_convert \ No newline at end of file +} \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/pass_request.hpp b/soccer/src/soccer/strategy/agent/communication/pass_request.hpp index c499edf5179..3fd41d95a59 100644 --- a/soccer/src/soccer/strategy/agent/communication/pass_request.hpp +++ b/soccer/src/soccer/strategy/agent/communication/pass_request.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -7,43 +7,43 @@ #include #include - #include "rj_msgs/msg/pass_request.hpp" namespace strategy::communication { struct PassRequest { - uint32_t request_uid; - bool direct; - uint8_t from_robot_id; + uint32_t request_uid; + bool direct; + uint8_t from_robot_id; }; bool operator==(const PassRequest& a, const PassRequest& b); void generate_uid(PassRequest& request); -} // namespace strategy::communication +} namespace rj_convert { template <> struct RosConverter { - static rj_msgs::msg::PassRequest to_ros(const strategy::communication::PassRequest& from) { - rj_msgs::msg::PassRequest result; - result.request_uid = from.request_uid; - result.direct = from.direct; - result.from_robot_id = from.from_robot_id; - return result; - } - - static strategy::communication::PassRequest from_ros(const rj_msgs::msg::PassRequest& from) { - return strategy::communication::PassRequest{ - from.request_uid, - from.direct, - from.from_robot_id, - }; - } + static rj_msgs::msg::PassRequest to_ros(const strategy::communication::PassRequest& from) { + rj_msgs::msg::PassRequest result; + result.request_uid = from.request_uid; + result.direct = from.direct; + result.from_robot_id = from.from_robot_id; + return result; + } + + static strategy::communication::PassRequest from_ros(const rj_msgs::msg::PassRequest& from) { + return strategy::communication::PassRequest{ + from.request_uid, + from.direct, + from.from_robot_id, + }; + } + }; ASSOCIATE_CPP_ROS(strategy::communication::PassRequest, rj_msgs::msg::PassRequest); -} // namespace rj_convert \ No newline at end of file +} \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/pass_response.hpp b/soccer/src/soccer/strategy/agent/communication/pass_response.hpp index e96cd3c5dd1..f8e3f4739cf 100644 --- a/soccer/src/soccer/strategy/agent/communication/pass_response.hpp +++ b/soccer/src/soccer/strategy/agent/communication/pass_response.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -7,40 +7,40 @@ #include #include - #include "rj_msgs/msg/pass_response.hpp" namespace strategy::communication { struct PassResponse { - uint32_t response_uid; - bool direct_open; + uint32_t response_uid; + bool direct_open; }; bool operator==(const PassResponse& a, const PassResponse& b); void generate_uid(PassResponse& response); -} // namespace strategy::communication +} namespace rj_convert { template <> struct RosConverter { - static rj_msgs::msg::PassResponse to_ros(const strategy::communication::PassResponse& from) { - rj_msgs::msg::PassResponse result; - result.response_uid = from.response_uid; - result.direct_open = from.direct_open; - return result; - } - - static strategy::communication::PassResponse from_ros(const rj_msgs::msg::PassResponse& from) { - return strategy::communication::PassResponse{ - from.response_uid, - from.direct_open, - }; - } + static rj_msgs::msg::PassResponse to_ros(const strategy::communication::PassResponse& from) { + rj_msgs::msg::PassResponse result; + result.response_uid = from.response_uid; + result.direct_open = from.direct_open; + return result; + } + + static strategy::communication::PassResponse from_ros(const rj_msgs::msg::PassResponse& from) { + return strategy::communication::PassResponse{ + from.response_uid, + from.direct_open, + }; + } + }; ASSOCIATE_CPP_ROS(strategy::communication::PassResponse, rj_msgs::msg::PassResponse); -} // namespace rj_convert \ No newline at end of file +} \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/position_request.hpp b/soccer/src/soccer/strategy/agent/communication/position_request.hpp index 5232655c3b7..cd0552519db 100644 --- a/soccer/src/soccer/strategy/agent/communication/position_request.hpp +++ b/soccer/src/soccer/strategy/agent/communication/position_request.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -7,39 +7,37 @@ #include #include - #include "rj_msgs/msg/position_request.hpp" namespace strategy::communication { struct PositionRequest { - uint32_t request_uid; + uint32_t request_uid; }; bool operator==(const PositionRequest& a, const PositionRequest& b); void generate_uid(PositionRequest& request); -} // namespace strategy::communication +} namespace rj_convert { template <> struct RosConverter { - static rj_msgs::msg::PositionRequest to_ros( - const strategy::communication::PositionRequest& from) { - rj_msgs::msg::PositionRequest result; - result.request_uid = from.request_uid; - return result; - } - - static strategy::communication::PositionRequest from_ros( - const rj_msgs::msg::PositionRequest& from) { - return strategy::communication::PositionRequest{ - from.request_uid, - }; - } + static rj_msgs::msg::PositionRequest to_ros(const strategy::communication::PositionRequest& from) { + rj_msgs::msg::PositionRequest result; + result.request_uid = from.request_uid; + return result; + } + + static strategy::communication::PositionRequest from_ros(const rj_msgs::msg::PositionRequest& from) { + return strategy::communication::PositionRequest{ + from.request_uid, + }; + } + }; ASSOCIATE_CPP_ROS(strategy::communication::PositionRequest, rj_msgs::msg::PositionRequest); -} // namespace rj_convert \ No newline at end of file +} \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/position_response.hpp b/soccer/src/soccer/strategy/agent/communication/position_response.hpp index e40ab07e3c0..46dd539551e 100644 --- a/soccer/src/soccer/strategy/agent/communication/position_response.hpp +++ b/soccer/src/soccer/strategy/agent/communication/position_response.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -7,42 +7,40 @@ #include #include - #include "rj_msgs/msg/position_response.hpp" namespace strategy::communication { struct PositionResponse { - uint32_t response_uid; - std::string position; + uint32_t response_uid; + std::string position; }; bool operator==(const PositionResponse& a, const PositionResponse& b); void generate_uid(PositionResponse& response); -} // namespace strategy::communication +} namespace rj_convert { template <> struct RosConverter { - static rj_msgs::msg::PositionResponse to_ros( - const strategy::communication::PositionResponse& from) { - rj_msgs::msg::PositionResponse result; - result.response_uid = from.response_uid; - result.position = from.position; - return result; - } - - static strategy::communication::PositionResponse from_ros( - const rj_msgs::msg::PositionResponse& from) { - return strategy::communication::PositionResponse{ - from.response_uid, - from.position, - }; - } + static rj_msgs::msg::PositionResponse to_ros(const strategy::communication::PositionResponse& from) { + rj_msgs::msg::PositionResponse result; + result.response_uid = from.response_uid; + result.position = from.position; + return result; + } + + static strategy::communication::PositionResponse from_ros(const rj_msgs::msg::PositionResponse& from) { + return strategy::communication::PositionResponse{ + from.response_uid, + from.position, + }; + } + }; ASSOCIATE_CPP_ROS(strategy::communication::PositionResponse, rj_msgs::msg::PositionResponse); -} // namespace rj_convert \ No newline at end of file +} \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/reset_scorer_request.hpp b/soccer/src/soccer/strategy/agent/communication/reset_scorer_request.hpp index 32848b5a3c4..dd7d18d3949 100644 --- a/soccer/src/soccer/strategy/agent/communication/reset_scorer_request.hpp +++ b/soccer/src/soccer/strategy/agent/communication/reset_scorer_request.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -7,39 +7,37 @@ #include #include - #include "rj_msgs/msg/reset_scorer_request.hpp" namespace strategy::communication { struct ResetScorerRequest { - uint32_t request_uid; + uint32_t request_uid; }; bool operator==(const ResetScorerRequest& a, const ResetScorerRequest& b); void generate_uid(ResetScorerRequest& request); -} // namespace strategy::communication +} namespace rj_convert { template <> struct RosConverter { - static rj_msgs::msg::ResetScorerRequest to_ros( - const strategy::communication::ResetScorerRequest& from) { - rj_msgs::msg::ResetScorerRequest result; - result.request_uid = from.request_uid; - return result; - } - - static strategy::communication::ResetScorerRequest from_ros( - const rj_msgs::msg::ResetScorerRequest& from) { - return strategy::communication::ResetScorerRequest{ - from.request_uid, - }; - } + static rj_msgs::msg::ResetScorerRequest to_ros(const strategy::communication::ResetScorerRequest& from) { + rj_msgs::msg::ResetScorerRequest result; + result.request_uid = from.request_uid; + return result; + } + + static strategy::communication::ResetScorerRequest from_ros(const rj_msgs::msg::ResetScorerRequest& from) { + return strategy::communication::ResetScorerRequest{ + from.request_uid, + }; + } + }; ASSOCIATE_CPP_ROS(strategy::communication::ResetScorerRequest, rj_msgs::msg::ResetScorerRequest); -} // namespace rj_convert \ No newline at end of file +} \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/scorer_request.hpp b/soccer/src/soccer/strategy/agent/communication/scorer_request.hpp index 116934d48d3..2882e161204 100644 --- a/soccer/src/soccer/strategy/agent/communication/scorer_request.hpp +++ b/soccer/src/soccer/strategy/agent/communication/scorer_request.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -7,44 +7,43 @@ #include #include - #include "rj_msgs/msg/scorer_request.hpp" namespace strategy::communication { struct ScorerRequest { - uint32_t request_uid; - uint8_t robot_id; - double ball_distance; + uint32_t request_uid; + uint8_t robot_id; + double ball_distance; }; bool operator==(const ScorerRequest& a, const ScorerRequest& b); void generate_uid(ScorerRequest& request); -} // namespace strategy::communication +} namespace rj_convert { template <> struct RosConverter { - static rj_msgs::msg::ScorerRequest to_ros(const strategy::communication::ScorerRequest& from) { - rj_msgs::msg::ScorerRequest result; - result.request_uid = from.request_uid; - result.robot_id = from.robot_id; - result.ball_distance = from.ball_distance; - return result; - } - - static strategy::communication::ScorerRequest from_ros( - const rj_msgs::msg::ScorerRequest& from) { - return strategy::communication::ScorerRequest{ - from.request_uid, - from.robot_id, - from.ball_distance, - }; - } + static rj_msgs::msg::ScorerRequest to_ros(const strategy::communication::ScorerRequest& from) { + rj_msgs::msg::ScorerRequest result; + result.request_uid = from.request_uid; + result.robot_id = from.robot_id; + result.ball_distance = from.ball_distance; + return result; + } + + static strategy::communication::ScorerRequest from_ros(const rj_msgs::msg::ScorerRequest& from) { + return strategy::communication::ScorerRequest{ + from.request_uid, + from.robot_id, + from.ball_distance, + }; + } + }; ASSOCIATE_CPP_ROS(strategy::communication::ScorerRequest, rj_msgs::msg::ScorerRequest); -} // namespace rj_convert \ No newline at end of file +} \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/scorer_response.hpp b/soccer/src/soccer/strategy/agent/communication/scorer_response.hpp index 99d94e0aa55..0683769c248 100644 --- a/soccer/src/soccer/strategy/agent/communication/scorer_response.hpp +++ b/soccer/src/soccer/strategy/agent/communication/scorer_response.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -7,45 +7,43 @@ #include #include - #include "rj_msgs/msg/scorer_response.hpp" namespace strategy::communication { struct ScorerResponse { - uint32_t response_uid; - uint8_t robot_id; - double ball_distance; + uint32_t response_uid; + uint8_t robot_id; + double ball_distance; }; bool operator==(const ScorerResponse& a, const ScorerResponse& b); void generate_uid(ScorerResponse& response); -} // namespace strategy::communication +} namespace rj_convert { template <> struct RosConverter { - static rj_msgs::msg::ScorerResponse to_ros( - const strategy::communication::ScorerResponse& from) { - rj_msgs::msg::ScorerResponse result; - result.response_uid = from.response_uid; - result.robot_id = from.robot_id; - result.ball_distance = from.ball_distance; - return result; - } - - static strategy::communication::ScorerResponse from_ros( - const rj_msgs::msg::ScorerResponse& from) { - return strategy::communication::ScorerResponse{ - from.response_uid, - from.robot_id, - from.ball_distance, - }; - } + static rj_msgs::msg::ScorerResponse to_ros(const strategy::communication::ScorerResponse& from) { + rj_msgs::msg::ScorerResponse result; + result.response_uid = from.response_uid; + result.robot_id = from.robot_id; + result.ball_distance = from.ball_distance; + return result; + } + + static strategy::communication::ScorerResponse from_ros(const rj_msgs::msg::ScorerResponse& from) { + return strategy::communication::ScorerResponse{ + from.response_uid, + from.robot_id, + from.ball_distance, + }; + } + }; ASSOCIATE_CPP_ROS(strategy::communication::ScorerResponse, rj_msgs::msg::ScorerResponse); -} // namespace rj_convert \ No newline at end of file +} \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/seeker_request.hpp b/soccer/src/soccer/strategy/agent/communication/seeker_request.hpp new file mode 100644 index 00000000000..d3de172b771 --- /dev/null +++ b/soccer/src/soccer/strategy/agent/communication/seeker_request.hpp @@ -0,0 +1,55 @@ +#pragma once + +#include +#include +#include +#include + +#include +#include +#include "rj_msgs/msg/seeker_request.hpp" + +namespace strategy::communication { + +struct SeekerRequest { + uint32_t request_uid; + uint8_t robot_id; + double seeking_point_x; + double seeking_point_y; + bool adding; +}; + +bool operator==(const SeekerRequest& a, const SeekerRequest& b); +void generate_uid(SeekerRequest& request); + +} + +namespace rj_convert { + +template <> +struct RosConverter { + static rj_msgs::msg::SeekerRequest to_ros(const strategy::communication::SeekerRequest& from) { + rj_msgs::msg::SeekerRequest result; + result.request_uid = from.request_uid; + result.robot_id = from.robot_id; + result.seeking_point_x = from.seeking_point_x; + result.seeking_point_y = from.seeking_point_y; + result.adding = from.adding; + return result; + } + + static strategy::communication::SeekerRequest from_ros(const rj_msgs::msg::SeekerRequest& from) { + return strategy::communication::SeekerRequest{ + from.request_uid, + from.robot_id, + from.seeking_point_x, + from.seeking_point_y, + from.adding, + }; + } + +}; + +ASSOCIATE_CPP_ROS(strategy::communication::SeekerRequest, rj_msgs::msg::SeekerRequest); + +} \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/test_request.hpp b/soccer/src/soccer/strategy/agent/communication/test_request.hpp index 62c79a7c2e6..7252eb7894d 100644 --- a/soccer/src/soccer/strategy/agent/communication/test_request.hpp +++ b/soccer/src/soccer/strategy/agent/communication/test_request.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -7,37 +7,37 @@ #include #include - #include "rj_msgs/msg/test_request.hpp" namespace strategy::communication { struct TestRequest { - uint32_t request_uid; + uint32_t request_uid; }; bool operator==(const TestRequest& a, const TestRequest& b); void generate_uid(TestRequest& request); -} // namespace strategy::communication +} namespace rj_convert { template <> struct RosConverter { - static rj_msgs::msg::TestRequest to_ros(const strategy::communication::TestRequest& from) { - rj_msgs::msg::TestRequest result; - result.request_uid = from.request_uid; - return result; - } - - static strategy::communication::TestRequest from_ros(const rj_msgs::msg::TestRequest& from) { - return strategy::communication::TestRequest{ - from.request_uid, - }; - } + static rj_msgs::msg::TestRequest to_ros(const strategy::communication::TestRequest& from) { + rj_msgs::msg::TestRequest result; + result.request_uid = from.request_uid; + return result; + } + + static strategy::communication::TestRequest from_ros(const rj_msgs::msg::TestRequest& from) { + return strategy::communication::TestRequest{ + from.request_uid, + }; + } + }; ASSOCIATE_CPP_ROS(strategy::communication::TestRequest, rj_msgs::msg::TestRequest); -} // namespace rj_convert \ No newline at end of file +} \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/test_response.hpp b/soccer/src/soccer/strategy/agent/communication/test_response.hpp index 034cae56c99..0aa8ae838ca 100644 --- a/soccer/src/soccer/strategy/agent/communication/test_response.hpp +++ b/soccer/src/soccer/strategy/agent/communication/test_response.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -7,40 +7,40 @@ #include #include - #include "rj_msgs/msg/test_response.hpp" namespace strategy::communication { struct TestResponse { - uint32_t response_uid; - std::string message; + uint32_t response_uid; + std::string message; }; bool operator==(const TestResponse& a, const TestResponse& b); void generate_uid(TestResponse& response); -} // namespace strategy::communication +} namespace rj_convert { template <> struct RosConverter { - static rj_msgs::msg::TestResponse to_ros(const strategy::communication::TestResponse& from) { - rj_msgs::msg::TestResponse result; - result.response_uid = from.response_uid; - result.message = from.message; - return result; - } - - static strategy::communication::TestResponse from_ros(const rj_msgs::msg::TestResponse& from) { - return strategy::communication::TestResponse{ - from.response_uid, - from.message, - }; - } + static rj_msgs::msg::TestResponse to_ros(const strategy::communication::TestResponse& from) { + rj_msgs::msg::TestResponse result; + result.response_uid = from.response_uid; + result.message = from.message; + return result; + } + + static strategy::communication::TestResponse from_ros(const rj_msgs::msg::TestResponse& from) { + return strategy::communication::TestResponse{ + from.response_uid, + from.message, + }; + } + }; ASSOCIATE_CPP_ROS(strategy::communication::TestResponse, rj_msgs::msg::TestResponse); -} // namespace rj_convert \ No newline at end of file +} \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/position/offense.cpp b/soccer/src/soccer/strategy/agent/position/offense.cpp index 8d45d9e6422..351ee5aa203 100644 --- a/soccer/src/soccer/strategy/agent/position/offense.cpp +++ b/soccer/src/soccer/strategy/agent/position/offense.cpp @@ -11,6 +11,9 @@ std::optional Offense::derived_get_task(RobotIntent intent) { if (current_state_ != new_state) { reset_timeout(); SPDLOG_INFO("Robot {}: now {}", robot_id_, state_to_name(current_state_)); + if (current_state_ == SEEKING) { + broadcast_seeker_request(rj_geometry::Point{}, false); + } } current_state_ = new_state; @@ -179,7 +182,10 @@ std::optional Offense::state_to_task(RobotIntent intent) { case SEEKING_START: { // Calculate a new seeking point seeker_.reset_target(); - return seeker_.get_task(std::move(intent), last_world_state_, field_dimensions_); + seeker_.set_seeker_points(seeker_points_); + std::optional actual_intent = seeker_.get_task(std::move(intent), last_world_state_, field_dimensions_); + broadcast_seeker_request(seeker_.get_target_point(), true); + return actual_intent; } case SEEKING: { @@ -367,6 +373,14 @@ communication::PosAgentResponseWrapper Offense::receive_communication_request( comm_response.response = response; return comm_response; + } else if (const communication::SeekerRequest* seeker_request = + std::get_if(&request.request)) { + if (seeker_request->adding) { + seeker_points_[seeker_request->robot_id] + = rj_geometry::Point{seeker_request->seeking_point_x, seeker_request->seeking_point_y}; + } else { + seeker_points_.erase(seeker_request->robot_id); + } } return comm_response; @@ -559,4 +573,19 @@ rj_geometry::Point Offense::calculate_best_shot() const { } return best_shot; } + +void Offense::broadcast_seeker_request(rj_geometry::Point seeking_point, bool adding) { + communication::SeekerRequest seeker_request{}; + communication::generate_uid(seeker_request); + seeker_request.robot_id = robot_id_; + seeker_request.seeking_point_x = seeking_point.x(); + seeker_request.seeking_point_y = seeking_point.y(); + seeker_request.adding = adding; + + communication::PosAgentRequestWrapper communication_request{}; + communication_request.request = seeker_request; + communication_request.urgent = false; + communication_request.broadcast = true; + communication_request_ = communication_request; +} } // namespace strategy diff --git a/soccer/src/soccer/strategy/agent/position/offense.hpp b/soccer/src/soccer/strategy/agent/position/offense.hpp index befe696c42c..0feee0ec2a1 100644 --- a/soccer/src/soccer/strategy/agent/position/offense.hpp +++ b/soccer/src/soccer/strategy/agent/position/offense.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -231,6 +232,10 @@ class Offense : public Position { * @return the target (within the goal) that would be the most clear shot */ rj_geometry::Point calculate_best_shot() const; + + void broadcast_seeker_request(rj_geometry::Point seeking_point, bool adding); + + std::unordered_map seeker_points_; }; } // namespace strategy diff --git a/soccer/src/soccer/strategy/agent/position/seeker.cpp b/soccer/src/soccer/strategy/agent/position/seeker.cpp index 6487344fbfb..46f8403c33d 100644 --- a/soccer/src/soccer/strategy/agent/position/seeker.cpp +++ b/soccer/src/soccer/strategy/agent/position/seeker.cpp @@ -24,6 +24,14 @@ std::optional Seeker::get_task(RobotIntent intent, const WorldState void Seeker::reset_target() { target_valid_ = false; } +rj_geometry::Point Seeker::get_target_point() { + return target_pt_; +} + +void Seeker::set_seeker_points(std::unordered_map seeker_points) { + seeker_points_ = seeker_points; +} + rj_geometry::Point Seeker::get_open_point(const WorldState* world_state, rj_geometry::Point current_position, const FieldDimensions& field_dimensions) const { @@ -60,7 +68,7 @@ rj_geometry::Point Seeker::calculate_open_point(double current_prec, double min_ // Finds the best point out of the ones checked for (auto point : check_points) { - curr_val = Seeker::eval_point(ball_pos, point, world_state, field_dimensions); + curr_val = eval_point(ball_pos, point, world_state, field_dimensions); if (curr_val < min_val) { min_val = curr_val; min = point; @@ -107,35 +115,11 @@ rj_geometry::Point Seeker::correct_point(rj_geometry::Point p, } } - // Assigns robots to horizontal thirds - if (robot_id_ == 1) { - // Assign left - if (x > field_dimensions.field_x_left_coord() + field_dimensions.width() / 2) { - x = field_dimensions.field_x_left_coord() + field_dimensions.width() / 2 - - border_buffer; - } - } else if (robot_id_ == 2) { - // Assign right - if (x < field_dimensions.field_x_right_coord() - field_dimensions.width() / 2) { - x = field_dimensions.field_x_right_coord() - field_dimensions.width() / 2 + - border_buffer; - } - } else { - // Assign middle - if (x < field_dimensions.field_x_left_coord() + field_dimensions.width() / 3) { - x = field_dimensions.field_x_left_coord() + field_dimensions.width() / 3 + - border_buffer; - } else if (x > field_dimensions.field_x_right_coord() - field_dimensions.width() / 3) { - x = field_dimensions.field_x_right_coord() - field_dimensions.width() / 3 - - border_buffer; - } - } - return rj_geometry::Point(x, y); } double Seeker::eval_point(rj_geometry::Point ball_pos, rj_geometry::Point current_point, - const WorldState* world_state, const FieldDimensions& field_dimensions) { + const WorldState* world_state, const FieldDimensions& field_dimensions) const { // Determines 'how good' a point is // A higher value is a worse point @@ -207,9 +191,15 @@ double Seeker::eval_point(rj_geometry::Point ball_pos, rj_geometry::Point curren block_shot_loss = 1; } + double min_seeker_dist = std::numeric_limits::infinity(); + for (const auto & [ key, value ] : seeker_points_) { + min_seeker_dist = std::min(min_seeker_dist, current_point.dist_to(value)); + } + const double seeker_dist_loss = 0.4 * 1/min_seeker_dist; + // Final evaluation return max + ball_proximity_loss + goal_distance_loss + min_path_dist + min_robot_dist + - block_shot_loss; + block_shot_loss + seeker_dist_loss; } } // namespace strategy diff --git a/soccer/src/soccer/strategy/agent/position/seeker.hpp b/soccer/src/soccer/strategy/agent/position/seeker.hpp index abdff0a5503..5b1d760ace1 100644 --- a/soccer/src/soccer/strategy/agent/position/seeker.hpp +++ b/soccer/src/soccer/strategy/agent/position/seeker.hpp @@ -1,6 +1,8 @@ #pragma once #include +#include + #include #include @@ -37,7 +39,7 @@ class Seeker : public RoleInterface { * * @param intent The RobotIntent to add the movement to * @param world_state The current WorldState - * @param field_dimensions The dimensions of the field + * @param field_dimensions The dimensions of the fields * * @return [RobotIntent with next target point for the robot] */ @@ -46,6 +48,12 @@ class Seeker : public RoleInterface { void reset_target(); + rj_geometry::Point get_target_point(); + + + void set_seeker_points(std::unordered_map seeker_points); + + private: // The seeker's id int robot_id_; @@ -103,9 +111,11 @@ class Seeker : public RoleInterface { * * @return double The evaluation of that target point */ - static double eval_point(rj_geometry::Point ball_pos, rj_geometry::Point current_point, + [[nodiscard]] double eval_point(rj_geometry::Point ball_pos, rj_geometry::Point current_point, const WorldState* world_state, - const FieldDimensions& field_dimensions); + const FieldDimensions& field_dimensions) const; + + std::unordered_map seeker_points_ {}; }; } // namespace strategy From c879f19d1423dbd70d14063c50ece1d6983c4940 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 11 Mar 2024 00:09:04 -0400 Subject: [PATCH 2/6] Fix Code Style On fix-seeking (#2227) automated style fixes Co-authored-by: sanatd33 --- .../agent/communication/acknowledge.hpp | 31 +- .../communication/ball_in_transit_request.hpp | 45 ++- .../agent/communication/communication.cpp | 174 ++++---- .../agent/communication/communication.hpp | 372 +++++++++--------- .../communication/incoming_ball_request.hpp | 42 +- .../agent/communication/join_wall_request.hpp | 39 +- .../communication/join_wall_response.hpp | 39 +- .../communication/leave_wall_request.hpp | 39 +- .../communication/leave_wall_response.hpp | 39 +- .../agent/communication/pass_request.hpp | 43 +- .../agent/communication/pass_response.hpp | 37 +- .../agent/communication/position_request.hpp | 33 +- .../agent/communication/position_response.hpp | 39 +- .../communication/reset_scorer_request.hpp | 33 +- .../agent/communication/scorer_request.hpp | 44 +-- .../agent/communication/scorer_response.hpp | 45 +-- .../agent/communication/seeker_request.hpp | 54 ++- .../agent/communication/test_request.hpp | 31 +- .../agent/communication/test_response.hpp | 37 +- .../strategy/agent/position/offense.cpp | 13 +- .../soccer/strategy/agent/position/seeker.cpp | 11 +- .../soccer/strategy/agent/position/seeker.hpp | 9 +- 22 files changed, 636 insertions(+), 613 deletions(-) diff --git a/soccer/src/soccer/strategy/agent/communication/acknowledge.hpp b/soccer/src/soccer/strategy/agent/communication/acknowledge.hpp index 220b81a5f05..883a5a89e0b 100644 --- a/soccer/src/soccer/strategy/agent/communication/acknowledge.hpp +++ b/soccer/src/soccer/strategy/agent/communication/acknowledge.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -12,32 +12,31 @@ namespace strategy::communication { struct Acknowledge { - uint32_t response_uid; + uint32_t response_uid; }; bool operator==(const Acknowledge& a, const Acknowledge& b); void generate_uid(Acknowledge& response); -} +} // namespace strategy::communication namespace rj_convert { template <> struct RosConverter { - static rj_msgs::msg::Acknowledge to_ros(const strategy::communication::Acknowledge& from) { - rj_msgs::msg::Acknowledge result; - result.response_uid = from.response_uid; - return result; - } - - static strategy::communication::Acknowledge from_ros(const rj_msgs::msg::Acknowledge& from) { - return strategy::communication::Acknowledge{ - from.response_uid, - }; - } - + static rj_msgs::msg::Acknowledge to_ros(const strategy::communication::Acknowledge& from) { + rj_msgs::msg::Acknowledge result; + result.response_uid = from.response_uid; + return result; + } + + static strategy::communication::Acknowledge from_ros(const rj_msgs::msg::Acknowledge& from) { + return strategy::communication::Acknowledge{ + from.response_uid, + }; + } }; ASSOCIATE_CPP_ROS(strategy::communication::Acknowledge, rj_msgs::msg::Acknowledge); -} \ No newline at end of file +} // namespace rj_convert \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/ball_in_transit_request.hpp b/soccer/src/soccer/strategy/agent/communication/ball_in_transit_request.hpp index e8656a1a9b6..f2f8e1732c9 100644 --- a/soccer/src/soccer/strategy/agent/communication/ball_in_transit_request.hpp +++ b/soccer/src/soccer/strategy/agent/communication/ball_in_transit_request.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -12,35 +12,38 @@ namespace strategy::communication { struct BallInTransitRequest { - uint32_t request_uid; - uint8_t from_robot_id; + uint32_t request_uid; + uint8_t from_robot_id; }; bool operator==(const BallInTransitRequest& a, const BallInTransitRequest& b); void generate_uid(BallInTransitRequest& request); -} +} // namespace strategy::communication namespace rj_convert { template <> -struct RosConverter { - static rj_msgs::msg::BallInTransitRequest to_ros(const strategy::communication::BallInTransitRequest& from) { - rj_msgs::msg::BallInTransitRequest result; - result.request_uid = from.request_uid; - result.from_robot_id = from.from_robot_id; - return result; - } - - static strategy::communication::BallInTransitRequest from_ros(const rj_msgs::msg::BallInTransitRequest& from) { - return strategy::communication::BallInTransitRequest{ - from.request_uid, - from.from_robot_id, - }; - } - +struct RosConverter { + static rj_msgs::msg::BallInTransitRequest to_ros( + const strategy::communication::BallInTransitRequest& from) { + rj_msgs::msg::BallInTransitRequest result; + result.request_uid = from.request_uid; + result.from_robot_id = from.from_robot_id; + return result; + } + + static strategy::communication::BallInTransitRequest from_ros( + const rj_msgs::msg::BallInTransitRequest& from) { + return strategy::communication::BallInTransitRequest{ + from.request_uid, + from.from_robot_id, + }; + } }; -ASSOCIATE_CPP_ROS(strategy::communication::BallInTransitRequest, rj_msgs::msg::BallInTransitRequest); +ASSOCIATE_CPP_ROS(strategy::communication::BallInTransitRequest, + rj_msgs::msg::BallInTransitRequest); -} \ No newline at end of file +} // namespace rj_convert \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/communication.cpp b/soccer/src/soccer/strategy/agent/communication/communication.cpp index 272d77ce214..98ff78afb13 100644 --- a/soccer/src/soccer/strategy/agent/communication/communication.cpp +++ b/soccer/src/soccer/strategy/agent/communication/communication.cpp @@ -9,194 +9,194 @@ std::mutex response_uid_mutex; u_int32_t response_uid = 0; bool operator==(const LeaveWallRequest& a, const LeaveWallRequest& b) { - return a.request_uid == b.request_uid; + return a.request_uid == b.request_uid; } bool operator==(const PassRequest& a, const PassRequest& b) { - return a.request_uid == b.request_uid; + return a.request_uid == b.request_uid; } bool operator==(const SeekerRequest& a, const SeekerRequest& b) { - return a.request_uid == b.request_uid; + return a.request_uid == b.request_uid; } bool operator==(const TestRequest& a, const TestRequest& b) { - return a.request_uid == b.request_uid; + return a.request_uid == b.request_uid; } bool operator==(const BallInTransitRequest& a, const BallInTransitRequest& b) { - return a.request_uid == b.request_uid; + return a.request_uid == b.request_uid; } bool operator==(const JoinWallRequest& a, const JoinWallRequest& b) { - return a.request_uid == b.request_uid; + return a.request_uid == b.request_uid; } bool operator==(const ScorerRequest& a, const ScorerRequest& b) { - return a.request_uid == b.request_uid; + return a.request_uid == b.request_uid; } bool operator==(const IncomingBallRequest& a, const IncomingBallRequest& b) { - return a.request_uid == b.request_uid; + return a.request_uid == b.request_uid; } bool operator==(const ResetScorerRequest& a, const ResetScorerRequest& b) { - return a.request_uid == b.request_uid; + return a.request_uid == b.request_uid; } bool operator==(const PositionRequest& a, const PositionRequest& b) { - return a.request_uid == b.request_uid; + return a.request_uid == b.request_uid; } bool operator==(const LeaveWallResponse& a, const LeaveWallResponse& b) { - return a.response_uid == b.response_uid; + return a.response_uid == b.response_uid; } bool operator==(const ScorerResponse& a, const ScorerResponse& b) { - return a.response_uid == b.response_uid; + return a.response_uid == b.response_uid; } bool operator==(const JoinWallResponse& a, const JoinWallResponse& b) { - return a.response_uid == b.response_uid; + return a.response_uid == b.response_uid; } bool operator==(const Acknowledge& a, const Acknowledge& b) { - return a.response_uid == b.response_uid; + return a.response_uid == b.response_uid; } bool operator==(const PositionResponse& a, const PositionResponse& b) { - return a.response_uid == b.response_uid; + return a.response_uid == b.response_uid; } bool operator==(const PassResponse& a, const PassResponse& b) { - return a.response_uid == b.response_uid; + return a.response_uid == b.response_uid; } bool operator==(const TestResponse& a, const TestResponse& b) { - return a.response_uid == b.response_uid; + return a.response_uid == b.response_uid; } bool operator==(const AgentResponse& a, const AgentResponse& b) { - return (a.associated_request == b.associated_request) && (a.response == b.response); + return (a.associated_request == b.associated_request) && (a.response == b.response); } void generate_uid(LeaveWallRequest& request) { - request_uid_mutex.lock(); - request.request_uid = request_uid; - request_uid++; - request_uid_mutex.unlock(); + request_uid_mutex.lock(); + request.request_uid = request_uid; + request_uid++; + request_uid_mutex.unlock(); } void generate_uid(PassRequest& request) { - request_uid_mutex.lock(); - request.request_uid = request_uid; - request_uid++; - request_uid_mutex.unlock(); + request_uid_mutex.lock(); + request.request_uid = request_uid; + request_uid++; + request_uid_mutex.unlock(); } void generate_uid(SeekerRequest& request) { - request_uid_mutex.lock(); - request.request_uid = request_uid; - request_uid++; - request_uid_mutex.unlock(); + request_uid_mutex.lock(); + request.request_uid = request_uid; + request_uid++; + request_uid_mutex.unlock(); } void generate_uid(TestRequest& request) { - request_uid_mutex.lock(); - request.request_uid = request_uid; - request_uid++; - request_uid_mutex.unlock(); + request_uid_mutex.lock(); + request.request_uid = request_uid; + request_uid++; + request_uid_mutex.unlock(); } void generate_uid(BallInTransitRequest& request) { - request_uid_mutex.lock(); - request.request_uid = request_uid; - request_uid++; - request_uid_mutex.unlock(); + request_uid_mutex.lock(); + request.request_uid = request_uid; + request_uid++; + request_uid_mutex.unlock(); } void generate_uid(JoinWallRequest& request) { - request_uid_mutex.lock(); - request.request_uid = request_uid; - request_uid++; - request_uid_mutex.unlock(); + request_uid_mutex.lock(); + request.request_uid = request_uid; + request_uid++; + request_uid_mutex.unlock(); } void generate_uid(ScorerRequest& request) { - request_uid_mutex.lock(); - request.request_uid = request_uid; - request_uid++; - request_uid_mutex.unlock(); + request_uid_mutex.lock(); + request.request_uid = request_uid; + request_uid++; + request_uid_mutex.unlock(); } void generate_uid(IncomingBallRequest& request) { - request_uid_mutex.lock(); - request.request_uid = request_uid; - request_uid++; - request_uid_mutex.unlock(); + request_uid_mutex.lock(); + request.request_uid = request_uid; + request_uid++; + request_uid_mutex.unlock(); } void generate_uid(ResetScorerRequest& request) { - request_uid_mutex.lock(); - request.request_uid = request_uid; - request_uid++; - request_uid_mutex.unlock(); + request_uid_mutex.lock(); + request.request_uid = request_uid; + request_uid++; + request_uid_mutex.unlock(); } void generate_uid(PositionRequest& request) { - request_uid_mutex.lock(); - request.request_uid = request_uid; - request_uid++; - request_uid_mutex.unlock(); + request_uid_mutex.lock(); + request.request_uid = request_uid; + request_uid++; + request_uid_mutex.unlock(); } void generate_uid(LeaveWallResponse& response) { - response_uid_mutex.lock(); - response.response_uid = response_uid; - response_uid++; - response_uid_mutex.unlock(); + response_uid_mutex.lock(); + response.response_uid = response_uid; + response_uid++; + response_uid_mutex.unlock(); } void generate_uid(ScorerResponse& response) { - response_uid_mutex.lock(); - response.response_uid = response_uid; - response_uid++; - response_uid_mutex.unlock(); + response_uid_mutex.lock(); + response.response_uid = response_uid; + response_uid++; + response_uid_mutex.unlock(); } void generate_uid(JoinWallResponse& response) { - response_uid_mutex.lock(); - response.response_uid = response_uid; - response_uid++; - response_uid_mutex.unlock(); + response_uid_mutex.lock(); + response.response_uid = response_uid; + response_uid++; + response_uid_mutex.unlock(); } void generate_uid(Acknowledge& response) { - response_uid_mutex.lock(); - response.response_uid = response_uid; - response_uid++; - response_uid_mutex.unlock(); + response_uid_mutex.lock(); + response.response_uid = response_uid; + response_uid++; + response_uid_mutex.unlock(); } void generate_uid(PositionResponse& response) { - response_uid_mutex.lock(); - response.response_uid = response_uid; - response_uid++; - response_uid_mutex.unlock(); + response_uid_mutex.lock(); + response.response_uid = response_uid; + response_uid++; + response_uid_mutex.unlock(); } void generate_uid(PassResponse& response) { - response_uid_mutex.lock(); - response.response_uid = response_uid; - response_uid++; - response_uid_mutex.unlock(); + response_uid_mutex.lock(); + response.response_uid = response_uid; + response_uid++; + response_uid_mutex.unlock(); } void generate_uid(TestResponse& response) { - response_uid_mutex.lock(); - response.response_uid = response_uid; - response_uid++; - response_uid_mutex.unlock(); + response_uid_mutex.lock(); + response.response_uid = response_uid; + response_uid++; + response_uid_mutex.unlock(); } -} \ No newline at end of file +} // namespace strategy::communication \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/communication.hpp b/soccer/src/soccer/strategy/agent/communication/communication.hpp index 1f0d5491b51..c3fd0d43389 100644 --- a/soccer/src/soccer/strategy/agent/communication/communication.hpp +++ b/soccer/src/soccer/strategy/agent/communication/communication.hpp @@ -8,231 +8,251 @@ #include #include +#include "acknowledge.hpp" +#include "ball_in_transit_request.hpp" +#include "incoming_ball_request.hpp" +#include "join_wall_request.hpp" +#include "join_wall_response.hpp" +#include "leave_wall_request.hpp" +#include "leave_wall_response.hpp" +#include "pass_request.hpp" +#include "pass_response.hpp" +#include "position_request.hpp" +#include "position_response.hpp" +#include "reset_scorer_request.hpp" #include "rj_msgs/msg/agent_request.hpp" #include "rj_msgs/msg/agent_response.hpp" #include "rj_msgs/msg/agent_response_variant.hpp" -#include "leave_wall_request.hpp" -#include "pass_request.hpp" -#include "seeker_request.hpp" -#include "test_request.hpp" -#include "ball_in_transit_request.hpp" -#include "join_wall_request.hpp" #include "scorer_request.hpp" -#include "incoming_ball_request.hpp" -#include "reset_scorer_request.hpp" -#include "position_request.hpp" -#include "leave_wall_response.hpp" #include "scorer_response.hpp" -#include "join_wall_response.hpp" -#include "acknowledge.hpp" -#include "position_response.hpp" -#include "pass_response.hpp" +#include "seeker_request.hpp" +#include "test_request.hpp" #include "test_response.hpp" namespace strategy::communication { /** -* @brief a conglomeration of the different request types. -*/ -using AgentRequest = std::variant; + * @brief a conglomeration of the different request types. + */ +using AgentRequest = std::variant; /** -* @brief a conglomeration of the different response types. -*/ -using AgentResponseVariant = std::variant; + * @brief a conglomeration of the different response types. + */ +using AgentResponseVariant = + std::variant; /** -* @brief response message that is sent from the receiver of the request to the -* sender of the request with an accompanying response. -* -* The agent response is the actual thing that gets sent from a receiver back -* to the sender. -* -*/ + * @brief response message that is sent from the receiver of the request to the + * sender of the request with an accompanying response. + * + * The agent response is the actual thing that gets sent from a receiver back + * to the sender. + * + */ struct AgentResponse { - AgentRequest associated_request; - AgentResponseVariant response; + AgentRequest associated_request; + AgentResponseVariant response; }; bool operator==(const AgentResponse& a, const AgentResponse& b); /** -* @brief Wraps a communication request by giving the intended destination of the -* communication. -* -* positions will create this and send it to their agent action client which will -* send out the request according to their specifications. -* -*/ + * @brief Wraps a communication request by giving the intended destination of the + * communication. + * + * positions will create this and send it to their agent action client which will + * send out the request according to their specifications. + * + */ struct PosAgentRequestWrapper { - AgentRequest request; - std::vector target_agents; - bool broadcast; - bool urgent; + AgentRequest request; + std::vector target_agents; + bool broadcast; + bool urgent; }; /** -* @brief Wraps a communication response to ensure symmetry for agent-to-agent -* communication. -* -* this wrapper is placed on agent responses to promote symmetry across the request -* response system to make understanding easier. All this struct does is make explicit -* that this response is going from the position to the agent. -* -*/ + * @brief Wraps a communication response to ensure symmetry for agent-to-agent + * communication. + * + * this wrapper is placed on agent responses to promote symmetry across the request + * response system to make understanding easier. All this struct does is make explicit + * that this response is going from the position to the agent. + * + */ struct PosAgentResponseWrapper { - AgentResponseVariant response; + AgentResponseVariant response; }; /** -* @brief Wraps a communication request to ensure symmetry for agent-to-agent -* communication. -* -* Like the PosAgentResponseWrapper, this struct does nothing other than make the request -* response system more symmetrical and (hopefully) more easy to understand. All this struct -* does is make it explicit that this request is being passed from the agent to the agent to -* the position. -* -*/ + * @brief Wraps a communication request to ensure symmetry for agent-to-agent + * communication. + * + * Like the PosAgentResponseWrapper, this struct does nothing other than make the request + * response system more symmetrical and (hopefully) more easy to understand. All this struct + * does is make it explicit that this request is being passed from the agent to the agent to + * the position. + * + */ struct AgentPosRequestWrapper { - AgentRequest request; + AgentRequest request; }; /** -* @brief Wraps a communication response by giving the robot the communication is from. -* -* the AgentPosResponseWrapper is the actual thing being passed from the agent to the position -* once either the timeout period was reached or enough responses were received. Ideally, the -* contents of this wrapper should contain all of the non-message specific fields that a position -* will need to handle a response. -* -*/ + * @brief Wraps a communication response by giving the robot the communication is from. + * + * the AgentPosResponseWrapper is the actual thing being passed from the agent to the position + * once either the timeout period was reached or enough responses were received. Ideally, the + * contents of this wrapper should contain all of the non-message specific fields that a position + * will need to handle a response. + * + */ struct AgentPosResponseWrapper { - AgentRequest associated_request; - std::vector to_robot_ids; - std::vector received_robot_ids; - bool broadcast; - bool urgent; - RJ::Time created; - std::vector responses; + AgentRequest associated_request; + std::vector to_robot_ids; + std::vector received_robot_ids; + bool broadcast; + bool urgent; + RJ::Time created; + std::vector responses; }; -} +} // namespace strategy::communication namespace rj_convert { template <> struct RosConverter { - static rj_msgs::msg::AgentRequest to_ros(const strategy::communication::AgentRequest& from) { - rj_msgs::msg::AgentRequest result; - if (const auto* leave_wall_request = std::get_if(&from)) { - result.leave_wall_request.emplace_back(convert_to_ros(*leave_wall_request)); - } else if (const auto* pass_request = std::get_if(&from)) { - result.pass_request.emplace_back(convert_to_ros(*pass_request)); - } else if (const auto* seeker_request = std::get_if(&from)) { - result.seeker_request.emplace_back(convert_to_ros(*seeker_request)); - } else if (const auto* test_request = std::get_if(&from)) { - result.test_request.emplace_back(convert_to_ros(*test_request)); - } else if (const auto* ball_in_transit_request = std::get_if(&from)) { - result.ball_in_transit_request.emplace_back(convert_to_ros(*ball_in_transit_request)); - } else if (const auto* join_wall_request = std::get_if(&from)) { - result.join_wall_request.emplace_back(convert_to_ros(*join_wall_request)); - } else if (const auto* scorer_request = std::get_if(&from)) { - result.scorer_request.emplace_back(convert_to_ros(*scorer_request)); - } else if (const auto* incoming_ball_request = std::get_if(&from)) { - result.incoming_ball_request.emplace_back(convert_to_ros(*incoming_ball_request)); - } else if (const auto* reset_scorer_request = std::get_if(&from)) { - result.reset_scorer_request.emplace_back(convert_to_ros(*reset_scorer_request)); - } else if (const auto* position_request = std::get_if(&from)) { - result.position_request.emplace_back(convert_to_ros(*position_request)); - } else { - throw std::runtime_error("Invalid variant of AgentRequest"); - } - return result; - } - - static strategy::communication::AgentRequest from_ros(const rj_msgs::msg::AgentRequest& from) { - strategy::communication::AgentRequest result; - if (!from.leave_wall_request.empty()) { - result = convert_from_ros(from.leave_wall_request.front()); - } else if (!from.pass_request.empty()) { - result = convert_from_ros(from.pass_request.front()); - } else if (!from.seeker_request.empty()) { - result = convert_from_ros(from.seeker_request.front()); - } else if (!from.test_request.empty()) { - result = convert_from_ros(from.test_request.front()); - } else if (!from.ball_in_transit_request.empty()) { - result = convert_from_ros(from.ball_in_transit_request.front()); - } else if (!from.join_wall_request.empty()) { - result = convert_from_ros(from.join_wall_request.front()); - } else if (!from.scorer_request.empty()) { - result = convert_from_ros(from.scorer_request.front()); - } else if (!from.incoming_ball_request.empty()) { - result = convert_from_ros(from.incoming_ball_request.front()); - } else if (!from.reset_scorer_request.empty()) { - result = convert_from_ros(from.reset_scorer_request.front()); - } else if (!from.position_request.empty()) { - result = convert_from_ros(from.position_request.front()); - } else { - throw std::runtime_error("Invalid variant of AgentRequest"); - } - return result; - } + static rj_msgs::msg::AgentRequest to_ros(const strategy::communication::AgentRequest& from) { + rj_msgs::msg::AgentRequest result; + if (const auto* leave_wall_request = + std::get_if(&from)) { + result.leave_wall_request.emplace_back(convert_to_ros(*leave_wall_request)); + } else if (const auto* pass_request = + std::get_if(&from)) { + result.pass_request.emplace_back(convert_to_ros(*pass_request)); + } else if (const auto* seeker_request = + std::get_if(&from)) { + result.seeker_request.emplace_back(convert_to_ros(*seeker_request)); + } else if (const auto* test_request = + std::get_if(&from)) { + result.test_request.emplace_back(convert_to_ros(*test_request)); + } else if (const auto* ball_in_transit_request = + std::get_if(&from)) { + result.ball_in_transit_request.emplace_back(convert_to_ros(*ball_in_transit_request)); + } else if (const auto* join_wall_request = + std::get_if(&from)) { + result.join_wall_request.emplace_back(convert_to_ros(*join_wall_request)); + } else if (const auto* scorer_request = + std::get_if(&from)) { + result.scorer_request.emplace_back(convert_to_ros(*scorer_request)); + } else if (const auto* incoming_ball_request = + std::get_if(&from)) { + result.incoming_ball_request.emplace_back(convert_to_ros(*incoming_ball_request)); + } else if (const auto* reset_scorer_request = + std::get_if(&from)) { + result.reset_scorer_request.emplace_back(convert_to_ros(*reset_scorer_request)); + } else if (const auto* position_request = + std::get_if(&from)) { + result.position_request.emplace_back(convert_to_ros(*position_request)); + } else { + throw std::runtime_error("Invalid variant of AgentRequest"); + } + return result; + } + static strategy::communication::AgentRequest from_ros(const rj_msgs::msg::AgentRequest& from) { + strategy::communication::AgentRequest result; + if (!from.leave_wall_request.empty()) { + result = convert_from_ros(from.leave_wall_request.front()); + } else if (!from.pass_request.empty()) { + result = convert_from_ros(from.pass_request.front()); + } else if (!from.seeker_request.empty()) { + result = convert_from_ros(from.seeker_request.front()); + } else if (!from.test_request.empty()) { + result = convert_from_ros(from.test_request.front()); + } else if (!from.ball_in_transit_request.empty()) { + result = convert_from_ros(from.ball_in_transit_request.front()); + } else if (!from.join_wall_request.empty()) { + result = convert_from_ros(from.join_wall_request.front()); + } else if (!from.scorer_request.empty()) { + result = convert_from_ros(from.scorer_request.front()); + } else if (!from.incoming_ball_request.empty()) { + result = convert_from_ros(from.incoming_ball_request.front()); + } else if (!from.reset_scorer_request.empty()) { + result = convert_from_ros(from.reset_scorer_request.front()); + } else if (!from.position_request.empty()) { + result = convert_from_ros(from.position_request.front()); + } else { + throw std::runtime_error("Invalid variant of AgentRequest"); + } + return result; + } }; ASSOCIATE_CPP_ROS(strategy::communication::AgentRequest, rj_msgs::msg::AgentRequest); template <> struct RosConverter { - static rj_msgs::msg::AgentResponse to_ros(const strategy::communication::AgentResponse& from) { - rj_msgs::msg::AgentResponse result; - result.associated_request = convert_to_ros(from.associated_request); - if (const auto* leave_wall_response = std::get_if(&(from.response))) { - result.response.leave_wall_response.emplace_back(convert_to_ros(*leave_wall_response)); - } else if (const auto* scorer_response = std::get_if(&(from.response))) { - result.response.scorer_response.emplace_back(convert_to_ros(*scorer_response)); - } else if (const auto* join_wall_response = std::get_if(&(from.response))) { - result.response.join_wall_response.emplace_back(convert_to_ros(*join_wall_response)); - } else if (const auto* acknowledge = std::get_if(&(from.response))) { - result.response.acknowledge.emplace_back(convert_to_ros(*acknowledge)); - } else if (const auto* position_response = std::get_if(&(from.response))) { - result.response.position_response.emplace_back(convert_to_ros(*position_response)); - } else if (const auto* pass_response = std::get_if(&(from.response))) { - result.response.pass_response.emplace_back(convert_to_ros(*pass_response)); - } else if (const auto* test_response = std::get_if(&(from.response))) { - result.response.test_response.emplace_back(convert_to_ros(*test_response)); - } else { - throw std::runtime_error("Invalid variant of AgentResponse"); - } - return result; - } - - static strategy::communication::AgentResponse from_ros(const rj_msgs::msg::AgentResponse& from) { - strategy::communication::AgentResponse result; - result.associated_request = convert_from_ros(from.associated_request); - if (!from.response.leave_wall_response.empty()) { - result.response = convert_from_ros(from.response.leave_wall_response.front()); - } else if (!from.response.scorer_response.empty()) { - result.response = convert_from_ros(from.response.scorer_response.front()); - } else if (!from.response.join_wall_response.empty()) { - result.response = convert_from_ros(from.response.join_wall_response.front()); - } else if (!from.response.acknowledge.empty()) { - result.response = convert_from_ros(from.response.acknowledge.front()); - } else if (!from.response.position_response.empty()) { - result.response = convert_from_ros(from.response.position_response.front()); - } else if (!from.response.pass_response.empty()) { - result.response = convert_from_ros(from.response.pass_response.front()); - } else if (!from.response.test_response.empty()) { - result.response = convert_from_ros(from.response.test_response.front()); - } else { - throw std::runtime_error("Invalid variant of AgentResponse"); - } - return result; - } + static rj_msgs::msg::AgentResponse to_ros(const strategy::communication::AgentResponse& from) { + rj_msgs::msg::AgentResponse result; + result.associated_request = convert_to_ros(from.associated_request); + if (const auto* leave_wall_response = + std::get_if(&(from.response))) { + result.response.leave_wall_response.emplace_back(convert_to_ros(*leave_wall_response)); + } else if (const auto* scorer_response = + std::get_if(&(from.response))) { + result.response.scorer_response.emplace_back(convert_to_ros(*scorer_response)); + } else if (const auto* join_wall_response = + std::get_if(&(from.response))) { + result.response.join_wall_response.emplace_back(convert_to_ros(*join_wall_response)); + } else if (const auto* acknowledge = + std::get_if(&(from.response))) { + result.response.acknowledge.emplace_back(convert_to_ros(*acknowledge)); + } else if (const auto* position_response = + std::get_if(&(from.response))) { + result.response.position_response.emplace_back(convert_to_ros(*position_response)); + } else if (const auto* pass_response = + std::get_if(&(from.response))) { + result.response.pass_response.emplace_back(convert_to_ros(*pass_response)); + } else if (const auto* test_response = + std::get_if(&(from.response))) { + result.response.test_response.emplace_back(convert_to_ros(*test_response)); + } else { + throw std::runtime_error("Invalid variant of AgentResponse"); + } + return result; + } + static strategy::communication::AgentResponse from_ros( + const rj_msgs::msg::AgentResponse& from) { + strategy::communication::AgentResponse result; + result.associated_request = convert_from_ros(from.associated_request); + if (!from.response.leave_wall_response.empty()) { + result.response = convert_from_ros(from.response.leave_wall_response.front()); + } else if (!from.response.scorer_response.empty()) { + result.response = convert_from_ros(from.response.scorer_response.front()); + } else if (!from.response.join_wall_response.empty()) { + result.response = convert_from_ros(from.response.join_wall_response.front()); + } else if (!from.response.acknowledge.empty()) { + result.response = convert_from_ros(from.response.acknowledge.front()); + } else if (!from.response.position_response.empty()) { + result.response = convert_from_ros(from.response.position_response.front()); + } else if (!from.response.pass_response.empty()) { + result.response = convert_from_ros(from.response.pass_response.front()); + } else if (!from.response.test_response.empty()) { + result.response = convert_from_ros(from.response.test_response.front()); + } else { + throw std::runtime_error("Invalid variant of AgentResponse"); + } + return result; + } }; ASSOCIATE_CPP_ROS(strategy::communication::AgentResponse, rj_msgs::msg::AgentResponse); -} \ No newline at end of file +} // namespace rj_convert \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/incoming_ball_request.hpp b/soccer/src/soccer/strategy/agent/communication/incoming_ball_request.hpp index 124a4fded83..a7d5007b960 100644 --- a/soccer/src/soccer/strategy/agent/communication/incoming_ball_request.hpp +++ b/soccer/src/soccer/strategy/agent/communication/incoming_ball_request.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -12,35 +12,37 @@ namespace strategy::communication { struct IncomingBallRequest { - uint32_t request_uid; - uint8_t from_robot_id; + uint32_t request_uid; + uint8_t from_robot_id; }; bool operator==(const IncomingBallRequest& a, const IncomingBallRequest& b); void generate_uid(IncomingBallRequest& request); -} +} // namespace strategy::communication namespace rj_convert { template <> -struct RosConverter { - static rj_msgs::msg::IncomingBallRequest to_ros(const strategy::communication::IncomingBallRequest& from) { - rj_msgs::msg::IncomingBallRequest result; - result.request_uid = from.request_uid; - result.from_robot_id = from.from_robot_id; - return result; - } - - static strategy::communication::IncomingBallRequest from_ros(const rj_msgs::msg::IncomingBallRequest& from) { - return strategy::communication::IncomingBallRequest{ - from.request_uid, - from.from_robot_id, - }; - } - +struct RosConverter { + static rj_msgs::msg::IncomingBallRequest to_ros( + const strategy::communication::IncomingBallRequest& from) { + rj_msgs::msg::IncomingBallRequest result; + result.request_uid = from.request_uid; + result.from_robot_id = from.from_robot_id; + return result; + } + + static strategy::communication::IncomingBallRequest from_ros( + const rj_msgs::msg::IncomingBallRequest& from) { + return strategy::communication::IncomingBallRequest{ + from.request_uid, + from.from_robot_id, + }; + } }; ASSOCIATE_CPP_ROS(strategy::communication::IncomingBallRequest, rj_msgs::msg::IncomingBallRequest); -} \ No newline at end of file +} // namespace rj_convert \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/join_wall_request.hpp b/soccer/src/soccer/strategy/agent/communication/join_wall_request.hpp index c8ba299419b..c3ee114ebb0 100644 --- a/soccer/src/soccer/strategy/agent/communication/join_wall_request.hpp +++ b/soccer/src/soccer/strategy/agent/communication/join_wall_request.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -12,35 +12,36 @@ namespace strategy::communication { struct JoinWallRequest { - uint32_t request_uid; - uint8_t robot_id; + uint32_t request_uid; + uint8_t robot_id; }; bool operator==(const JoinWallRequest& a, const JoinWallRequest& b); void generate_uid(JoinWallRequest& request); -} +} // namespace strategy::communication namespace rj_convert { template <> struct RosConverter { - static rj_msgs::msg::JoinWallRequest to_ros(const strategy::communication::JoinWallRequest& from) { - rj_msgs::msg::JoinWallRequest result; - result.request_uid = from.request_uid; - result.robot_id = from.robot_id; - return result; - } - - static strategy::communication::JoinWallRequest from_ros(const rj_msgs::msg::JoinWallRequest& from) { - return strategy::communication::JoinWallRequest{ - from.request_uid, - from.robot_id, - }; - } - + static rj_msgs::msg::JoinWallRequest to_ros( + const strategy::communication::JoinWallRequest& from) { + rj_msgs::msg::JoinWallRequest result; + result.request_uid = from.request_uid; + result.robot_id = from.robot_id; + return result; + } + + static strategy::communication::JoinWallRequest from_ros( + const rj_msgs::msg::JoinWallRequest& from) { + return strategy::communication::JoinWallRequest{ + from.request_uid, + from.robot_id, + }; + } }; ASSOCIATE_CPP_ROS(strategy::communication::JoinWallRequest, rj_msgs::msg::JoinWallRequest); -} \ No newline at end of file +} // namespace rj_convert \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/join_wall_response.hpp b/soccer/src/soccer/strategy/agent/communication/join_wall_response.hpp index 8e86bd0c6bb..6de5f098c3d 100644 --- a/soccer/src/soccer/strategy/agent/communication/join_wall_response.hpp +++ b/soccer/src/soccer/strategy/agent/communication/join_wall_response.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -12,35 +12,36 @@ namespace strategy::communication { struct JoinWallResponse { - uint32_t response_uid; - uint8_t robot_id; + uint32_t response_uid; + uint8_t robot_id; }; bool operator==(const JoinWallResponse& a, const JoinWallResponse& b); void generate_uid(JoinWallResponse& response); -} +} // namespace strategy::communication namespace rj_convert { template <> struct RosConverter { - static rj_msgs::msg::JoinWallResponse to_ros(const strategy::communication::JoinWallResponse& from) { - rj_msgs::msg::JoinWallResponse result; - result.response_uid = from.response_uid; - result.robot_id = from.robot_id; - return result; - } - - static strategy::communication::JoinWallResponse from_ros(const rj_msgs::msg::JoinWallResponse& from) { - return strategy::communication::JoinWallResponse{ - from.response_uid, - from.robot_id, - }; - } - + static rj_msgs::msg::JoinWallResponse to_ros( + const strategy::communication::JoinWallResponse& from) { + rj_msgs::msg::JoinWallResponse result; + result.response_uid = from.response_uid; + result.robot_id = from.robot_id; + return result; + } + + static strategy::communication::JoinWallResponse from_ros( + const rj_msgs::msg::JoinWallResponse& from) { + return strategy::communication::JoinWallResponse{ + from.response_uid, + from.robot_id, + }; + } }; ASSOCIATE_CPP_ROS(strategy::communication::JoinWallResponse, rj_msgs::msg::JoinWallResponse); -} \ No newline at end of file +} // namespace rj_convert \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/leave_wall_request.hpp b/soccer/src/soccer/strategy/agent/communication/leave_wall_request.hpp index 6b67d9b6942..b78d7d8206a 100644 --- a/soccer/src/soccer/strategy/agent/communication/leave_wall_request.hpp +++ b/soccer/src/soccer/strategy/agent/communication/leave_wall_request.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -12,35 +12,36 @@ namespace strategy::communication { struct LeaveWallRequest { - uint32_t request_uid; - uint8_t robot_id; + uint32_t request_uid; + uint8_t robot_id; }; bool operator==(const LeaveWallRequest& a, const LeaveWallRequest& b); void generate_uid(LeaveWallRequest& request); -} +} // namespace strategy::communication namespace rj_convert { template <> struct RosConverter { - static rj_msgs::msg::LeaveWallRequest to_ros(const strategy::communication::LeaveWallRequest& from) { - rj_msgs::msg::LeaveWallRequest result; - result.request_uid = from.request_uid; - result.robot_id = from.robot_id; - return result; - } - - static strategy::communication::LeaveWallRequest from_ros(const rj_msgs::msg::LeaveWallRequest& from) { - return strategy::communication::LeaveWallRequest{ - from.request_uid, - from.robot_id, - }; - } - + static rj_msgs::msg::LeaveWallRequest to_ros( + const strategy::communication::LeaveWallRequest& from) { + rj_msgs::msg::LeaveWallRequest result; + result.request_uid = from.request_uid; + result.robot_id = from.robot_id; + return result; + } + + static strategy::communication::LeaveWallRequest from_ros( + const rj_msgs::msg::LeaveWallRequest& from) { + return strategy::communication::LeaveWallRequest{ + from.request_uid, + from.robot_id, + }; + } }; ASSOCIATE_CPP_ROS(strategy::communication::LeaveWallRequest, rj_msgs::msg::LeaveWallRequest); -} \ No newline at end of file +} // namespace rj_convert \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/leave_wall_response.hpp b/soccer/src/soccer/strategy/agent/communication/leave_wall_response.hpp index 4a5c26ce6f8..d0f14d6d312 100644 --- a/soccer/src/soccer/strategy/agent/communication/leave_wall_response.hpp +++ b/soccer/src/soccer/strategy/agent/communication/leave_wall_response.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -12,35 +12,36 @@ namespace strategy::communication { struct LeaveWallResponse { - uint32_t response_uid; - uint8_t robot_id; + uint32_t response_uid; + uint8_t robot_id; }; bool operator==(const LeaveWallResponse& a, const LeaveWallResponse& b); void generate_uid(LeaveWallResponse& response); -} +} // namespace strategy::communication namespace rj_convert { template <> struct RosConverter { - static rj_msgs::msg::LeaveWallResponse to_ros(const strategy::communication::LeaveWallResponse& from) { - rj_msgs::msg::LeaveWallResponse result; - result.response_uid = from.response_uid; - result.robot_id = from.robot_id; - return result; - } - - static strategy::communication::LeaveWallResponse from_ros(const rj_msgs::msg::LeaveWallResponse& from) { - return strategy::communication::LeaveWallResponse{ - from.response_uid, - from.robot_id, - }; - } - + static rj_msgs::msg::LeaveWallResponse to_ros( + const strategy::communication::LeaveWallResponse& from) { + rj_msgs::msg::LeaveWallResponse result; + result.response_uid = from.response_uid; + result.robot_id = from.robot_id; + return result; + } + + static strategy::communication::LeaveWallResponse from_ros( + const rj_msgs::msg::LeaveWallResponse& from) { + return strategy::communication::LeaveWallResponse{ + from.response_uid, + from.robot_id, + }; + } }; ASSOCIATE_CPP_ROS(strategy::communication::LeaveWallResponse, rj_msgs::msg::LeaveWallResponse); -} \ No newline at end of file +} // namespace rj_convert \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/pass_request.hpp b/soccer/src/soccer/strategy/agent/communication/pass_request.hpp index 3fd41d95a59..68f7f104c4d 100644 --- a/soccer/src/soccer/strategy/agent/communication/pass_request.hpp +++ b/soccer/src/soccer/strategy/agent/communication/pass_request.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -12,38 +12,37 @@ namespace strategy::communication { struct PassRequest { - uint32_t request_uid; - bool direct; - uint8_t from_robot_id; + uint32_t request_uid; + bool direct; + uint8_t from_robot_id; }; bool operator==(const PassRequest& a, const PassRequest& b); void generate_uid(PassRequest& request); -} +} // namespace strategy::communication namespace rj_convert { template <> struct RosConverter { - static rj_msgs::msg::PassRequest to_ros(const strategy::communication::PassRequest& from) { - rj_msgs::msg::PassRequest result; - result.request_uid = from.request_uid; - result.direct = from.direct; - result.from_robot_id = from.from_robot_id; - return result; - } - - static strategy::communication::PassRequest from_ros(const rj_msgs::msg::PassRequest& from) { - return strategy::communication::PassRequest{ - from.request_uid, - from.direct, - from.from_robot_id, - }; - } - + static rj_msgs::msg::PassRequest to_ros(const strategy::communication::PassRequest& from) { + rj_msgs::msg::PassRequest result; + result.request_uid = from.request_uid; + result.direct = from.direct; + result.from_robot_id = from.from_robot_id; + return result; + } + + static strategy::communication::PassRequest from_ros(const rj_msgs::msg::PassRequest& from) { + return strategy::communication::PassRequest{ + from.request_uid, + from.direct, + from.from_robot_id, + }; + } }; ASSOCIATE_CPP_ROS(strategy::communication::PassRequest, rj_msgs::msg::PassRequest); -} \ No newline at end of file +} // namespace rj_convert \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/pass_response.hpp b/soccer/src/soccer/strategy/agent/communication/pass_response.hpp index f8e3f4739cf..dd984694ea7 100644 --- a/soccer/src/soccer/strategy/agent/communication/pass_response.hpp +++ b/soccer/src/soccer/strategy/agent/communication/pass_response.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -12,35 +12,34 @@ namespace strategy::communication { struct PassResponse { - uint32_t response_uid; - bool direct_open; + uint32_t response_uid; + bool direct_open; }; bool operator==(const PassResponse& a, const PassResponse& b); void generate_uid(PassResponse& response); -} +} // namespace strategy::communication namespace rj_convert { template <> struct RosConverter { - static rj_msgs::msg::PassResponse to_ros(const strategy::communication::PassResponse& from) { - rj_msgs::msg::PassResponse result; - result.response_uid = from.response_uid; - result.direct_open = from.direct_open; - return result; - } - - static strategy::communication::PassResponse from_ros(const rj_msgs::msg::PassResponse& from) { - return strategy::communication::PassResponse{ - from.response_uid, - from.direct_open, - }; - } - + static rj_msgs::msg::PassResponse to_ros(const strategy::communication::PassResponse& from) { + rj_msgs::msg::PassResponse result; + result.response_uid = from.response_uid; + result.direct_open = from.direct_open; + return result; + } + + static strategy::communication::PassResponse from_ros(const rj_msgs::msg::PassResponse& from) { + return strategy::communication::PassResponse{ + from.response_uid, + from.direct_open, + }; + } }; ASSOCIATE_CPP_ROS(strategy::communication::PassResponse, rj_msgs::msg::PassResponse); -} \ No newline at end of file +} // namespace rj_convert \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/position_request.hpp b/soccer/src/soccer/strategy/agent/communication/position_request.hpp index cd0552519db..fa90964c196 100644 --- a/soccer/src/soccer/strategy/agent/communication/position_request.hpp +++ b/soccer/src/soccer/strategy/agent/communication/position_request.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -12,32 +12,33 @@ namespace strategy::communication { struct PositionRequest { - uint32_t request_uid; + uint32_t request_uid; }; bool operator==(const PositionRequest& a, const PositionRequest& b); void generate_uid(PositionRequest& request); -} +} // namespace strategy::communication namespace rj_convert { template <> struct RosConverter { - static rj_msgs::msg::PositionRequest to_ros(const strategy::communication::PositionRequest& from) { - rj_msgs::msg::PositionRequest result; - result.request_uid = from.request_uid; - return result; - } - - static strategy::communication::PositionRequest from_ros(const rj_msgs::msg::PositionRequest& from) { - return strategy::communication::PositionRequest{ - from.request_uid, - }; - } - + static rj_msgs::msg::PositionRequest to_ros( + const strategy::communication::PositionRequest& from) { + rj_msgs::msg::PositionRequest result; + result.request_uid = from.request_uid; + return result; + } + + static strategy::communication::PositionRequest from_ros( + const rj_msgs::msg::PositionRequest& from) { + return strategy::communication::PositionRequest{ + from.request_uid, + }; + } }; ASSOCIATE_CPP_ROS(strategy::communication::PositionRequest, rj_msgs::msg::PositionRequest); -} \ No newline at end of file +} // namespace rj_convert \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/position_response.hpp b/soccer/src/soccer/strategy/agent/communication/position_response.hpp index 46dd539551e..b380b6bf45b 100644 --- a/soccer/src/soccer/strategy/agent/communication/position_response.hpp +++ b/soccer/src/soccer/strategy/agent/communication/position_response.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -12,35 +12,36 @@ namespace strategy::communication { struct PositionResponse { - uint32_t response_uid; - std::string position; + uint32_t response_uid; + std::string position; }; bool operator==(const PositionResponse& a, const PositionResponse& b); void generate_uid(PositionResponse& response); -} +} // namespace strategy::communication namespace rj_convert { template <> struct RosConverter { - static rj_msgs::msg::PositionResponse to_ros(const strategy::communication::PositionResponse& from) { - rj_msgs::msg::PositionResponse result; - result.response_uid = from.response_uid; - result.position = from.position; - return result; - } - - static strategy::communication::PositionResponse from_ros(const rj_msgs::msg::PositionResponse& from) { - return strategy::communication::PositionResponse{ - from.response_uid, - from.position, - }; - } - + static rj_msgs::msg::PositionResponse to_ros( + const strategy::communication::PositionResponse& from) { + rj_msgs::msg::PositionResponse result; + result.response_uid = from.response_uid; + result.position = from.position; + return result; + } + + static strategy::communication::PositionResponse from_ros( + const rj_msgs::msg::PositionResponse& from) { + return strategy::communication::PositionResponse{ + from.response_uid, + from.position, + }; + } }; ASSOCIATE_CPP_ROS(strategy::communication::PositionResponse, rj_msgs::msg::PositionResponse); -} \ No newline at end of file +} // namespace rj_convert \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/reset_scorer_request.hpp b/soccer/src/soccer/strategy/agent/communication/reset_scorer_request.hpp index dd7d18d3949..4933c621494 100644 --- a/soccer/src/soccer/strategy/agent/communication/reset_scorer_request.hpp +++ b/soccer/src/soccer/strategy/agent/communication/reset_scorer_request.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -12,32 +12,33 @@ namespace strategy::communication { struct ResetScorerRequest { - uint32_t request_uid; + uint32_t request_uid; }; bool operator==(const ResetScorerRequest& a, const ResetScorerRequest& b); void generate_uid(ResetScorerRequest& request); -} +} // namespace strategy::communication namespace rj_convert { template <> struct RosConverter { - static rj_msgs::msg::ResetScorerRequest to_ros(const strategy::communication::ResetScorerRequest& from) { - rj_msgs::msg::ResetScorerRequest result; - result.request_uid = from.request_uid; - return result; - } - - static strategy::communication::ResetScorerRequest from_ros(const rj_msgs::msg::ResetScorerRequest& from) { - return strategy::communication::ResetScorerRequest{ - from.request_uid, - }; - } - + static rj_msgs::msg::ResetScorerRequest to_ros( + const strategy::communication::ResetScorerRequest& from) { + rj_msgs::msg::ResetScorerRequest result; + result.request_uid = from.request_uid; + return result; + } + + static strategy::communication::ResetScorerRequest from_ros( + const rj_msgs::msg::ResetScorerRequest& from) { + return strategy::communication::ResetScorerRequest{ + from.request_uid, + }; + } }; ASSOCIATE_CPP_ROS(strategy::communication::ResetScorerRequest, rj_msgs::msg::ResetScorerRequest); -} \ No newline at end of file +} // namespace rj_convert \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/scorer_request.hpp b/soccer/src/soccer/strategy/agent/communication/scorer_request.hpp index 2882e161204..40e9a1500e4 100644 --- a/soccer/src/soccer/strategy/agent/communication/scorer_request.hpp +++ b/soccer/src/soccer/strategy/agent/communication/scorer_request.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -12,38 +12,38 @@ namespace strategy::communication { struct ScorerRequest { - uint32_t request_uid; - uint8_t robot_id; - double ball_distance; + uint32_t request_uid; + uint8_t robot_id; + double ball_distance; }; bool operator==(const ScorerRequest& a, const ScorerRequest& b); void generate_uid(ScorerRequest& request); -} +} // namespace strategy::communication namespace rj_convert { template <> struct RosConverter { - static rj_msgs::msg::ScorerRequest to_ros(const strategy::communication::ScorerRequest& from) { - rj_msgs::msg::ScorerRequest result; - result.request_uid = from.request_uid; - result.robot_id = from.robot_id; - result.ball_distance = from.ball_distance; - return result; - } - - static strategy::communication::ScorerRequest from_ros(const rj_msgs::msg::ScorerRequest& from) { - return strategy::communication::ScorerRequest{ - from.request_uid, - from.robot_id, - from.ball_distance, - }; - } - + static rj_msgs::msg::ScorerRequest to_ros(const strategy::communication::ScorerRequest& from) { + rj_msgs::msg::ScorerRequest result; + result.request_uid = from.request_uid; + result.robot_id = from.robot_id; + result.ball_distance = from.ball_distance; + return result; + } + + static strategy::communication::ScorerRequest from_ros( + const rj_msgs::msg::ScorerRequest& from) { + return strategy::communication::ScorerRequest{ + from.request_uid, + from.robot_id, + from.ball_distance, + }; + } }; ASSOCIATE_CPP_ROS(strategy::communication::ScorerRequest, rj_msgs::msg::ScorerRequest); -} \ No newline at end of file +} // namespace rj_convert \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/scorer_response.hpp b/soccer/src/soccer/strategy/agent/communication/scorer_response.hpp index 0683769c248..46491de34eb 100644 --- a/soccer/src/soccer/strategy/agent/communication/scorer_response.hpp +++ b/soccer/src/soccer/strategy/agent/communication/scorer_response.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -12,38 +12,39 @@ namespace strategy::communication { struct ScorerResponse { - uint32_t response_uid; - uint8_t robot_id; - double ball_distance; + uint32_t response_uid; + uint8_t robot_id; + double ball_distance; }; bool operator==(const ScorerResponse& a, const ScorerResponse& b); void generate_uid(ScorerResponse& response); -} +} // namespace strategy::communication namespace rj_convert { template <> struct RosConverter { - static rj_msgs::msg::ScorerResponse to_ros(const strategy::communication::ScorerResponse& from) { - rj_msgs::msg::ScorerResponse result; - result.response_uid = from.response_uid; - result.robot_id = from.robot_id; - result.ball_distance = from.ball_distance; - return result; - } - - static strategy::communication::ScorerResponse from_ros(const rj_msgs::msg::ScorerResponse& from) { - return strategy::communication::ScorerResponse{ - from.response_uid, - from.robot_id, - from.ball_distance, - }; - } - + static rj_msgs::msg::ScorerResponse to_ros( + const strategy::communication::ScorerResponse& from) { + rj_msgs::msg::ScorerResponse result; + result.response_uid = from.response_uid; + result.robot_id = from.robot_id; + result.ball_distance = from.ball_distance; + return result; + } + + static strategy::communication::ScorerResponse from_ros( + const rj_msgs::msg::ScorerResponse& from) { + return strategy::communication::ScorerResponse{ + from.response_uid, + from.robot_id, + from.ball_distance, + }; + } }; ASSOCIATE_CPP_ROS(strategy::communication::ScorerResponse, rj_msgs::msg::ScorerResponse); -} \ No newline at end of file +} // namespace rj_convert \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/seeker_request.hpp b/soccer/src/soccer/strategy/agent/communication/seeker_request.hpp index d3de172b771..e71f05994a0 100644 --- a/soccer/src/soccer/strategy/agent/communication/seeker_request.hpp +++ b/soccer/src/soccer/strategy/agent/communication/seeker_request.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -7,49 +7,47 @@ #include #include + #include "rj_msgs/msg/seeker_request.hpp" namespace strategy::communication { struct SeekerRequest { - uint32_t request_uid; - uint8_t robot_id; - double seeking_point_x; - double seeking_point_y; - bool adding; + uint32_t request_uid; + uint8_t robot_id; + double seeking_point_x; + double seeking_point_y; + bool adding; }; bool operator==(const SeekerRequest& a, const SeekerRequest& b); void generate_uid(SeekerRequest& request); -} +} // namespace strategy::communication namespace rj_convert { template <> struct RosConverter { - static rj_msgs::msg::SeekerRequest to_ros(const strategy::communication::SeekerRequest& from) { - rj_msgs::msg::SeekerRequest result; - result.request_uid = from.request_uid; - result.robot_id = from.robot_id; - result.seeking_point_x = from.seeking_point_x; - result.seeking_point_y = from.seeking_point_y; - result.adding = from.adding; - return result; - } - - static strategy::communication::SeekerRequest from_ros(const rj_msgs::msg::SeekerRequest& from) { - return strategy::communication::SeekerRequest{ - from.request_uid, - from.robot_id, - from.seeking_point_x, - from.seeking_point_y, - from.adding, - }; - } - + static rj_msgs::msg::SeekerRequest to_ros(const strategy::communication::SeekerRequest& from) { + rj_msgs::msg::SeekerRequest result; + result.request_uid = from.request_uid; + result.robot_id = from.robot_id; + result.seeking_point_x = from.seeking_point_x; + result.seeking_point_y = from.seeking_point_y; + result.adding = from.adding; + return result; + } + + static strategy::communication::SeekerRequest from_ros( + const rj_msgs::msg::SeekerRequest& from) { + return strategy::communication::SeekerRequest{ + from.request_uid, from.robot_id, from.seeking_point_x, + from.seeking_point_y, from.adding, + }; + } }; ASSOCIATE_CPP_ROS(strategy::communication::SeekerRequest, rj_msgs::msg::SeekerRequest); -} \ No newline at end of file +} // namespace rj_convert \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/test_request.hpp b/soccer/src/soccer/strategy/agent/communication/test_request.hpp index 7252eb7894d..ef1f6dfc25a 100644 --- a/soccer/src/soccer/strategy/agent/communication/test_request.hpp +++ b/soccer/src/soccer/strategy/agent/communication/test_request.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -12,32 +12,31 @@ namespace strategy::communication { struct TestRequest { - uint32_t request_uid; + uint32_t request_uid; }; bool operator==(const TestRequest& a, const TestRequest& b); void generate_uid(TestRequest& request); -} +} // namespace strategy::communication namespace rj_convert { template <> struct RosConverter { - static rj_msgs::msg::TestRequest to_ros(const strategy::communication::TestRequest& from) { - rj_msgs::msg::TestRequest result; - result.request_uid = from.request_uid; - return result; - } - - static strategy::communication::TestRequest from_ros(const rj_msgs::msg::TestRequest& from) { - return strategy::communication::TestRequest{ - from.request_uid, - }; - } - + static rj_msgs::msg::TestRequest to_ros(const strategy::communication::TestRequest& from) { + rj_msgs::msg::TestRequest result; + result.request_uid = from.request_uid; + return result; + } + + static strategy::communication::TestRequest from_ros(const rj_msgs::msg::TestRequest& from) { + return strategy::communication::TestRequest{ + from.request_uid, + }; + } }; ASSOCIATE_CPP_ROS(strategy::communication::TestRequest, rj_msgs::msg::TestRequest); -} \ No newline at end of file +} // namespace rj_convert \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/communication/test_response.hpp b/soccer/src/soccer/strategy/agent/communication/test_response.hpp index 0aa8ae838ca..4e2600ca149 100644 --- a/soccer/src/soccer/strategy/agent/communication/test_response.hpp +++ b/soccer/src/soccer/strategy/agent/communication/test_response.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -12,35 +12,34 @@ namespace strategy::communication { struct TestResponse { - uint32_t response_uid; - std::string message; + uint32_t response_uid; + std::string message; }; bool operator==(const TestResponse& a, const TestResponse& b); void generate_uid(TestResponse& response); -} +} // namespace strategy::communication namespace rj_convert { template <> struct RosConverter { - static rj_msgs::msg::TestResponse to_ros(const strategy::communication::TestResponse& from) { - rj_msgs::msg::TestResponse result; - result.response_uid = from.response_uid; - result.message = from.message; - return result; - } - - static strategy::communication::TestResponse from_ros(const rj_msgs::msg::TestResponse& from) { - return strategy::communication::TestResponse{ - from.response_uid, - from.message, - }; - } - + static rj_msgs::msg::TestResponse to_ros(const strategy::communication::TestResponse& from) { + rj_msgs::msg::TestResponse result; + result.response_uid = from.response_uid; + result.message = from.message; + return result; + } + + static strategy::communication::TestResponse from_ros(const rj_msgs::msg::TestResponse& from) { + return strategy::communication::TestResponse{ + from.response_uid, + from.message, + }; + } }; ASSOCIATE_CPP_ROS(strategy::communication::TestResponse, rj_msgs::msg::TestResponse); -} \ No newline at end of file +} // namespace rj_convert \ No newline at end of file diff --git a/soccer/src/soccer/strategy/agent/position/offense.cpp b/soccer/src/soccer/strategy/agent/position/offense.cpp index 351ee5aa203..db90148b045 100644 --- a/soccer/src/soccer/strategy/agent/position/offense.cpp +++ b/soccer/src/soccer/strategy/agent/position/offense.cpp @@ -183,7 +183,8 @@ std::optional Offense::state_to_task(RobotIntent intent) { // Calculate a new seeking point seeker_.reset_target(); seeker_.set_seeker_points(seeker_points_); - std::optional actual_intent = seeker_.get_task(std::move(intent), last_world_state_, field_dimensions_); + std::optional actual_intent = + seeker_.get_task(std::move(intent), last_world_state_, field_dimensions_); broadcast_seeker_request(seeker_.get_target_point(), true); return actual_intent; } @@ -374,10 +375,10 @@ communication::PosAgentResponseWrapper Offense::receive_communication_request( comm_response.response = response; return comm_response; } else if (const communication::SeekerRequest* seeker_request = - std::get_if(&request.request)) { + std::get_if(&request.request)) { if (seeker_request->adding) { - seeker_points_[seeker_request->robot_id] - = rj_geometry::Point{seeker_request->seeking_point_x, seeker_request->seeking_point_y}; + seeker_points_[seeker_request->robot_id] = rj_geometry::Point{ + seeker_request->seeking_point_x, seeker_request->seeking_point_y}; } else { seeker_points_.erase(seeker_request->robot_id); } @@ -579,8 +580,8 @@ void Offense::broadcast_seeker_request(rj_geometry::Point seeking_point, bool ad communication::generate_uid(seeker_request); seeker_request.robot_id = robot_id_; seeker_request.seeking_point_x = seeking_point.x(); - seeker_request.seeking_point_y = seeking_point.y(); - seeker_request.adding = adding; + seeker_request.seeking_point_y = seeking_point.y(); + seeker_request.adding = adding; communication::PosAgentRequestWrapper communication_request{}; communication_request.request = seeker_request; diff --git a/soccer/src/soccer/strategy/agent/position/seeker.cpp b/soccer/src/soccer/strategy/agent/position/seeker.cpp index 46f8403c33d..98b87ef39c2 100644 --- a/soccer/src/soccer/strategy/agent/position/seeker.cpp +++ b/soccer/src/soccer/strategy/agent/position/seeker.cpp @@ -24,9 +24,7 @@ std::optional Seeker::get_task(RobotIntent intent, const WorldState void Seeker::reset_target() { target_valid_ = false; } -rj_geometry::Point Seeker::get_target_point() { - return target_pt_; -} +rj_geometry::Point Seeker::get_target_point() { return target_pt_; } void Seeker::set_seeker_points(std::unordered_map seeker_points) { seeker_points_ = seeker_points; @@ -119,7 +117,8 @@ rj_geometry::Point Seeker::correct_point(rj_geometry::Point p, } double Seeker::eval_point(rj_geometry::Point ball_pos, rj_geometry::Point current_point, - const WorldState* world_state, const FieldDimensions& field_dimensions) const { + const WorldState* world_state, + const FieldDimensions& field_dimensions) const { // Determines 'how good' a point is // A higher value is a worse point @@ -192,10 +191,10 @@ double Seeker::eval_point(rj_geometry::Point ball_pos, rj_geometry::Point curren } double min_seeker_dist = std::numeric_limits::infinity(); - for (const auto & [ key, value ] : seeker_points_) { + for (const auto& [key, value] : seeker_points_) { min_seeker_dist = std::min(min_seeker_dist, current_point.dist_to(value)); } - const double seeker_dist_loss = 0.4 * 1/min_seeker_dist; + const double seeker_dist_loss = 0.4 * 1 / min_seeker_dist; // Final evaluation return max + ball_proximity_loss + goal_distance_loss + min_path_dist + min_robot_dist + diff --git a/soccer/src/soccer/strategy/agent/position/seeker.hpp b/soccer/src/soccer/strategy/agent/position/seeker.hpp index 5b1d760ace1..573ce1b8e0b 100644 --- a/soccer/src/soccer/strategy/agent/position/seeker.hpp +++ b/soccer/src/soccer/strategy/agent/position/seeker.hpp @@ -3,7 +3,6 @@ #include #include - #include #include #include @@ -50,10 +49,8 @@ class Seeker : public RoleInterface { rj_geometry::Point get_target_point(); - void set_seeker_points(std::unordered_map seeker_points); - private: // The seeker's id int robot_id_; @@ -112,10 +109,10 @@ class Seeker : public RoleInterface { * @return double The evaluation of that target point */ [[nodiscard]] double eval_point(rj_geometry::Point ball_pos, rj_geometry::Point current_point, - const WorldState* world_state, - const FieldDimensions& field_dimensions) const; + const WorldState* world_state, + const FieldDimensions& field_dimensions) const; - std::unordered_map seeker_points_ {}; + std::unordered_map seeker_points_{}; }; } // namespace strategy From 88af25c4937361c14db82a075082babd38385d7a Mon Sep 17 00:00:00 2001 From: sanatd33 Date: Thu, 14 Mar 2024 12:52:37 -0400 Subject: [PATCH 3/6] added comments / fixed stuff --- soccer/src/soccer/strategy/agent/position/offense.cpp | 1 - soccer/src/soccer/strategy/agent/position/seeker.cpp | 10 ++++++---- soccer/src/soccer/strategy/agent/position/seeker.hpp | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/soccer/src/soccer/strategy/agent/position/offense.cpp b/soccer/src/soccer/strategy/agent/position/offense.cpp index db90148b045..df08d293e6f 100644 --- a/soccer/src/soccer/strategy/agent/position/offense.cpp +++ b/soccer/src/soccer/strategy/agent/position/offense.cpp @@ -373,7 +373,6 @@ communication::PosAgentResponseWrapper Offense::receive_communication_request( // SPDLOG_INFO("Robot {} accepts pass", robot_id_); comm_response.response = response; - return comm_response; } else if (const communication::SeekerRequest* seeker_request = std::get_if(&request.request)) { if (seeker_request->adding) { diff --git a/soccer/src/soccer/strategy/agent/position/seeker.cpp b/soccer/src/soccer/strategy/agent/position/seeker.cpp index 98b87ef39c2..50c926be5fb 100644 --- a/soccer/src/soccer/strategy/agent/position/seeker.cpp +++ b/soccer/src/soccer/strategy/agent/position/seeker.cpp @@ -26,7 +26,7 @@ void Seeker::reset_target() { target_valid_ = false; } rj_geometry::Point Seeker::get_target_point() { return target_pt_; } -void Seeker::set_seeker_points(std::unordered_map seeker_points) { +void Seeker::set_seeker_points(const std::unordered_map& seeker_points) { seeker_points_ = seeker_points; } @@ -125,7 +125,7 @@ double Seeker::eval_point(rj_geometry::Point ball_pos, rj_geometry::Point curren // Does not go into the goalie boxes rj_geometry::Rect goal_box{rj_geometry::Point{1, 8}, rj_geometry::Point{-1, 9}}; if (goal_box.contains_point(current_point)) { - return 10000000; + return std::numeric_limits::infinity();; } // Line of Sight Heuristic @@ -142,8 +142,8 @@ double Seeker::eval_point(rj_geometry::Point ball_pos, rj_geometry::Point curren // Whether the path from ball to the point is blocked // Same logic in passing to check if target is open rj_geometry::Segment pass_path{ball_pos, current_point}; - double min_robot_dist = 10000; - float min_path_dist = 10000; + double min_robot_dist = std::numeric_limits::infinity();; + float min_path_dist = std::numeric_limits::infinity();; for (const RobotState& robot : world_state->their_robots) { rj_geometry::Point opp_pos = robot.pose.position(); auto robot_dist = current_point.dist_to(opp_pos); @@ -190,6 +190,8 @@ double Seeker::eval_point(rj_geometry::Point ball_pos, rj_geometry::Point curren block_shot_loss = 1; } + // Finding the minimum distance from the target point to the other seeker points (from communication) + // Heuristic to penalize being close to other seekers (a small minimum distance)s double min_seeker_dist = std::numeric_limits::infinity(); for (const auto& [key, value] : seeker_points_) { min_seeker_dist = std::min(min_seeker_dist, current_point.dist_to(value)); diff --git a/soccer/src/soccer/strategy/agent/position/seeker.hpp b/soccer/src/soccer/strategy/agent/position/seeker.hpp index 573ce1b8e0b..b87d6f6c638 100644 --- a/soccer/src/soccer/strategy/agent/position/seeker.hpp +++ b/soccer/src/soccer/strategy/agent/position/seeker.hpp @@ -49,7 +49,7 @@ class Seeker : public RoleInterface { rj_geometry::Point get_target_point(); - void set_seeker_points(std::unordered_map seeker_points); + void set_seeker_points(const std::unordered_map& seeker_points); private: // The seeker's id From c404ba523fd3d63ec362f4d16b768d2243e53116 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 14 Mar 2024 13:06:14 -0400 Subject: [PATCH 4/6] Fix Code Style On fix-seeking (#2238) * automated style fixes * Update seeker.cpp --------- Co-authored-by: sanatd33 Co-authored-by: Sanat Dhanyamraju <53443682+sanatd33@users.noreply.github.com> --- soccer/src/soccer/strategy/agent/position/seeker.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/soccer/src/soccer/strategy/agent/position/seeker.cpp b/soccer/src/soccer/strategy/agent/position/seeker.cpp index 50c926be5fb..e33c6588e4a 100644 --- a/soccer/src/soccer/strategy/agent/position/seeker.cpp +++ b/soccer/src/soccer/strategy/agent/position/seeker.cpp @@ -125,7 +125,7 @@ double Seeker::eval_point(rj_geometry::Point ball_pos, rj_geometry::Point curren // Does not go into the goalie boxes rj_geometry::Rect goal_box{rj_geometry::Point{1, 8}, rj_geometry::Point{-1, 9}}; if (goal_box.contains_point(current_point)) { - return std::numeric_limits::infinity();; + return std::numeric_limits::infinity(); } // Line of Sight Heuristic @@ -142,8 +142,9 @@ double Seeker::eval_point(rj_geometry::Point ball_pos, rj_geometry::Point curren // Whether the path from ball to the point is blocked // Same logic in passing to check if target is open rj_geometry::Segment pass_path{ball_pos, current_point}; - double min_robot_dist = std::numeric_limits::infinity();; - float min_path_dist = std::numeric_limits::infinity();; + double min_robot_dist = std::numeric_limits::infinity(); + float min_path_dist = std::numeric_limits::infinity(); + for (const RobotState& robot : world_state->their_robots) { rj_geometry::Point opp_pos = robot.pose.position(); auto robot_dist = current_point.dist_to(opp_pos); @@ -190,8 +191,8 @@ double Seeker::eval_point(rj_geometry::Point ball_pos, rj_geometry::Point curren block_shot_loss = 1; } - // Finding the minimum distance from the target point to the other seeker points (from communication) - // Heuristic to penalize being close to other seekers (a small minimum distance)s + // Finding the minimum distance from the target point to the other seeker points (from + // communication) Heuristic to penalize being close to other seekers (a small minimum distance)s double min_seeker_dist = std::numeric_limits::infinity(); for (const auto& [key, value] : seeker_points_) { min_seeker_dist = std::min(min_seeker_dist, current_point.dist_to(value)); From aa05413d56f7eff2f798ad360ca92f082f094dbe Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 14 Mar 2024 13:08:42 -0400 Subject: [PATCH 5/6] Fix Code Style On fix-seeking (#2239) automated style fixes Co-authored-by: sanatd33 --- soccer/src/soccer/strategy/agent/position/seeker.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/soccer/src/soccer/strategy/agent/position/seeker.cpp b/soccer/src/soccer/strategy/agent/position/seeker.cpp index e33c6588e4a..37cf07acce4 100644 --- a/soccer/src/soccer/strategy/agent/position/seeker.cpp +++ b/soccer/src/soccer/strategy/agent/position/seeker.cpp @@ -144,7 +144,7 @@ double Seeker::eval_point(rj_geometry::Point ball_pos, rj_geometry::Point curren rj_geometry::Segment pass_path{ball_pos, current_point}; double min_robot_dist = std::numeric_limits::infinity(); float min_path_dist = std::numeric_limits::infinity(); - + for (const RobotState& robot : world_state->their_robots) { rj_geometry::Point opp_pos = robot.pose.position(); auto robot_dist = current_point.dist_to(opp_pos); From 00066edd4d2175e8bea7c2f683e7a4cb7f38abe0 Mon Sep 17 00:00:00 2001 From: Sid Parikh Date: Thu, 14 Mar 2024 17:36:21 -0400 Subject: [PATCH 6/6] Fix narrowing type conversion --- soccer/src/soccer/strategy/agent/position/seeker.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/soccer/src/soccer/strategy/agent/position/seeker.cpp b/soccer/src/soccer/strategy/agent/position/seeker.cpp index 37cf07acce4..327e122ba90 100644 --- a/soccer/src/soccer/strategy/agent/position/seeker.cpp +++ b/soccer/src/soccer/strategy/agent/position/seeker.cpp @@ -143,7 +143,7 @@ double Seeker::eval_point(rj_geometry::Point ball_pos, rj_geometry::Point curren // Same logic in passing to check if target is open rj_geometry::Segment pass_path{ball_pos, current_point}; double min_robot_dist = std::numeric_limits::infinity(); - float min_path_dist = std::numeric_limits::infinity(); + float min_path_dist = std::numeric_limits::infinity(); for (const RobotState& robot : world_state->their_robots) { rj_geometry::Point opp_pos = robot.pose.position();