Skip to content

Commit

Permalink
Implement soccer_mom
Browse files Browse the repository at this point in the history
  • Loading branch information
oddlyspookycherry committed Feb 14, 2024
1 parent 1926726 commit 4cd6d09
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 0 deletions.
8 changes: 8 additions & 0 deletions launch/soccer.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions soccer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions soccer/src/soccer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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})

Expand Down
29 changes: 29 additions & 0 deletions soccer/src/soccer/soccer_mom/soccer_mom.cpp
Original file line number Diff line number Diff line change
@@ -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<rj_msgs::msg::TeamColor>(
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<std_msgs::msg::String>(
pub_topic, rclcpp::QoS(1));
}

void SoccerMom::publish_fruit(bool is_blue_team) {
auto msg = std::make_unique<std_msgs::msg::String>();
if (is_blue_team) {
msg->data = "blueberries";
} else {
msg->data = "banana";
}
mom_msg_pub_->publish(std::move(msg));
}

} // namespace tutorial
22 changes: 22 additions & 0 deletions soccer/src/soccer/soccer_mom/soccer_mom.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include <rclcpp/rclcpp.hpp>

Check failure on line 3 in soccer/src/soccer/soccer_mom/soccer_mom.hpp

View workflow job for this annotation

GitHub Actions / build-and-test

'rclcpp/rclcpp.hpp' file not found
#include <rj_constants/topic_names.hpp>

#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<std_msgs::msg::String>::SharedPtr mom_msg_pub_;
rclcpp::Subscription<rj_msgs::msg::TeamColor>::SharedPtr team_color_sub_;
const std::string pub_topic = "team_fruit";

Check warning on line 19 in soccer/src/soccer/soccer_mom/soccer_mom.hpp

View workflow job for this annotation

GitHub Actions / build-and-test

invalid case style for private member 'pub_topic'
};

} // namespace tutorial
8 changes: 8 additions & 0 deletions soccer/src/soccer/soccer_mom/soccer_mom_node_main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "soccer_mom.hpp"

int main(int argc, char** argv) {
rclcpp::init(argc, argv);

auto soccer_mom = std::make_shared<tutorial::SoccerMom>();
rclcpp::spin(soccer_mom);

Check warning on line 7 in soccer/src/soccer/soccer_mom/soccer_mom_node_main.cpp

View workflow job for this annotation

GitHub Actions / build-and-test

variable 'soccer_mom' is not initialized
}

0 comments on commit 4cd6d09

Please sign in to comment.