-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1926726
commit 4cd6d09
Showing
6 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
|
||
#include <rclcpp/rclcpp.hpp> | ||
#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"; | ||
}; | ||
|
||
} // namespace tutorial |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |