-
Notifications
You must be signed in to change notification settings - Fork 186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Eduardo rodriguez/robocup sw tutorial #2102
Changes from all commits
54da3b6
2684cba
0d2ad91
99ed1fc
59bd98e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include "soccer_mom.hpp" | ||
|
||
#include <spdlog/spdlog.h> | ||
|
||
namespace soccer_mom { | ||
|
||
SoccerMom::SoccerMom() | ||
: Node{"soccer_mom", rclcpp::NodeOptions{} | ||
.automatically_declare_parameters_from_overrides(true) | ||
.allow_undeclared_parameters(true)} { | ||
team_fruit_pub_ = create_publisher<std_msgs::msg::String>("/team_fruit", 10); | ||
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 | ||
auto message = std_msgs::msg::String(); | ||
message.data = "blueberries"; | ||
if (!color->is_blue) { | ||
message.data = "banana"; | ||
} | ||
team_fruit_pub_->publish(message); | ||
}); | ||
} | ||
|
||
} // namespace soccer_mom |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include <deque> | ||
#include <mutex> | ||
|
||
#include <rclcpp/rclcpp.hpp> | ||
|
||
#include <rj_constants/topic_names.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 <std_msgs/msg/string.hpp> | ||
|
||
#include "robot_intent.hpp" | ||
#include "strategy/coach/coach_node.hpp" | ||
|
||
namespace soccer_mom { | ||
|
||
class SoccerMom : public rclcpp::Node { | ||
public: | ||
SoccerMom(); | ||
|
||
private: | ||
rclcpp::Subscription<rj_msgs::msg::TeamColor>::SharedPtr team_color_sub_; | ||
rclcpp::Publisher<std_msgs::msg::String>::SharedPtr team_fruit_pub_; | ||
}; | ||
|
||
} // namespace soccer_mom |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <rj_common/network.hpp> | ||
#include <rj_utils/logging.hpp> | ||
|
||
#include "global_params.hpp" | ||
#include "soccer_mom.hpp" | ||
|
||
int main(int argc, char** argv) { | ||
rclcpp::init(argc, argv); | ||
rj_utils::set_spdlog_default_ros2("processor"); | ||
|
||
auto radio = std::make_shared<soccer_mom::SoccerMom>(); | ||
start_global_param_provider(radio.get(), kGlobalParamServerNode); | ||
rclcpp::spin(radio); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include "runner.hpp" | ||
|
||
namespace strategy { | ||
|
||
Runner::Runner(int r_id) : Position(r_id) { position_name_ = "Runner"; } | ||
|
||
std::optional<RobotIntent> Runner::derived_get_task(RobotIntent intent) { | ||
current_state_ = update_state(); | ||
return state_to_task(intent); | ||
} | ||
|
||
Runner::State Runner::update_state() { | ||
State next_state = current_state_; | ||
// handle transitions between states | ||
WorldState* world_state = this->world_state(); | ||
rj_geometry::Point robot_position = world_state->get_robot(true, robot_id_).pose.position(); | ||
|
||
switch (current_state_) { | ||
case RIGHT: | ||
if (robot_position.x() <= field_dimensions_.field_x_left_coord() + 1.1) next_state = UP; | ||
break; | ||
case UP: | ||
if (robot_position.y() <= 1.1) next_state = LEFT; | ||
break; | ||
case LEFT: | ||
if (robot_position.x() >= field_dimensions_.field_x_right_coord() - 1.1) | ||
next_state = DOWN; | ||
break; | ||
case DOWN: | ||
if (robot_position.y() >= field_dimensions_.length() - 1.1) next_state = RIGHT; | ||
break; | ||
} | ||
|
||
return next_state; | ||
} | ||
|
||
std::optional<RobotIntent> Runner::state_to_task(RobotIntent intent) { | ||
rj_geometry::Point robot_position = world_state()->get_robot(true, robot_id_).pose.position(); | ||
rj_geometry::Point destination; | ||
|
||
switch (current_state_) { | ||
case RIGHT: | ||
destination = rj_geometry::Point{field_dimensions_.field_x_left_coord() + 1, | ||
field_dimensions_.length() - 1}; | ||
break; | ||
case UP: | ||
destination = rj_geometry::Point{field_dimensions_.field_x_left_coord() + 1, 1}; | ||
break; | ||
case LEFT: | ||
destination = rj_geometry::Point{field_dimensions_.field_x_right_coord() - 1, 1}; | ||
break; | ||
case DOWN: | ||
destination = rj_geometry::Point{field_dimensions_.field_x_right_coord() - 1, | ||
field_dimensions_.length() - 1}; | ||
break; | ||
} | ||
|
||
auto goal = planning::LinearMotionInstant{destination, {0.0, 0.0}}; | ||
auto move_direction = | ||
planning::MotionCommand{"path_target", goal, planning::FaceTarget{}, true}; | ||
|
||
intent.motion_command = move_direction; | ||
return intent; | ||
} | ||
|
||
void Runner::derived_acknowledge_pass() {} | ||
|
||
void Runner::derived_pass_ball() {} | ||
|
||
void Runner::derived_acknowledge_ball_in_transit() {} | ||
|
||
} // namespace strategy |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#pragma once | ||
|
||
#include <cmath> | ||
|
||
#include <rclcpp/rclcpp.hpp> | ||
#include <rclcpp_action/rclcpp_action.hpp> | ||
#include <spdlog/spdlog.h> | ||
|
||
#include <rj_msgs/action/robot_move.hpp> | ||
|
||
#include "planning/instant.hpp" | ||
#include "position.hpp" | ||
#include "rj_common/field_dimensions.hpp" | ||
#include "rj_common/time.hpp" | ||
#include "rj_constants/constants.hpp" | ||
#include "rj_geometry/geometry_conversions.hpp" | ||
#include "rj_geometry/point.hpp" | ||
|
||
namespace strategy { | ||
|
||
/* | ||
* This robot runs in a square path | ||
*/ | ||
class Runner : public Position { | ||
Check warning on line 24 in soccer/src/soccer/strategy/agent/position/runner.hpp GitHub Actions / build-and-test
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note the GH actions here and perhaps read up on the rule of 5. you can set many of those to the default implementation, but it's best to explicitly do so |
||
public: | ||
Runner(int r_id); | ||
~Runner() override = default; | ||
|
||
void derived_acknowledge_pass() override; | ||
void derived_pass_ball() override; | ||
void derived_acknowledge_ball_in_transit() override; | ||
|
||
private: | ||
std::optional<RobotIntent> derived_get_task(RobotIntent intent) override; | ||
|
||
enum State { RIGHT, UP, LEFT, DOWN }; | ||
|
||
State update_state(); | ||
|
||
std::optional<RobotIntent> state_to_task(RobotIntent intent); | ||
|
||
State current_state_ = LEFT; | ||
}; | ||
|
||
} // namespace strategy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note the GH actions warnings here. inline if statements are hard to read! it's fine for now, but won't be approved in the future