From 4cd6d0958862707a228add9d7899ff81c4d45e7f Mon Sep 17 00:00:00 2001 From: oddlyspookycherry Date: Tue, 13 Feb 2024 21:48:40 -0500 Subject: [PATCH] Implement soccer_mom --- launch/soccer.launch.py | 8 +++++ soccer/CMakeLists.txt | 9 ++++++ soccer/src/soccer/CMakeLists.txt | 6 ++++ soccer/src/soccer/soccer_mom/soccer_mom.cpp | 29 +++++++++++++++++++ soccer/src/soccer/soccer_mom/soccer_mom.hpp | 22 ++++++++++++++ .../soccer_mom/soccer_mom_node_main.cpp | 8 +++++ 6 files changed, 82 insertions(+) create mode 100644 soccer/src/soccer/soccer_mom/soccer_mom.cpp create mode 100644 soccer/src/soccer/soccer_mom/soccer_mom.hpp create mode 100644 soccer/src/soccer/soccer_mom/soccer_mom_node_main.cpp diff --git a/launch/soccer.launch.py b/launch/soccer.launch.py index c908a878999..7255eaeca0c 100644 --- a/launch/soccer.launch.py +++ b/launch/soccer.launch.py @@ -147,6 +147,14 @@ def generate_launch_description(): parameters=[param_config_filepath], on_exit=Shutdown(), ), + Node( + condition=IfCondition(PythonExpression([run_sim])), + package="rj_robocup", + executable="soccer_mom_node", + output="screen", + parameters=[param_config_filepath], + on_exit=Shutdown(), + ) Node( condition=IfCondition(PythonExpression(["not ", run_sim])), package="rj_robocup", diff --git a/soccer/CMakeLists.txt b/soccer/CMakeLists.txt index df564030637..5575d7528a6 100644 --- a/soccer/CMakeLists.txt +++ b/soccer/CMakeLists.txt @@ -82,6 +82,7 @@ add_executable(external_referee_node) add_executable(planner_node) add_executable(control_node) add_executable(sim_radio_node) +add_executable(soccer_mom_node) add_executable(network_radio_node) add_executable(manual_control_node) add_executable(global_param_server_node) @@ -172,6 +173,9 @@ set(REFEREE_NODE_DEPS_LIBRARIES robocup) set(RADIO_NODE_DEPS_SYSTEM_LIBRARIES) set(RADIO_NODE_DEPS_LIBRARIES robocup) +set(SOCCER_MOM_NODE_DEPS_SYSTEM_LIBRARIES) +set(SOCCER_MOM_DEPS_LIBRARIES robocup) + set(CONTROL_NODE_DEPS_SYSTEM_LIBRARIES) set(CONTROL_NODE_DEPS_LIBRARIES robocup) @@ -221,6 +225,10 @@ target_link_libraries(external_referee_node PRIVATE ${REFEREE_NODE_DEPS_SYSTEM_L target_link_libraries(internal_referee_node PRIVATE ${REFEREE_NODE_DEPS_SYSTEM_LIBRARIES} ${REFEREE_NODE_DEPS_LIBRARIES}) +# -- soccer_mom node -- +target_link_libraries(soccer_mom_node PRIVATE ${SOCCER_MOM_NODE_DEPS_SYSTEM_LIBRARIES} + ${SOCCER_MOM_NODE_DEPS_LIBRARIES}) + # -- sim_radio_node -- target_link_libraries(sim_radio_node PRIVATE ${RADIO_NODE_DEPS_SYSTEM_LIBRARIES} ${RADIO_NODE_DEPS_LIBRARIES}) @@ -289,6 +297,7 @@ install( planner_node control_node sim_radio_node + soccer_mom_node network_radio_node manual_control_node global_param_server_node diff --git a/soccer/src/soccer/CMakeLists.txt b/soccer/src/soccer/CMakeLists.txt index 9f93219dc06..53531e04648 100644 --- a/soccer/src/soccer/CMakeLists.txt +++ b/soccer/src/soccer/CMakeLists.txt @@ -73,6 +73,7 @@ set(ROBOCUP_LIB_SRC ros2_temp/referee_sub.cpp ros2_temp/autonomy_interface.cpp ros2_temp/debug_draw_interface.cpp + soccer_mom/soccer_mom.cpp strategy/agent/agent_action_client.cpp strategy/agent/communication/communication.cpp strategy/agent/position/position.cpp @@ -123,6 +124,8 @@ set(SIM_RADIO_NODE_SRC radio/sim_radio_node_main.cpp) set(NETWORK_RADIO_NODE_SRC radio/network_radio_node_main.cpp) +set(SOCCER_MOM_NODE_SRC soccer_mom/soccer_mom_node_main.cpp) + set(MANUAL_CONTROL_NODE_SRC joystick/manual_control_node_main.cpp) set(GLOBAL_PARAMETER_SERVER_NODE_SRC global_param_server.cpp) @@ -163,6 +166,9 @@ target_sources(sim_radio_node PRIVATE ${SIM_RADIO_NODE_SRC}) # ---- sim_radio_node ---- target_sources(network_radio_node PRIVATE ${NETWORK_RADIO_NODE_SRC}) +# ---- soccer mom node ---- +target_sources(soccer_mom_node PRIVATE ${SOCCER_MOM_NODE_SRC}) + # ---- manual_control_node ---- target_sources(manual_control_node PRIVATE ${MANUAL_CONTROL_NODE_SRC}) diff --git a/soccer/src/soccer/soccer_mom/soccer_mom.cpp b/soccer/src/soccer/soccer_mom/soccer_mom.cpp new file mode 100644 index 00000000000..5d4b1238143 --- /dev/null +++ b/soccer/src/soccer/soccer_mom/soccer_mom.cpp @@ -0,0 +1,29 @@ +#include "soccer_mom.hpp" + +namespace tutorial { + +SoccerMom::SoccerMom() + : Node{"soccer_mom", rclcpp::NodeOptions{} + .automatically_declare_parameters_from_overrides(true) + .allow_undeclared_parameters(true)} { + team_color_sub_ = create_subscription( + referee::topics::kTeamColorTopic, rclcpp::QoS(1).transient_local(), + [this](rj_msgs::msg::TeamColor::SharedPtr color) { // NOLINT + publish_fruit(color->is_blue); + }); + + mom_msg_pub_ = create_publisher( + pub_topic, rclcpp::QoS(1)); +} + +void SoccerMom::publish_fruit(bool is_blue_team) { + auto msg = std::make_unique(); + if (is_blue_team) { + msg->data = "blueberries"; + } else { + msg->data = "banana"; + } + mom_msg_pub_->publish(std::move(msg)); +} + +} // namespace tutorial \ No newline at end of file diff --git a/soccer/src/soccer/soccer_mom/soccer_mom.hpp b/soccer/src/soccer/soccer_mom/soccer_mom.hpp new file mode 100644 index 00000000000..b98d3dc883d --- /dev/null +++ b/soccer/src/soccer/soccer_mom/soccer_mom.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include +#include + +#include "std_msgs/msg/string.hpp" +#include "rj_msgs/msg/team_color.hpp" + +namespace tutorial { + +class SoccerMom : public rclcpp::Node { +public: + SoccerMom(); + +private: + void publish_fruit(bool is_blue_team); + rclcpp::Publisher::SharedPtr mom_msg_pub_; + rclcpp::Subscription::SharedPtr team_color_sub_; + const std::string pub_topic = "team_fruit"; +}; + +} // namespace tutorial \ No newline at end of file diff --git a/soccer/src/soccer/soccer_mom/soccer_mom_node_main.cpp b/soccer/src/soccer/soccer_mom/soccer_mom_node_main.cpp new file mode 100644 index 00000000000..b38a23d343e --- /dev/null +++ b/soccer/src/soccer/soccer_mom/soccer_mom_node_main.cpp @@ -0,0 +1,8 @@ +#include "soccer_mom.hpp" + +int main(int argc, char** argv) { + rclcpp::init(argc, argv); + + auto soccer_mom = std::make_shared(); + rclcpp::spin(soccer_mom); +} \ No newline at end of file