Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Goalie : public Position {
// current state of Goalie (state machine)
State latest_state_ = IDLING;

rj_geometry::Point penalty_location();
rj_geometry::Point penalty_location(WorldState* world_state);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Consider passing in just the parts of the world_state you need instead of the entire thing

};

} // namespace strategy
47 changes: 44 additions & 3 deletions src/rj_strategy/src/agent/position/goalie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Goalie::State Goalie::update_state() {

// if PlayState is in state Ready and Restart is Penalty go to penalty state
// call is_our_restart and if that is false we go into this state

if (current_play_state_.is_ready() && current_play_state_.is_penalty() &&
!current_play_state_.is_our_restart()) {
return PENALTY;
Expand Down Expand Up @@ -149,7 +150,8 @@ std::optional<RobotIntent> Goalie::state_to_task(RobotIntent intent) {
return intent;
} else if (latest_state_ == PENALTY) {
// stay on baseline
rj_geometry::Point target_pt = penalty_location();

rj_geometry::Point target_pt = penalty_location(last_world_state_);
rj_geometry::Point target_vel{0.0, 0.0};

planning::PathTargetFaceOption face_option =
Expand Down Expand Up @@ -197,11 +199,50 @@ void Goalie::derived_pass_ball() { latest_state_ = PASSING; }

void Goalie::derived_acknowledge_ball_in_transit() { latest_state_ = RECEIVING; }

rj_geometry::Point Goalie::penalty_location() {
rj_geometry::Point Goalie::penalty_location(WorldState* world_state) {
// be dumb: center of baseline
return this->field_dimensions_.our_goal_loc();
// return this->field_dimensions_.our_goal_loc();
// be smart
// find robot on their team closest to ball
std::vector<RobotState> const their_robots = last_world_state_->their_robots;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to make a copy of their_robots. If you really want to keep this, make their_robots a reference.

rj_geometry::Point enemy_location;
rj_geometry::Point enemy_shooter_location;
Comment on lines +208 to +209
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rj_geometry::Point enemy_location;
rj_geometry::Point enemy_shooter_location;


double closest_distance = std::numeric_limits<double>::infinity();
RobotState curr_shooter;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curr_shooter can just store the enemy robot's position, no need to store the entire RobotState

for (const RobotState& enemy : their_robots) {
// Get position of their shooter and the ball
rj_geometry::Point ball_pos = world_state->ball.position;
rj_geometry::Point enemy_location = enemy.pose.position();

double ball_distance = ball_pos.dist_to(enemy_location);

if (ball_distance < closest_distance) {
closest_distance = ball_distance;
curr_shooter = enemy;
}
}

enemy_shooter_location = curr_shooter.pose.position(); // COORDS 1
rj_geometry::Point ball_pos = world_state->ball.position; // COORDS 2

// SPDLOG_INFO("botpos {} {}", enemy_shooter_location.x(), enemy_shooter_location.y());
// SPDLOG_INFO("ballpos {} {}", ball_pos.x(), ball_pos.y());
// SPDLOG_INFO("GOALX {}", field_dimensions_.goal_width());

Comment on lines +228 to +232
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// SPDLOG_INFO("botpos {} {}", enemy_shooter_location.x(), enemy_shooter_location.y());
// SPDLOG_INFO("ballpos {} {}", ball_pos.x(), ball_pos.y());
// SPDLOG_INFO("GOALX {}", field_dimensions_.goal_width());

double goalie_pos_y = field_dimensions_.our_goal_loc().y();
float goalie_pos_x =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this a double

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: use the built-in intersect functions for this

enemy_shooter_location.x() + ((goalie_pos_y - enemy_shooter_location.y()) *
(ball_pos.x() - enemy_shooter_location.x())) /
(ball_pos.y() - enemy_shooter_location.y());

goalie_pos_x = std::clamp(goalie_pos_x, -1 * field_dimensions_.goal_width() / 2,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the field_dimensions_.our_goal_segment() to make this easier for someone to understand

field_dimensions_.goal_width() / 2);

// SPDLOG_INFO("enemy {}", goalie_pos_x);

rj_geometry::Point goaliepose = {goalie_pos_x, goalie_pos_y};
return goaliepose;
Comment on lines +241 to +245
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// SPDLOG_INFO("enemy {}", goalie_pos_x);
rj_geometry::Point goaliepose = {goalie_pos_x, goalie_pos_y};
return goaliepose;
rj_geometry::Point goalie_pos{goalie_pos_x, goalie_pos_y};
return goalie_pos;

To keep consistent with other uses

// line up in line with them and the ball on the baseline
}

Expand Down
Loading