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 FSM #2173

Merged
merged 9 commits into from
Feb 5, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,69 @@
}
}

std::optional<RobotIntent> RobotFactoryPosition::get_task(WorldState& world_state,

Check warning on line 17 in soccer/src/soccer/strategy/agent/position/robot_factory_position.cpp

View workflow job for this annotation

GitHub Actions / build-and-test

function 'get_task' has cognitive complexity of 28 (threshold 25)
FieldDimensions& field_dimensions) {
// This is where the current_position can be reassigned based on the
// PlayState
// If keeper, make no changes
if (robot_id_ == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

you can't assume 0 is the robot id. you need to get that information from the referee. If i'm not mistaken, there is already a mechanism for AAC to pass this information to its Position. if not, let's figure out how to add it.

return current_position_->get_task(world_state, field_dimensions);
}

// TODO (Rishi and Jack): Make this synchronized across all robots to avoid race conditions

// Get sorted positions of all friendly robots
using RobotPos = std::pair<int, double>; // (robotId, yPosition)

std::vector<RobotPos> robots_copy;
for (int i = 0; i < 6; i++) {
// Ignore goalie
if (i == 0) {
continue;
}
robots_copy.emplace_back(i, world_state.our_robots[i].pose.position().y());
}

std::sort(robots_copy.begin(), robots_copy.end(),
[](RobotPos const& a, RobotPos const& b) { return a.second < b.second; });

// Find relative location of current robot
int i = 0;
for (RobotPos r : robots_copy) {
if (r.first == robot_id_) {
break;
}
i++;
}

// Assigning new position
// Checking whether we have possesion or if the ball is on their half (using 1.99 to avoid
// rounding issues on midline)
if (Position::our_possession_ ||
rishiso marked this conversation as resolved.
Show resolved Hide resolved
world_state.ball.position.y() > field_dimensions.length() / 1.99) {
// Offensive mode
// Closest 2 robots on defense, rest on offense
if (i <= 1) {
if (current_position_->get_name() != "Defense") {
current_position_ = std::make_unique<Defense>(robot_id_);
}
} else {
if (current_position_->get_name() != "Offense") {
current_position_ = std::make_unique<Offense>(robot_id_);
}
}
} else {
// Defensive mode
// Closest 4 robots on defense, rest on offense
if (i <= 3) {
if (current_position_->get_name() != "Defense") {
current_position_ = std::make_unique<Defense>(robot_id_);
}
} else {
if (current_position_->get_name() != "Offense") {
current_position_ = std::make_unique<Offense>(robot_id_);
}
}
}

return current_position_->get_task(world_state, field_dimensions);
}

Expand Down
Loading