diff --git a/rj_msgs/CMakeLists.txt b/rj_msgs/CMakeLists.txt index d6dbbde2a37..f5b4ade5f80 100644 --- a/rj_msgs/CMakeLists.txt +++ b/rj_msgs/CMakeLists.txt @@ -62,24 +62,24 @@ rosidl_generate_interfaces( msg/AgentResponseVariant.msg # Agent Request Messages - request/PassRequest.msg + request/ResetScorerRequest.msg request/PositionRequest.msg request/TestRequest.msg - request/IncomingBallRequest.msg request/BallInTransitRequest.msg request/ScorerRequest.msg - request/ResetScorerRequest.msg - request/JoinWallRequest.msg + request/IncomingBallRequest.msg + request/PassRequest.msg request/LeaveWallRequest.msg + request/JoinWallRequest.msg # Agent Response Messages + response/LeaveWallResponse.msg response/Acknowledge.msg response/PassResponse.msg + response/JoinWallResponse.msg response/PositionResponse.msg - response/TestResponse.msg response/ScorerResponse.msg - response/JoinWallResponse.msg - response/LeaveWallResponse.msg + response/TestResponse.msg # Services srv/AgentCommunication.srv diff --git a/rj_msgs/msg/AgentRequest.msg b/rj_msgs/msg/AgentRequest.msg index 1684d81d074..69c8a152580 100644 --- a/rj_msgs/msg/AgentRequest.msg +++ b/rj_msgs/msg/AgentRequest.msg @@ -3,12 +3,12 @@ # 2 -> PositionResponse # 3 -> PassResponse # ACKNOWLEDGE REQUEST DOES NOT (AND SHOULD NOT) EXIST -TestRequest[<=1] test_request +ResetScorerRequest[<=1] reset_scorer_request PositionRequest[<=1] position_request -PassRequest[<=1] pass_request -IncomingBallRequest[<=1] incoming_ball_request +TestRequest[<=1] test_request BallInTransitRequest[<=1] ball_in_transit_request ScorerRequest[<=1] scorer_request -ResetScorerRequest[<=1] reset_scorer_request -JoinWallRequest[<=1] join_wall_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 diff --git a/rj_msgs/msg/AgentResponseVariant.msg b/rj_msgs/msg/AgentResponseVariant.msg index 6e6c964d88a..c4fc9c33705 100644 --- a/rj_msgs/msg/AgentResponseVariant.msg +++ b/rj_msgs/msg/AgentResponseVariant.msg @@ -1,7 +1,7 @@ -Acknowledge[<=1] acknowledge_response -TestResponse[<=1] test_response -PositionResponse[<=1] position_response +LeaveWallResponse[<=1] leave_wall_response +Acknowledge[<=1] acknowledge PassResponse[<=1] pass_response -ScorerResponse[<=1] scorer_response JoinWallResponse[<=1] join_wall_response -LeaveWallResponse[<=1] leave_wall_response +PositionResponse[<=1] position_response +ScorerResponse[<=1] scorer_response +TestResponse[<=1] test_response \ No newline at end of file diff --git a/rj_msgs/request/BallInTransitRequest.msg b/rj_msgs/request/BallInTransitRequest.msg index 532954c17f8..1d08e2a5b36 100644 --- a/rj_msgs/request/BallInTransitRequest.msg +++ b/rj_msgs/request/BallInTransitRequest.msg @@ -1,2 +1,11 @@ +# /** +# * @brief request sent by an agent to a specific agent indicating the +# * ball has left this agent's possession and is currently headed for the +# * other agent. +# * +# * an agent will send a BallInTransitRequest to a robot after they have +# * kicked the ball so the other robot knows to begin receiving the ball. +# * +# */ uint32 request_uid uint8 from_robot_id \ No newline at end of file diff --git a/rj_msgs/request/IncomingBallRequest.msg b/rj_msgs/request/IncomingBallRequest.msg index 532954c17f8..1268db43f5c 100644 --- a/rj_msgs/request/IncomingBallRequest.msg +++ b/rj_msgs/request/IncomingBallRequest.msg @@ -1,2 +1,11 @@ +# /** +# * @brief request sent by an agent to a specific agent indicating that +# * this agent is going to kick the ball to the other agent iff the other +# * agent acknowledges this message. +# * +# * agents will send an incoming ball request to the agent they will be passing +# * to. +# * +# */ uint32 request_uid uint8 from_robot_id \ No newline at end of file diff --git a/rj_msgs/request/JoinWallRequest.msg b/rj_msgs/request/JoinWallRequest.msg index 75b42a5bc87..f5b093ea72d 100644 --- a/rj_msgs/request/JoinWallRequest.msg +++ b/rj_msgs/request/JoinWallRequest.msg @@ -1,2 +1,6 @@ +# /** +# * @brief request sent by an agent when it wants to join the wall. +# * +# */ uint32 request_uid uint8 robot_id \ No newline at end of file diff --git a/rj_msgs/request/LeaveWallRequest.msg b/rj_msgs/request/LeaveWallRequest.msg index 75b42a5bc87..2661deca901 100644 --- a/rj_msgs/request/LeaveWallRequest.msg +++ b/rj_msgs/request/LeaveWallRequest.msg @@ -1,2 +1,6 @@ +# /** +# * @brief request sent by an agent when it wants to leave the wall. +# * +# */ uint32 request_uid uint8 robot_id \ No newline at end of file diff --git a/rj_msgs/request/PassRequest.msg b/rj_msgs/request/PassRequest.msg index ba0abf272f1..829c1463574 100644 --- a/rj_msgs/request/PassRequest.msg +++ b/rj_msgs/request/PassRequest.msg @@ -1,3 +1,11 @@ +# /** +# * @brief request sent by an agent to one or many agents indicating +# * that it would like to pass the bass. +# * +# * pass requests exist so that agents can find out which other agents +# * are open for passes. +# * +# */ uint32 request_uid bool direct uint8 from_robot_id \ No newline at end of file diff --git a/rj_msgs/request/PositionRequest.msg b/rj_msgs/request/PositionRequest.msg index 2681738c4fa..39bb89b2cc9 100644 --- a/rj_msgs/request/PositionRequest.msg +++ b/rj_msgs/request/PositionRequest.msg @@ -1 +1,10 @@ +# /** +# * @brief request sent by an agent to one or many agents indicating +# * that it would like to know the current position the agent is playing. +# * +# * position requests were originally used for testing, however they may be +# * useful for coordinating complex behaviors. For example, agent a may need +# * to know that agent b is currently a waller before attempting to ask agent b +# * for help. +# */ uint32 request_uid \ No newline at end of file diff --git a/rj_msgs/request/ResetScorerRequest.msg b/rj_msgs/request/ResetScorerRequest.msg index 2681738c4fa..9e116eaf4dd 100644 --- a/rj_msgs/request/ResetScorerRequest.msg +++ b/rj_msgs/request/ResetScorerRequest.msg @@ -1 +1,5 @@ +# /** +# * @brief request sent by a scorer after they shoot to avoid double touch penalties. +# * +# */ uint32 request_uid \ No newline at end of file diff --git a/rj_msgs/request/ScorerRequest.msg b/rj_msgs/request/ScorerRequest.msg index 3de86fea1db..9c469d065d6 100644 --- a/rj_msgs/request/ScorerRequest.msg +++ b/rj_msgs/request/ScorerRequest.msg @@ -1,3 +1,8 @@ +# /** +# * @brief request sent by an agent to determine whether or not it should be going to steal +# * the ball to then shoot the ball +# * +# */ uint32 request_uid uint8 robot_id float64 ball_distance \ No newline at end of file diff --git a/rj_msgs/request/TestRequest.msg b/rj_msgs/request/TestRequest.msg index 2681738c4fa..b13e1fed489 100644 --- a/rj_msgs/request/TestRequest.msg +++ b/rj_msgs/request/TestRequest.msg @@ -1 +1,9 @@ +# /** +# * @brief request sent by an agent to one or many target agents that +# * can be used for testing communication between different agents. +# * +# * the test request was used mainly for testing that messages were being successfully +# * sent between the various agents. +# * +# */ uint32 request_uid \ No newline at end of file diff --git a/rj_msgs/response/Acknowledge.msg b/rj_msgs/response/Acknowledge.msg index 82cf21e2bcb..dac0ccc5e0e 100644 --- a/rj_msgs/response/Acknowledge.msg +++ b/rj_msgs/response/Acknowledge.msg @@ -1 +1,9 @@ +# /** +# * @brief general response given by an agent to any request to let the sender know +# * that this agent has read the message, but will not be sending any additional data. +# * +# * acknowledge can be general purposely used whenever behaviour for a specific +# * request does not need to be specified for a specific role or position. +# * +# */ uint32 response_uid \ No newline at end of file diff --git a/rj_msgs/response/JoinWallResponse.msg b/rj_msgs/response/JoinWallResponse.msg index 661f83b7710..277d7eda943 100644 --- a/rj_msgs/response/JoinWallResponse.msg +++ b/rj_msgs/response/JoinWallResponse.msg @@ -1,2 +1,7 @@ +# /** +# * @brief response from other robots who are currently apart of the wall so this +# * robot can figure out where they are in the wall of robots. +# * +# */ uint32 response_uid uint8 robot_id \ No newline at end of file diff --git a/rj_msgs/response/LeaveWallResponse.msg b/rj_msgs/response/LeaveWallResponse.msg index 661f83b7710..077dc645f67 100644 --- a/rj_msgs/response/LeaveWallResponse.msg +++ b/rj_msgs/response/LeaveWallResponse.msg @@ -1,2 +1,6 @@ +# /** +# * @brief response from other robots who are currently apart of the wall. +# * +# */ uint32 response_uid uint8 robot_id \ No newline at end of file diff --git a/rj_msgs/response/PassResponse.msg b/rj_msgs/response/PassResponse.msg index 255d21f2788..88a11565c3d 100644 --- a/rj_msgs/response/PassResponse.msg +++ b/rj_msgs/response/PassResponse.msg @@ -1,2 +1,10 @@ +# /** +# * @brief response from an open agent that will let the sender know that the +# * receiver is open for a pass. +# * +# * the pass response is used to notify the sender that this robot is either +# * open or not open to direct or (in the future) leading passes. +# * +# */ uint32 response_uid bool direct_open \ No newline at end of file diff --git a/rj_msgs/response/PositionResponse.msg b/rj_msgs/response/PositionResponse.msg index 666e7a97715..d50d451a1a1 100644 --- a/rj_msgs/response/PositionResponse.msg +++ b/rj_msgs/response/PositionResponse.msg @@ -1,2 +1,11 @@ +# /** +# * @brief response containing a given agent's position (in string) to a position +# * request from another agent. +# * +# * the position response is used to return the name of the position or role +# * the receiving robot is playing which is currently not used, but could be +# * useful in the future. +# * +# */ uint32 response_uid string position \ No newline at end of file diff --git a/rj_msgs/response/ScorerResponse.msg b/rj_msgs/response/ScorerResponse.msg index f8214b2e581..b52b47238da 100644 --- a/rj_msgs/response/ScorerResponse.msg +++ b/rj_msgs/response/ScorerResponse.msg @@ -1,3 +1,9 @@ +# /** +# * @brief response to return to another robot asking to be the scorer (only offensive +# * robots will return this response to let another offensive robot know whether or not +# * they should be the scorer) +# * +# */ uint32 response_uid uint8 robot_id float64 ball_distance \ No newline at end of file diff --git a/rj_msgs/response/TestResponse.msg b/rj_msgs/response/TestResponse.msg index 493191c560a..62f725d6dc3 100644 --- a/rj_msgs/response/TestResponse.msg +++ b/rj_msgs/response/TestResponse.msg @@ -1,2 +1,10 @@ +# /** +# * @brief response containing some test message that can be used for testing the +# * sending capabilities between senders and receivers. +# * +# * If things aren't working send the test response with a message of your +# * choosing. +# * +# */ uint32 response_uid string message \ 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 new file mode 100644 index 00000000000..fc98f6264ae --- /dev/null +++ b/soccer/src/soccer/strategy/agent/communication/acknowledge.hpp @@ -0,0 +1,43 @@ +#pragma once + +#include +#include +#include +#include + +#include +#include + +#include "rj_msgs/msg/acknowledge.hpp" + +namespace strategy::communication { + +struct Acknowledge { + 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, + }; + } +}; + +ASSOCIATE_CPP_ROS(strategy::communication::Acknowledge, rj_msgs::msg::Acknowledge); + +} // 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 new file mode 100644 index 00000000000..5438935e41b --- /dev/null +++ b/soccer/src/soccer/strategy/agent/communication/ball_in_transit_request.hpp @@ -0,0 +1,50 @@ +#pragma once + +#include +#include +#include +#include + +#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; +}; + +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, + }; + } +}; + +ASSOCIATE_CPP_ROS(strategy::communication::BallInTransitRequest, + rj_msgs::msg::BallInTransitRequest); + +} // 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 5b3ed20121f..c840fb56456 100644 --- a/soccer/src/soccer/strategy/agent/communication/communication.cpp +++ b/soccer/src/soccer/strategy/agent/communication/communication.cpp @@ -8,7 +8,7 @@ u_int32_t request_uid = 0; std::mutex response_uid_mutex; u_int32_t response_uid = 0; -bool operator==(const PassRequest& a, const PassRequest& b) { +bool operator==(const ResetScorerRequest& a, const ResetScorerRequest& b) { return a.request_uid == b.request_uid; } @@ -20,10 +20,6 @@ bool operator==(const TestRequest& a, const TestRequest& 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 BallInTransitRequest& a, const BallInTransitRequest& b) { return a.request_uid == b.request_uid; } @@ -32,11 +28,11 @@ bool operator==(const ScorerRequest& a, const ScorerRequest& b) { return a.request_uid == b.request_uid; } -bool operator==(const ResetScorerRequest& a, const ResetScorerRequest& b) { +bool operator==(const IncomingBallRequest& a, const IncomingBallRequest& b) { return a.request_uid == b.request_uid; } -bool operator==(const JoinWallRequest& a, const JoinWallRequest& b) { +bool operator==(const PassRequest& a, const PassRequest& b) { return a.request_uid == b.request_uid; } @@ -44,31 +40,35 @@ bool operator==(const LeaveWallRequest& a, const LeaveWallRequest& b) { return a.request_uid == b.request_uid; } -bool operator==(const Acknowledge& a, const Acknowledge& b) { +bool operator==(const JoinWallRequest& a, const JoinWallRequest& b) { + return a.request_uid == b.request_uid; +} + +bool operator==(const LeaveWallResponse& a, const LeaveWallResponse& b) { return a.response_uid == b.response_uid; } -bool operator==(const PassResponse& a, const PassResponse& b) { +bool operator==(const Acknowledge& a, const Acknowledge& b) { return a.response_uid == b.response_uid; } -bool operator==(const PositionResponse& a, const PositionResponse& b) { +bool operator==(const PassResponse& a, const PassResponse& b) { return a.response_uid == b.response_uid; } -bool operator==(const TestResponse& a, const TestResponse& b) { +bool operator==(const JoinWallResponse& a, const JoinWallResponse& b) { return a.response_uid == b.response_uid; } -bool operator==(const ScorerResponse& a, const ScorerResponse& b) { +bool operator==(const PositionResponse& a, const PositionResponse& b) { return a.response_uid == b.response_uid; } -bool operator==(const JoinWallResponse& a, const JoinWallResponse& b) { +bool operator==(const ScorerResponse& a, const ScorerResponse& b) { return a.response_uid == b.response_uid; } -bool operator==(const LeaveWallResponse& a, const LeaveWallResponse& b) { +bool operator==(const TestResponse& a, const TestResponse& b) { return a.response_uid == b.response_uid; } @@ -76,7 +76,7 @@ bool operator==(const AgentResponse& a, const AgentResponse& b) { return (a.associated_request == b.associated_request) && (a.response == b.response); } -void generate_uid(PassRequest& request) { +void generate_uid(ResetScorerRequest& request) { request_uid_mutex.lock(); request.request_uid = request_uid; request_uid++; @@ -97,91 +97,91 @@ void generate_uid(TestRequest& request) { request_uid_mutex.unlock(); } -void generate_uid(IncomingBallRequest& request) { +void generate_uid(BallInTransitRequest& request) { request_uid_mutex.lock(); request.request_uid = request_uid; request_uid++; request_uid_mutex.unlock(); } -void generate_uid(BallInTransitRequest& request) { +void generate_uid(ScorerRequest& request) { request_uid_mutex.lock(); request.request_uid = request_uid; request_uid++; request_uid_mutex.unlock(); } -void generate_uid(ScorerRequest& request) { +void generate_uid(IncomingBallRequest& request) { request_uid_mutex.lock(); request.request_uid = request_uid; request_uid++; request_uid_mutex.unlock(); } -void generate_uid(JoinWallRequest& request) { +void generate_uid(PassRequest& request) { request_uid_mutex.lock(); request.request_uid = request_uid; request_uid++; request_uid_mutex.unlock(); } -void generate_uid(ResetScorerRequest& request) { +void generate_uid(LeaveWallRequest& request) { request_uid_mutex.lock(); request.request_uid = request_uid; request_uid++; request_uid_mutex.unlock(); } -void generate_uid(LeaveWallRequest& request) { +void generate_uid(JoinWallRequest& request) { request_uid_mutex.lock(); request.request_uid = request_uid; request_uid++; request_uid_mutex.unlock(); } -void generate_uid(Acknowledge& response) { +void generate_uid(LeaveWallResponse& response) { response_uid_mutex.lock(); response.response_uid = response_uid; response_uid++; response_uid_mutex.unlock(); } -void generate_uid(PassResponse& response) { +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) { +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) { +void generate_uid(JoinWallResponse& response) { response_uid_mutex.lock(); response.response_uid = response_uid; response_uid++; response_uid_mutex.unlock(); } -void generate_uid(ScorerResponse& response) { +void generate_uid(PositionResponse& response) { response_uid_mutex.lock(); response.response_uid = response_uid; response_uid++; response_uid_mutex.unlock(); } -void generate_uid(JoinWallResponse& response) { +void generate_uid(ScorerResponse& response) { response_uid_mutex.lock(); response.response_uid = response_uid; response_uid++; response_uid_mutex.unlock(); } -void generate_uid(LeaveWallResponse& response) { +void generate_uid(TestResponse& response) { response_uid_mutex.lock(); response.response_uid = response_uid; response_uid++; diff --git a/soccer/src/soccer/strategy/agent/communication/communication.hpp b/soccer/src/soccer/strategy/agent/communication/communication.hpp index 3a016781574..4f32a12a52d 100644 --- a/soccer/src/soccer/strategy/agent/communication/communication.hpp +++ b/soccer/src/soccer/strategy/agent/communication/communication.hpp @@ -8,249 +8,41 @@ #include #include -#include "rj_msgs/msg/acknowledge.hpp" +#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 "rj_msgs/msg/incoming_ball_request.hpp" -#include "rj_msgs/msg/join_wall_request.hpp" -#include "rj_msgs/msg/join_wall_response.hpp" -#include "rj_msgs/msg/leave_wall_request.hpp" -#include "rj_msgs/msg/leave_wall_response.hpp" -#include "rj_msgs/msg/pass_request.hpp" -#include "rj_msgs/msg/pass_response.hpp" -#include "rj_msgs/msg/position_request.hpp" -#include "rj_msgs/msg/position_response.hpp" -#include "rj_msgs/msg/reset_scorer_request.hpp" -#include "rj_msgs/msg/scorer_request.hpp" -#include "rj_msgs/msg/scorer_response.hpp" -#include "rj_msgs/msg/test_request.hpp" -#include "rj_msgs/msg/test_response.hpp" +#include "scorer_request.hpp" +#include "scorer_response.hpp" +#include "test_request.hpp" +#include "test_response.hpp" namespace strategy::communication { -// BEGIN REQUEST TYPES // - -/** - * @brief request sent by an agent to one or many agents indicating - * that it would like to pass the bass. - * - * pass requests exist so that agents can find out which other agents - * are open for passes. - * - */ -struct PassRequest { - u_int32_t request_uid; - bool direct; - u_int8_t from_robot_id; -}; -bool operator==(const PassRequest& a, const PassRequest& b); - -/** - * @brief request sent by an agent to one or many agents indicating - * that it would like to know the current position the agent is playing. - * - * position requests were originally used for testing, however they may be - * useful for coordinating complex behaviors. For example, agent a may need - * to know that agent b is currently a waller before attempting to ask agent b - * for help. - */ -struct PositionRequest { - u_int32_t request_uid; -}; -bool operator==(const PositionRequest& a, const PositionRequest& b); - -/** - * @brief request sent by an agent to one or many target agents that - * can be used for testing communication between different agents. - * - * the test request was used mainly for testing that messages were being successfully - * sent between the various agents. - * - */ -struct TestRequest { - u_int32_t request_uid; -}; -bool operator==(const TestRequest& a, const TestRequest& b); - -/** - * @brief request sent by an agent to a specific agent indicating that - * this agent is going to kick the ball to the other agent iff the other - * agent acknowledges this message. - * - * agents will send an incoming ball request to the agent they will be passing - * to. - * - */ -struct IncomingBallRequest { - u_int32_t request_uid; - u_int8_t from_robot_id; -}; -bool operator==(const IncomingBallRequest& a, const IncomingBallRequest& b); - -/** - * @brief request sent by an agent to a specific agent indicating the - * ball has left this agent's possession and is currently headed for the - * other agent. - * - * an agent will send a BallInTransitRequest to a robot after they have - * kicked the ball so the other robot knows to begin receiving the ball. - * - */ -struct BallInTransitRequest { - u_int32_t request_uid; - u_int8_t from_robot_id; -}; -bool operator==(const BallInTransitRequest& a, const BallInTransitRequest& b); - -/** - * @brief request sent by an agent to determine whether or not it should be going to steal - * the ball to then shoot the ball - * - */ -struct ScorerRequest { - u_int32_t request_uid; - u_int8_t robot_id; - double ball_distance; -}; -bool operator==(const ScorerRequest& a, const ScorerRequest& b); - -/** - * @brief request sent by a scorer after they shoot to avoid double touch penalties. - * - */ -struct ResetScorerRequest { - u_int32_t request_uid; -}; -bool operator==(const ResetScorerRequest& a, const ResetScorerRequest& b); - -/** - * @brief request sent by an agent when it wants to join the wall. - * - */ -struct JoinWallRequest { - u_int32_t request_uid; - u_int8_t robot_id; -}; -bool operator==(const JoinWallRequest& a, const JoinWallRequest& b); - -/** - * @brief request sent by an agent when it wants to leave the wall. - * - */ -struct LeaveWallRequest { - u_int32_t request_uid; - u_int8_t robot_id; -}; -bool operator==(const LeaveWallRequest& a, const LeaveWallRequest& b); - /** * @brief a conglomeration of the different request types. */ -using AgentRequest = std::variant; - -// END REQUEST TYPES // - -// BEGIN RESPONSE TYPES // - -/** - * @brief general response given by an agent to any request to let the sender know - * that this agent has read the message, but will not be sending any additional data. - * - * acknowledge can be general purposely used whenever behaviour for a specific - * request does not need to be specified for a specific role or position. - * - */ -struct Acknowledge { - u_int32_t response_uid; -}; -bool operator==(const Acknowledge& a, const Acknowledge& b); - -/** - * @brief response from an open agent that will let the sender know that the - * receiver is open for a pass. - * - * the pass response is used to notify the sender that this robot is either - * open or not open to direct or (in the future) leading passes. - * - */ -struct PassResponse { - u_int32_t response_uid; - bool direct_open; -}; -bool operator==(const PassResponse& a, const PassResponse& b); - -/** - * @brief response containing a given agent's position (in string) to a position - * request from another agent. - * - * the position response is used to return the name of the position or role - * the receiving robot is playing which is currently not used, but could be - * useful in the future. - * - */ -struct PositionResponse { - u_int32_t response_uid; - std::string position; -}; -bool operator==(const PositionResponse& a, const PositionResponse& b); - -/** - * @brief response containing some test message that can be used for testing the - * sending capabilities between senders and receivers. - * - * If things aren't working send the test response with a message of your - * choosing. - * - */ -struct TestResponse { - u_int32_t response_uid; - std::string message; -}; -bool operator==(const TestResponse& a, const TestResponse& b); - -/** - * @brief response to return to another robot asking to be the scorer (only offensive - * robots will return this response to let another offensive robot know whether or not - * they should be the scorer) - * - */ -struct ScorerResponse { - u_int32_t response_uid; - u_int8_t robot_id; - double ball_distance; -}; -bool operator==(const ScorerResponse& a, const ScorerResponse& b); - -/** - * @brief response from other robots who are currently apart of the wall so this - * robot can figure out where they are in the wall of robots. - * - */ -struct JoinWallResponse { - u_int32_t response_uid; - u_int8_t robot_id; -}; -bool operator==(const JoinWallResponse& a, const JoinWallResponse& b); - -/** - * @brief response from other robots who are currently apart of the wall. - * - */ -struct LeaveWallResponse { - u_int32_t response_uid; - u_int8_t robot_id; -}; -bool operator==(const LeaveWallResponse& a, const LeaveWallResponse& b); +using AgentRequest = std::variant; /** - * @brief conglomeration of the different response types. - * + * @brief a conglomeration of the different response types. */ -using AgentResponseVariant = std::variant; +using AgentResponseVariant = + std::variant; /** * @brief response message that is sent from the receiver of the request to the @@ -264,27 +56,27 @@ struct AgentResponse { AgentRequest associated_request; AgentResponseVariant response; }; -bool operator==(const AgentResponse& a, const AgentResponse& b); -// END RESPONSE TYPES // +bool operator==(const AgentResponse& a, const AgentResponse& b); /** - * @brief Wraps a communication request by giving the intended destination of the communication. + * @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; // The request to be send - std::vector - target_agents; // The target receivers of the message (unnecessary in broadcast) - bool broadcast; // Denotes whether or not the message should be sent to all robots. - bool urgent; // If urgent, first response is sent through (others are dropped) + AgentRequest request; + std::vector target_agents; + bool broadcast; + bool urgent; }; /** - * @brief Wraps a communication response to ensure symmetry for agent-to-agent communication. + * @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 @@ -296,7 +88,8 @@ struct PosAgentResponseWrapper { }; /** - * @brief Wraps a communication request to ensure symmetry for agent-to-agent communication. + * @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 @@ -318,239 +111,50 @@ struct AgentPosRequestWrapper { * */ struct AgentPosResponseWrapper { - AgentRequest associated_request; // the request sent for the given response - std::vector to_robot_ids; // the robot ids the request was sent to - std::vector received_robot_ids; // the robot ids responses were found from - bool broadcast; // true if the response should go to every robot - bool urgent; // true if only the first response should be handled - RJ::Time created; // the time the request was created - std::vector responses; // a list of the response from the other agent + AgentRequest associated_request; + std::vector to_robot_ids; + std::vector received_robot_ids; + bool broadcast; + bool urgent; + RJ::Time created; + std::vector responses; }; -// TODO (https://app.clickup.com/t/8677c0tqe): Make this templated and less ugly -void generate_uid(PassRequest& request); -void generate_uid(PositionRequest& request); -void generate_uid(TestRequest& request); -void generate_uid(IncomingBallRequest& request); -void generate_uid(BallInTransitRequest& request); -void generate_uid(ScorerRequest& request); -void generate_uid(ResetScorerRequest& request); -void generate_uid(JoinWallRequest& request); -void generate_uid(LeaveWallRequest& request); - -void generate_uid(Acknowledge& response); -void generate_uid(PassResponse& response); -void generate_uid(PositionResponse& response); -void generate_uid(TestResponse& response); -void generate_uid(ScorerResponse& response); -void generate_uid(JoinWallResponse& response); -void generate_uid(LeaveWallResponse& response); - } // namespace strategy::communication namespace rj_convert { -// BEGIN REQUEST TYPES // - -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) { - strategy::communication::PassRequest result{}; - result.request_uid = from.request_uid; - result.direct = from.direct; - result.from_robot_id = from.from_robot_id; - return result; - } -}; - -ASSOCIATE_CPP_ROS(strategy::communication::PassRequest, rj_msgs::msg::PassRequest); - -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}; - } -}; - -ASSOCIATE_CPP_ROS(strategy::communication::PositionRequest, rj_msgs::msg::PositionRequest); - -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}; - } -}; - -ASSOCIATE_CPP_ROS(strategy::communication::TestRequest, rj_msgs::msg::TestRequest); - -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}; - } -}; - -ASSOCIATE_CPP_ROS(strategy::communication::IncomingBallRequest, rj_msgs::msg::IncomingBallRequest); - -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}; - } -}; - -ASSOCIATE_CPP_ROS(strategy::communication::JoinWallRequest, rj_msgs::msg::JoinWallRequest); - -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}; - } -}; - -ASSOCIATE_CPP_ROS(strategy::communication::LeaveWallRequest, rj_msgs::msg::LeaveWallRequest); - -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}; - } -}; - -ASSOCIATE_CPP_ROS(strategy::communication::BallInTransitRequest, - rj_msgs::msg::BallInTransitRequest); - -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, - }; - } -}; - -ASSOCIATE_CPP_ROS(strategy::communication::ScorerRequest, rj_msgs::msg::ScorerRequest); - -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, - }; - } -}; - -ASSOCIATE_CPP_ROS(strategy::communication::ResetScorerRequest, rj_msgs::msg::ResetScorerRequest); - template <> struct RosConverter { static rj_msgs::msg::AgentRequest to_ros(const strategy::communication::AgentRequest& from) { rj_msgs::msg::AgentRequest result; - if (const auto* test_request = std::get_if(&from)) { - result.test_request.emplace_back(convert_to_ros(*test_request)); + 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* pass_request = - std::get_if(&from)) { - result.pass_request.emplace_back(convert_to_ros(*pass_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* 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* reset_scorer_request = - std::get_if(&from)) { - result.reset_scorer_request.emplace_back(convert_to_ros(*reset_scorer_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* 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"); } @@ -559,24 +163,24 @@ struct RosConverter -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}; - } -}; - -ASSOCIATE_CPP_ROS(strategy::communication::Acknowledge, rj_msgs::msg::Acknowledge); - -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) { - strategy::communication::PassResponse result{}; - result.response_uid = from.response_uid; - result.direct_open = from.direct_open; - return result; - } -}; - -ASSOCIATE_CPP_ROS(strategy::communication::PassResponse, rj_msgs::msg::PassResponse); - -template <> -struct RosConverter { - static rj_msgs::msg::PositionResponse to_ros( - const strategy::communication::PositionResponse& from) { - rj_msgs::msg::PositionResponse result; - result.position = from.position; - result.response_uid = from.response_uid; - return result; - } - - static strategy::communication::PositionResponse from_ros( - const rj_msgs::msg::PositionResponse& from) { - strategy::communication::PositionResponse result; - result.position = from.position; - result.response_uid = from.response_uid; - return result; - } -}; - -ASSOCIATE_CPP_ROS(strategy::communication::PositionResponse, rj_msgs::msg::PositionResponse); - -template <> -struct RosConverter { - static rj_msgs::msg::TestResponse to_ros(const strategy::communication::TestResponse& from) { - rj_msgs::msg::TestResponse result; - result.message = from.message; - result.response_uid = from.response_uid; - return result; - } - - static strategy::communication::TestResponse from_ros(const rj_msgs::msg::TestResponse& from) { - strategy::communication::TestResponse result; - result.message = from.message; - result.response_uid = from.response_uid; - return result; - } -}; - -ASSOCIATE_CPP_ROS(strategy::communication::TestResponse, rj_msgs::msg::TestResponse); - -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) { - strategy::communication::ScorerResponse result{from.response_uid, from.robot_id, - from.ball_distance}; - return result; - } -}; - -ASSOCIATE_CPP_ROS(strategy::communication::ScorerResponse, rj_msgs::msg::ScorerResponse); - -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}; - } -}; - -ASSOCIATE_CPP_ROS(strategy::communication::JoinWallResponse, rj_msgs::msg::JoinWallResponse); - -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}; - } -}; - -ASSOCIATE_CPP_ROS(strategy::communication::LeaveWallResponse, rj_msgs::msg::LeaveWallResponse); - 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* acknowledge_response = - std::get_if(&(from.response))) { - result.response.acknowledge_response.emplace_back( - convert_to_ros(*acknowledge_response)); - } else if (const auto* test_response = - std::get_if(&(from.response))) { - result.response.test_response.emplace_back(convert_to_ros(*test_response)); - } else if (const auto* position_response = - std::get_if(&(from.response))) { - result.response.position_response.emplace_back(convert_to_ros(*position_response)); + 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* 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* 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* 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"); } @@ -758,20 +226,20 @@ struct RosConverter\n#include \n#include" + " \n#include \n\n#include \n#include" + " \n" + ) + hpp += convert_msg_to_hpp_include(msg) + hpp += "\n\n" + hpp += "namespace strategy::communication {\n\n" + hpp += "struct " + msgName + " {\n" + with open(path + "/" + msg) as f: + for line in f: + if "#" not in line: + hpp += "\t" + hpp += map_message_type_to_cpp_type(line) + hpp += "\n" + hpp += "};\n\n" + hpp += "bool operator==(const " + msgName + "& a, const " + msgName + "& b);\n" + hpp += "void generate_uid(" + msgName + "& " + msg_type + ");\n\n" + hpp += "}\n\n" + hpp += "namespace rj_convert {\n\n" + hpp += "template <>\n" + hpp += ( + "struct RosConverter {\n" + ) + hpp += ( + "\tstatic rj_msgs::msg::" + + msgName + + " to_ros(const strategy::communication::" + + msgName + + "& from) {\n" + ) + hpp += "\t\trj_msgs::msg::" + msgName + " result;\n" + with open(path + "/" + msg) as f: + for line in f: + if "#" not in line: + varName = line.split(" ")[1].strip() + hpp += "\t\tresult." + varName + " = from." + varName + ";\n" + hpp += "\t\treturn result;\n" + hpp += "\t}\n\n" + hpp += ( + "\tstatic strategy::communication::" + + msgName + + " from_ros(const rj_msgs::msg::" + + msgName + + "& from) {\n" + ) + hpp += "\t\treturn strategy::communication::" + msgName + "{\n" + with open(path + "/" + msg) as f: + for line in f: + if "#" not in line: + varName = line.split(" ")[1].strip() + hpp += "\t\t\tfrom." + varName + ",\n" + hpp += "\t\t};\n" + hpp += "\t}\n\n" + hpp += "};\n\n" + hpp += ( + "ASSOCIATE_CPP_ROS(strategy::communication::" + + msgName + + ", rj_msgs::msg::" + + msgName + + ");\n\n" + ) + hpp += "}" + return hpp + + +def convert_cpp(requests, responses, hpp_names): + cpp = '#include "communication.hpp"\n' + cpp += "\nnamespace strategy::communication {\n\n" + cpp += "std::mutex request_uid_mutex;\n" + cpp += "u_int32_t request_uid = 0;\n\n" + cpp += "std::mutex response_uid_mutex;\n" + cpp += "u_int32_t response_uid = 0;\n\n" + + for request in requests: + msgName = request[:-4] # Stripping .msg from the end + cpp += "bool operator==(const " + msgName + "& a, const " + msgName + "& b) {\n" + cpp += "\treturn a.request_uid == b.request_uid;\n" + cpp += "}\n\n" + + for response in responses: + msgName = response[:-4] # Stripping .msg from the end + cpp += "bool operator==(const " + msgName + "& a, const " + msgName + "& b) {\n" + cpp += "\treturn a.response_uid == b.response_uid;\n" + cpp += "}\n\n" + + cpp += "bool operator==(const AgentResponse& a, const AgentResponse& b) {\n" + cpp += ( + "\treturn (a.associated_request == b.associated_request) && (a.response ==" + " b.response);\n" + ) + cpp += "}\n\n" + + for request in requests: + msgName = request[:-4] # Stripping .msg from the end + cpp += "void generate_uid(" + msgName + "& request) {\n" + cpp += "\trequest_uid_mutex.lock();\n" + cpp += "\trequest.request_uid = request_uid;\n" + cpp += "\trequest_uid++;\n" + cpp += "\trequest_uid_mutex.unlock();\n" + cpp += "}\n\n" + + for response in responses: + msgName = response[:-4] # Stripping .msg from the end + cpp += "void generate_uid(" + msgName + "& response) {\n" + cpp += "\tresponse_uid_mutex.lock();\n" + cpp += "\tresponse.response_uid = response_uid;\n" + cpp += "\tresponse_uid++;\n" + cpp += "\tresponse_uid_mutex.unlock();\n" + cpp += "}\n\n" + + cpp += "}" + return cpp + + +def create_cpp_file(requests, responses, hpp_names): + cpp = convert_cpp(requests, responses, hpp_names) + with open("communication.cpp", "w") as f: + f.write(cpp) + + +def create_hpp_files(requests, requestPath, responses, responsePath): + hpp_names = [] + for request in requests: + fileName = convert_msg_to_hpp_include(request)[22:-1] + hpp = convert_individual_hpp(request, requestPath, "request") + hpp_names.append(fileName) + with open(fileName, "w") as f: + f.write(hpp) + + for response in responses: + fileName = convert_msg_to_hpp_include(response)[22:-1] + hpp = convert_individual_hpp(response, responsePath, "response") + hpp_names.append(fileName) + with open(fileName, "w") as f: + f.write(hpp) + + return hpp_names + + +def convert_main_hpp_file(requests_msgs, response_msgs, hpp_names): + hpp = ( + "#pragma once\n\n#include \n#include \n#include" + " \n#include \n\n#include \n#include" + " \n\n" + ) + hpp += '#include "rj_msgs/msg/agent_request.hpp"\n' + hpp += '#include "rj_msgs/msg/agent_response.hpp"\n' + hpp += '#include "rj_msgs/msg/agent_response_variant.hpp"\n' + + for name in hpp_names: + hpp += '#include "' + name + '"\n' + + hpp += "\nnamespace strategy::communication {\n\n" + hpp += "/**\n" + hpp += "* @brief a conglomeration of the different request types.\n" + hpp += "*/\n" + hpp += "using AgentRequest = std::variant<" + for request in requests_msgs: + msgName = request[:-4] + hpp += msgName + ", " + + hpp = hpp[:-2] + ">;\n\n" + + hpp += "/**\n" + hpp += "* @brief a conglomeration of the different response types.\n" + hpp += "*/\n" + hpp += "using AgentResponseVariant = std::variant<" + for response in response_msgs: + msgName = response[:-4] + hpp += msgName + ", " + hpp = hpp[:-2] + ">;\n\n" + + hpp += "/**\n" + hpp += ( + "* @brief response message that is sent from the receiver of the request to" + " the\n" + ) + hpp += "* sender of the request with an accompanying response.\n" + hpp += "*\n" + hpp += ( + "* The agent response is the actual thing that gets sent from a receiver back\n" + ) + hpp += "* to the sender.\n" + hpp += "*\n" + hpp += "*/\n" + hpp += "struct AgentResponse {\n" + hpp += "\tAgentRequest associated_request;\n" + hpp += "\tAgentResponseVariant response;\n" + hpp += "};\n\n" + + hpp += "bool operator==(const AgentResponse& a, const AgentResponse& b);\n\n" + + hpp += "/**\n" + hpp += ( + "* @brief Wraps a communication request by giving the intended destination of" + " the\n" + ) + hpp += "* communication.\n" + hpp += "*\n" + hpp += ( + "* positions will create this and send it to their agent action client which" + " will\n" + ) + hpp += "* send out the request according to their specifications.\n" + hpp += "*\n" + hpp += "*/\n" + + hpp += "struct PosAgentRequestWrapper {\n" + hpp += "\tAgentRequest request;\n" + hpp += "\tstd::vector target_agents;\n" + hpp += "\tbool broadcast;\n" + hpp += "\tbool urgent;\n" + hpp += "};\n\n" + + hpp += "/**\n" + hpp += ( + "* @brief Wraps a communication response to ensure symmetry for" + " agent-to-agent\n" + ) + hpp += "* communication.\n" + hpp += "*\n" + hpp += ( + "* this wrapper is placed on agent responses to promote symmetry across the" + " request\n" + ) + hpp += ( + "* response system to make understanding easier. All this struct does is make" + " explicit\n" + ) + hpp += "* that this response is going from the position to the agent.\n" + hpp += "*\n" + hpp += "*/\n" + hpp += "struct PosAgentResponseWrapper {\n" + hpp += "\tAgentResponseVariant response;\n" + hpp += "};\n\n" + + hpp += "/**\n" + hpp += ( + "* @brief Wraps a communication request to ensure symmetry for agent-to-agent\n" + ) + hpp += "* communication.\n" + hpp += "*\n" + hpp += ( + "* Like the PosAgentResponseWrapper, this struct does nothing other than make" + " the request\n" + ) + hpp += ( + "* response system more symmetrical and (hopefully) more easy to understand. " + " All this struct\n" + ) + hpp += ( + "* does is make it explicit that this request is being passed from the agent to" + " the agent to\n" + ) + hpp += "* the position.\n" + hpp += "*\n" + hpp += "*/\n" + hpp += "struct AgentPosRequestWrapper {\n" + hpp += "\tAgentRequest request;\n" + hpp += "};\n\n" + + hpp += "/**\n" + hpp += ( + "* @brief Wraps a communication response by giving the robot the communication" + " is from.\n" + ) + hpp += "*\n" + hpp += ( + "* the AgentPosResponseWrapper is the actual thing being passed from the agent" + " to the position\n" + ) + hpp += ( + "* once either the timeout period was reached or enough responses were" + " received. Ideally, the\n" + ) + hpp += ( + "* contents of this wrapper should contain all of the non-message specific" + " fields that a position\n" + ) + hpp += "* will need to handle a response.\n" + hpp += "*\n" + hpp += "*/\n" + hpp += "struct AgentPosResponseWrapper {\n" + hpp += "\tAgentRequest associated_request;\n" + hpp += "\tstd::vector to_robot_ids;\n" + hpp += "\tstd::vector received_robot_ids;\n" + hpp += "\tbool broadcast;\n" + hpp += "\tbool urgent;\n" + hpp += "\tRJ::Time created;\n" + hpp += "\tstd::vector responses;\n" + hpp += "};\n\n" + hpp += "}\n\n" + + hpp += "namespace rj_convert {\n\n" + hpp += "template <>\n" + hpp += ( + "struct RosConverter {\n" + ) + hpp += ( + "\tstatic rj_msgs::msg::AgentRequest to_ros(const" + " strategy::communication::AgentRequest& from) {\n" + ) + hpp += "\t\trj_msgs::msg::AgentRequest result;\n" + hpp += "\t\t" + for request in requests_msgs: + msgName = convert_msg_to_hpp_include(request)[22:-5] + hpp += ( + "if (const auto* " + + msgName + + " = std::get_if(&from)) {\n" + ) + hpp += ( + "\t\t\tresult." + + msgName + + ".emplace_back(convert_to_ros(*" + + msgName + + "));\n" + ) + hpp += "\t\t} else " + hpp += "{\n" + hpp += '\t\t\tthrow std::runtime_error("Invalid variant of AgentRequest");\n' + hpp += "\t\t}\n" + hpp += "\t\treturn result;\n" + hpp += "\t}\n\n" + + hpp += ( + "\tstatic strategy::communication::AgentRequest from_ros(const" + " rj_msgs::msg::AgentRequest& from) {\n" + ) + hpp += "\t\tstrategy::communication::AgentRequest result;\n\t\t" + for request in requests_msgs: + msgName = convert_msg_to_hpp_include(request)[22:-5] + hpp += "if (!from." + msgName + ".empty()) {\n" + hpp += "\t\t\tresult = convert_from_ros(from." + msgName + ".front());\n" + hpp += "\t\t} else " + hpp += "{\n" + hpp += '\t\t\tthrow std::runtime_error("Invalid variant of AgentRequest");\n' + hpp += "\t\t}\n" + hpp += "\t\treturn result;\n" + hpp += "\t}\n\n" + hpp += "};\n\n" + hpp += ( + "ASSOCIATE_CPP_ROS(strategy::communication::AgentRequest," + " rj_msgs::msg::AgentRequest);\n\n" + ) + + hpp += "template <>\n" + hpp += ( + "struct RosConverter {\n" + ) + hpp += ( + "\tstatic rj_msgs::msg::AgentResponse to_ros(const" + " strategy::communication::AgentResponse& from) {\n" + ) + hpp += "\t\trj_msgs::msg::AgentResponse result;\n" + hpp += ( + "\t\tresult.associated_request = convert_to_ros(from.associated_request);\n\t\t" + ) + for response in response_msgs: + msgName = convert_msg_to_hpp_include(response)[22:-5] + hpp += ( + "if (const auto* " + + msgName + + " = std::get_if(&(from.response))) {\n" + ) + hpp += ( + "\t\t\tresult.response." + + msgName + + ".emplace_back(convert_to_ros(*" + + msgName + + "));\n" + ) + hpp += "\t\t} else " + hpp += "{\n" + hpp += '\t\t\tthrow std::runtime_error("Invalid variant of AgentResponse");\n' + hpp += "\t\t}\n" + hpp += "\t\treturn result;\n" + hpp += "\t}\n\n" + + hpp += ( + "\tstatic strategy::communication::AgentResponse from_ros(const" + " rj_msgs::msg::AgentResponse& from) {\n" + ) + hpp += "\t\tstrategy::communication::AgentResponse result;\n" + hpp += ( + "\t\tresult.associated_request =" + " convert_from_ros(from.associated_request);\n\t\t" + ) + for response in response_msgs: + msgName = convert_msg_to_hpp_include(response)[22:-5] + hpp += "if (!from.response." + msgName + ".empty()) {\n" + hpp += ( + "\t\t\tresult.response = convert_from_ros(from.response." + + msgName + + ".front());\n" + ) + hpp += "\t\t} else " + hpp += "{\n" + hpp += '\t\t\tthrow std::runtime_error("Invalid variant of AgentResponse");\n' + hpp += "\t\t}\n" + hpp += "\t\treturn result;\n" + hpp += "\t}\n\n" + hpp += "};\n\n" + + hpp += ( + "ASSOCIATE_CPP_ROS(strategy::communication::AgentResponse," + " rj_msgs::msg::AgentResponse);\n\n" + ) + hpp += "}" + return hpp + + +def create_main_hpp_file(requests_msgs, response_msgs, hpp_names): + hpp = convert_main_hpp_file(requests_msgs, response_msgs, hpp_names) + with open("communication.hpp", "w") as f: + f.write(hpp) + + +def update_cmake(requests_msgs, response_msgs): + with open("../../../../../../rj_msgs/CMakeLists.txt", "r") as f: + contents = f.read().split("\n") + + start = contents.index(" # Agent Request Messages") + end = contents.index(" # Services") + + requests = [" request/" + request for request in requests_msgs] + responses = [" response/" + response for response in response_msgs] + + contents = ( + contents[:start] + + [" # Agent Request Messages"] + + requests + + ["\n # Agent Response Messages"] + + responses + + [""] + + contents[end:] + ) + + with open("../../../../../../rj_msgs/CMakeLists.txt", "w") as f: + f.write("\n".join(contents)) + + +def update_agent_message(requests_msgs, response_msgs): + with open("../../../../../../rj_msgs/msg/AgentRequest.msg", "r") as f: + contents = f.read().split("\n") + + end = contents.index("# ACKNOWLEDGE REQUEST DOES NOT (AND SHOULD NOT) EXIST") + + requests = [ + request[:-4] + "[<=1] " + convert_msg_to_hpp_include(request)[22:-5] + for request in requests_msgs + ] + responses = [ + response[:-4] + "[<=1] " + convert_msg_to_hpp_include(response)[22:-5] + for response in response_msgs + ] + + contents = contents[: end + 1] + requests + + with open("../../../../../../rj_msgs/msg/AgentRequest.msg", "w") as f: + f.write("\n".join(contents)) + + with open("../../../../../../rj_msgs/msg/AgentResponseVariant.msg", "w") as f: + f.write("\n".join(responses)) + + +if __name__ == "__main__": + path_request = "../../../../../../rj_msgs/request" + path_response = "../../../../../../rj_msgs/response" + + requests_msgs = os.listdir(path_request) + response_msgs = os.listdir(path_response) + + hpp_names = create_hpp_files( + requests_msgs, path_request, response_msgs, path_response + ) + create_cpp_file(requests_msgs, response_msgs, hpp_names) + create_main_hpp_file(requests_msgs, response_msgs, hpp_names) + update_cmake(requests_msgs, response_msgs) + update_agent_message(requests_msgs, response_msgs) diff --git a/soccer/src/soccer/strategy/agent/communication/incoming_ball_request.hpp b/soccer/src/soccer/strategy/agent/communication/incoming_ball_request.hpp new file mode 100644 index 00000000000..24ec11366c6 --- /dev/null +++ b/soccer/src/soccer/strategy/agent/communication/incoming_ball_request.hpp @@ -0,0 +1,49 @@ +#pragma once + +#include +#include +#include +#include + +#include +#include + +#include "rj_msgs/msg/incoming_ball_request.hpp" + +namespace strategy::communication { + +struct IncomingBallRequest { + 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, + }; + } +}; + +ASSOCIATE_CPP_ROS(strategy::communication::IncomingBallRequest, rj_msgs::msg::IncomingBallRequest); + +} // 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 new file mode 100644 index 00000000000..eb45b69e4d3 --- /dev/null +++ b/soccer/src/soccer/strategy/agent/communication/join_wall_request.hpp @@ -0,0 +1,48 @@ +#pragma once + +#include +#include +#include +#include + +#include +#include + +#include "rj_msgs/msg/join_wall_request.hpp" + +namespace strategy::communication { + +struct JoinWallRequest { + 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, + }; + } +}; + +ASSOCIATE_CPP_ROS(strategy::communication::JoinWallRequest, rj_msgs::msg::JoinWallRequest); + +} // 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 new file mode 100644 index 00000000000..d69e52b67b5 --- /dev/null +++ b/soccer/src/soccer/strategy/agent/communication/join_wall_response.hpp @@ -0,0 +1,48 @@ +#pragma once + +#include +#include +#include +#include + +#include +#include + +#include "rj_msgs/msg/join_wall_response.hpp" + +namespace strategy::communication { + +struct JoinWallResponse { + 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, + }; + } +}; + +ASSOCIATE_CPP_ROS(strategy::communication::JoinWallResponse, rj_msgs::msg::JoinWallResponse); + +} // 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 new file mode 100644 index 00000000000..51218590f16 --- /dev/null +++ b/soccer/src/soccer/strategy/agent/communication/leave_wall_request.hpp @@ -0,0 +1,48 @@ +#pragma once + +#include +#include +#include +#include + +#include +#include + +#include "rj_msgs/msg/leave_wall_request.hpp" + +namespace strategy::communication { + +struct LeaveWallRequest { + 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, + }; + } +}; + +ASSOCIATE_CPP_ROS(strategy::communication::LeaveWallRequest, rj_msgs::msg::LeaveWallRequest); + +} // 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 new file mode 100644 index 00000000000..7510e24e952 --- /dev/null +++ b/soccer/src/soccer/strategy/agent/communication/leave_wall_response.hpp @@ -0,0 +1,48 @@ +#pragma once + +#include +#include +#include +#include + +#include +#include + +#include "rj_msgs/msg/leave_wall_response.hpp" + +namespace strategy::communication { + +struct LeaveWallResponse { + 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, + }; + } +}; + +ASSOCIATE_CPP_ROS(strategy::communication::LeaveWallResponse, rj_msgs::msg::LeaveWallResponse); + +} // 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 new file mode 100644 index 00000000000..c499edf5179 --- /dev/null +++ b/soccer/src/soccer/strategy/agent/communication/pass_request.hpp @@ -0,0 +1,49 @@ +#pragma once + +#include +#include +#include +#include + +#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; +}; + +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, + }; + } +}; + +ASSOCIATE_CPP_ROS(strategy::communication::PassRequest, rj_msgs::msg::PassRequest); + +} // 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 new file mode 100644 index 00000000000..e96cd3c5dd1 --- /dev/null +++ b/soccer/src/soccer/strategy/agent/communication/pass_response.hpp @@ -0,0 +1,46 @@ +#pragma once + +#include +#include +#include +#include + +#include +#include + +#include "rj_msgs/msg/pass_response.hpp" + +namespace strategy::communication { + +struct PassResponse { + 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, + }; + } +}; + +ASSOCIATE_CPP_ROS(strategy::communication::PassResponse, rj_msgs::msg::PassResponse); + +} // 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 new file mode 100644 index 00000000000..5232655c3b7 --- /dev/null +++ b/soccer/src/soccer/strategy/agent/communication/position_request.hpp @@ -0,0 +1,45 @@ +#pragma once + +#include +#include +#include +#include + +#include +#include + +#include "rj_msgs/msg/position_request.hpp" + +namespace strategy::communication { + +struct PositionRequest { + 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, + }; + } +}; + +ASSOCIATE_CPP_ROS(strategy::communication::PositionRequest, rj_msgs::msg::PositionRequest); + +} // 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 new file mode 100644 index 00000000000..e40ab07e3c0 --- /dev/null +++ b/soccer/src/soccer/strategy/agent/communication/position_response.hpp @@ -0,0 +1,48 @@ +#pragma once + +#include +#include +#include +#include + +#include +#include + +#include "rj_msgs/msg/position_response.hpp" + +namespace strategy::communication { + +struct PositionResponse { + 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, + }; + } +}; + +ASSOCIATE_CPP_ROS(strategy::communication::PositionResponse, rj_msgs::msg::PositionResponse); + +} // 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 new file mode 100644 index 00000000000..32848b5a3c4 --- /dev/null +++ b/soccer/src/soccer/strategy/agent/communication/reset_scorer_request.hpp @@ -0,0 +1,45 @@ +#pragma once + +#include +#include +#include +#include + +#include +#include + +#include "rj_msgs/msg/reset_scorer_request.hpp" + +namespace strategy::communication { + +struct ResetScorerRequest { + 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, + }; + } +}; + +ASSOCIATE_CPP_ROS(strategy::communication::ResetScorerRequest, rj_msgs::msg::ResetScorerRequest); + +} // 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 new file mode 100644 index 00000000000..116934d48d3 --- /dev/null +++ b/soccer/src/soccer/strategy/agent/communication/scorer_request.hpp @@ -0,0 +1,50 @@ +#pragma once + +#include +#include +#include +#include + +#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; +}; + +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, + }; + } +}; + +ASSOCIATE_CPP_ROS(strategy::communication::ScorerRequest, rj_msgs::msg::ScorerRequest); + +} // 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 new file mode 100644 index 00000000000..99d94e0aa55 --- /dev/null +++ b/soccer/src/soccer/strategy/agent/communication/scorer_response.hpp @@ -0,0 +1,51 @@ +#pragma once + +#include +#include +#include +#include + +#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; +}; + +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, + }; + } +}; + +ASSOCIATE_CPP_ROS(strategy::communication::ScorerResponse, rj_msgs::msg::ScorerResponse); + +} // 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 new file mode 100644 index 00000000000..62c79a7c2e6 --- /dev/null +++ b/soccer/src/soccer/strategy/agent/communication/test_request.hpp @@ -0,0 +1,43 @@ +#pragma once + +#include +#include +#include +#include + +#include +#include + +#include "rj_msgs/msg/test_request.hpp" + +namespace strategy::communication { + +struct TestRequest { + 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, + }; + } +}; + +ASSOCIATE_CPP_ROS(strategy::communication::TestRequest, rj_msgs::msg::TestRequest); + +} // 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 new file mode 100644 index 00000000000..034cae56c99 --- /dev/null +++ b/soccer/src/soccer/strategy/agent/communication/test_response.hpp @@ -0,0 +1,46 @@ +#pragma once + +#include +#include +#include +#include + +#include +#include + +#include "rj_msgs/msg/test_response.hpp" + +namespace strategy::communication { + +struct TestResponse { + 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, + }; + } +}; + +ASSOCIATE_CPP_ROS(strategy::communication::TestResponse, rj_msgs::msg::TestResponse); + +} // namespace rj_convert \ No newline at end of file