-
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
7b30635
commit d149f07
Showing
6 changed files
with
153 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,44 @@ | ||
#include "soccermom.hpp" | ||
|
||
#include <spdlog/spdlog.h> | ||
|
||
Soccermom::Soccermom(bool blue_team) | ||
: Node{"soccermom", 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 | ||
team_fruit_pub_ = | ||
create_publisher<std_msgs::msg::String>("/team_fruit", rclcpp::QoS(10)); | ||
|
||
if (color->is_blue) { | ||
// publish "blueberries" | ||
auto message = std_msgs::msg::String(); | ||
message.data = "blueberries"; | ||
team_fruit_pub_->publish(message); | ||
} else { | ||
// publish "bananas" | ||
auto message = std_msgs::msg::String(); | ||
message.data = "bananas"; | ||
team_fruit_pub_->publish(message); | ||
} | ||
|
||
}); | ||
|
||
team_fruit_pub_ = create_publisher<std_msgs::msg::String>("/team_fruit", rclcpp::QoS(10)); | ||
|
||
if (blue_team) { | ||
// publish "blueberries" | ||
auto message = std_msgs::msg::String(); | ||
message.data = "blueberries"; | ||
team_fruit_pub_->publish(message); | ||
} else { | ||
// publish "bananas" | ||
auto message = std_msgs::msg::String(); | ||
message.data = "bananas"; | ||
team_fruit_pub_->publish(message); | ||
} | ||
} |
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,76 @@ | ||
#pragma once | ||
|
||
#include <deque> | ||
#include <mutex> | ||
|
||
#include <rclcpp/rclcpp.hpp> | ||
|
||
#include <rj_constants/topic_names.hpp> | ||
#include <rj_msgs/msg/alive_robots.hpp> | ||
#include <rj_msgs/msg/manipulator_setpoint.hpp> | ||
#include <rj_msgs/msg/motion_setpoint.hpp> | ||
#include <rj_msgs/msg/robot_status.hpp> | ||
#include <rj_msgs/msg/team_color.hpp> | ||
#include <rj_param_utils/param.hpp> | ||
#include <rj_param_utils/ros2_local_param_provider.hpp> | ||
|
||
#include "robot_intent.hpp" | ||
#include "std_msgs/msg/string.hpp" | ||
#include "strategy/agent/position/positions.hpp" | ||
|
||
/** | ||
* @brief Sends and receives information to/from our robots. | ||
* | ||
* @details This is the abstract superclass for NetworkRadio and SimRadio, which do | ||
* the actual work - this just declares the interface and handles sending stop commands when no new | ||
* commands come in for a while. | ||
* | ||
* The radio should handle: | ||
* 1. Sending Control Messages to the Robots | ||
* * Alive Robots should be receiving real commands | ||
* * Non-responsive (dead) robots should receive stop commands | ||
* 2. Receiving Robot Status Messages and Publish to the robot status topic | ||
* 3. Calculate Alive Robots and Publish to the alive robots topic | ||
*/ | ||
class Soccermom : public rclcpp::Node { | ||
public: | ||
Soccermom(bool blue_team = false); | ||
|
||
protected: | ||
// Time between consecutive calls to tick(). | ||
std::chrono::milliseconds tick_period_ = std::chrono::milliseconds(100); | ||
// Ros timer to trigger tick every tick_period | ||
rclcpp::TimerBase::SharedPtr tick_timer_; | ||
|
||
// The position of each robot | ||
std::array<strategy::Positions, kNumShells> positions_; | ||
|
||
// Ros publishers to send robot statuses | ||
std::array<rclcpp::Publisher<rj_msgs::msg::RobotStatus>::SharedPtr, kNumShells> | ||
robot_status_pubs_; | ||
|
||
rclcpp::Publisher<std_msgs::msg::String>::SharedPtr team_fruit_pub_; | ||
|
||
// Ros publisher to update alive robots | ||
rclcpp::Publisher<rj_msgs::msg::AliveRobots>::SharedPtr alive_robots_pub_; | ||
|
||
// Ros subscribers to receive velocity commands, which are sent to the robot | ||
std::array<rclcpp::Subscription<rj_msgs::msg::MotionSetpoint>::SharedPtr, kNumShells> | ||
motion_subs_; | ||
// Last Update Timestamps (per robot) | ||
std::array<RJ::Time, kNumShells> last_updates_ = {}; | ||
// Cached last velocity command | ||
std::array<rj_msgs::msg::MotionSetpoint::SharedPtr, kNumShells> motions_; | ||
|
||
// Ros subscribers to receive auxillary control (i.e. shoot_mode, trigger_mode, kick_speed, and | ||
// dribbler_speed) which are stored and sent to the robot | ||
std::array<rclcpp::Subscription<rj_msgs::msg::ManipulatorSetpoint>::SharedPtr, kNumShells> | ||
manipulator_subs_; | ||
// Cached auxillary control information | ||
std::array<rj_msgs::msg::ManipulatorSetpoint, kNumShells> manipulators_cached_; | ||
|
||
// Ros subscriber for the team's color. | ||
rclcpp::Subscription<rj_msgs::msg::TeamColor>::SharedPtr team_color_sub_; | ||
// Whether or not the current team color is blue | ||
bool blue_team_; | ||
}; |
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,13 @@ | ||
#include <rj_common/network.hpp> | ||
#include <rj_utils/logging.hpp> | ||
|
||
#include "global_params.hpp" | ||
#include "soccermom.hpp" | ||
|
||
int main(int argc, char** argv) { | ||
rclcpp::init(argc, argv); | ||
rj_utils::set_spdlog_default_ros2("processor"); | ||
|
||
auto soccermom = std::make_shared<Soccermom>(); | ||
rclcpp::spin(soccermom); | ||
} |