Skip to content
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

Position Monitoring Framework #2194

Merged
merged 10 commits into from
Feb 28, 2024
1 change: 1 addition & 0 deletions rj_msgs/msg/AgentState.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
string state
4 changes: 4 additions & 0 deletions soccer/src/soccer/strategy/agent/position/defense.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ std::optional<RobotIntent> Defense::derived_get_task(RobotIntent intent) {
return state_to_task(intent);
}

std::string Defense::get_current_state() {
return std::string{"Defense"} + std::to_string(static_cast<int>(current_state_));
}

Defense::State Defense::update_state() {
State next_state = current_state_;
// handle transitions between states
Expand Down
2 changes: 2 additions & 0 deletions soccer/src/soccer/strategy/agent/position/defense.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <cmath>
#include <string>

#include <rclcpp/rclcpp.hpp>
#include <rclcpp_action/rclcpp_action.hpp>
Expand Down Expand Up @@ -35,6 +36,7 @@ class Defense : public Position {
void derived_acknowledge_pass() override;
void derived_pass_ball() override;
void derived_acknowledge_ball_in_transit() override;
std::string get_current_state() override;

void die() override;
void revive() override;
Expand Down
2 changes: 2 additions & 0 deletions soccer/src/soccer/strategy/agent/position/goal_kicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ std::optional<RobotIntent> GoalKicker::derived_get_task(RobotIntent intent) {
return intent;
}

std::string GoalKicker::get_current_state() { return "GoalKicker"; }

void GoalKicker::derived_acknowledge_pass() {}

void GoalKicker::derived_pass_ball() {}
Expand Down
4 changes: 4 additions & 0 deletions soccer/src/soccer/strategy/agent/position/goal_kicker.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <string>

#include <rclcpp/rclcpp.hpp>

#include "planning/instant.hpp"
Expand Down Expand Up @@ -32,6 +34,8 @@ class GoalKicker : public Position {
*/
void derived_acknowledge_ball_in_transit() override;

std::string get_current_state() override;

private:
std::optional<RobotIntent> derived_get_task(RobotIntent intent) override;
};
Expand Down
2 changes: 2 additions & 0 deletions soccer/src/soccer/strategy/agent/position/goalie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ std::optional<RobotIntent> Goalie::derived_get_task(RobotIntent intent) {
return state_to_task(intent);
}

std::string Goalie::get_current_state() { return "Goalie"; }

Goalie::State Goalie::update_state() {
// if a shot is coming, override all and go block it
WorldState* world_state = last_world_state_;
Expand Down
3 changes: 3 additions & 0 deletions soccer/src/soccer/strategy/agent/position/goalie.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <cmath>
#include <string>

#include <spdlog/spdlog.h>

Expand Down Expand Up @@ -28,6 +29,8 @@ class Goalie : public Position {
void derived_pass_ball() override;
void derived_acknowledge_ball_in_transit() override;

std::string get_current_state() override;

private:
// point goalie will aim for when clearing balls
const rj_geometry::Point clear_point_{0.0, 4.5};
Expand Down
4 changes: 4 additions & 0 deletions soccer/src/soccer/strategy/agent/position/offense.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ std::optional<RobotIntent> Offense::derived_get_task(RobotIntent intent) {
return state_to_task(intent);
}

std::string Offense::get_current_state() {
return std::string{"Offense"} + std::to_string(static_cast<int>(current_state_));
}

Offense::State Offense::update_state() {
State next_state = current_state_;
// handle transitions between current state
Expand Down
3 changes: 3 additions & 0 deletions soccer/src/soccer/strategy/agent/position/offense.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <chrono>
#include <cmath>
#include <string>

#include <rclcpp/rclcpp.hpp>
#include <rclcpp_action/rclcpp_action.hpp>
Expand Down Expand Up @@ -36,6 +37,8 @@ class Offense : public Position {
void derived_pass_ball() override;
void derived_acknowledge_ball_in_transit() override;

std::string get_current_state() override;

private:
bool kicking_{true};

Expand Down
2 changes: 2 additions & 0 deletions soccer/src/soccer/strategy/agent/position/penalty_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ std::optional<RobotIntent> PenaltyPlayer::derived_get_task(RobotIntent intent) {
return intent;
}

std::string PenaltyPlayer::get_current_state() { return "PenaltyPlayer"; }

void PenaltyPlayer::derived_acknowledge_pass() {}

void PenaltyPlayer::derived_pass_ball() {}
Expand Down
4 changes: 4 additions & 0 deletions soccer/src/soccer/strategy/agent/position/penalty_player.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <string>

#include <rclcpp/rclcpp.hpp>

#include "planning/instant.hpp"
Expand Down Expand Up @@ -32,6 +34,8 @@ class PenaltyPlayer : public Position {
*/
void derived_acknowledge_ball_in_transit() override;

std::string get_current_state() override;

private:
std::optional<RobotIntent> derived_get_task(RobotIntent intent) override;
};
Expand Down
4 changes: 4 additions & 0 deletions soccer/src/soccer/strategy/agent/position/position.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <cstdlib>
#include <string>
#include <vector>

#include <spdlog/spdlog.h>
Expand Down Expand Up @@ -75,6 +76,9 @@ class Position {
void update_alive_robots(std::vector<u_int8_t> alive_robots);
const std::string get_name();

// returns the current state of the robot
virtual std::string get_current_state() = 0;

/**
* @brief setter for time_left_
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,8 @@ void RobotFactoryPosition::die() { current_position_->die(); }

void RobotFactoryPosition::revive() { current_position_->revive(); }

std::string RobotFactoryPosition::get_current_state() {
return current_position_->get_current_state();
}

} // namespace strategy
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <cmath>
#include <string>

#include <rclcpp/rclcpp.hpp>
#include <rclcpp_action/rclcpp_action.hpp>
Expand Down Expand Up @@ -54,6 +55,8 @@ class RobotFactoryPosition : public Position {
void derived_pass_ball() override;
void derived_acknowledge_ball_in_transit() override;

std::string get_current_state() override;

void set_is_done() override;
void die() override;
void revive() override;
Expand Down
Loading