Skip to content

Improve FreeKickPlay behaviour and convert it to use FSMs #2953

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

Merged
merged 256 commits into from
Jul 16, 2024

Conversation

raymond212
Copy link
Contributor

@raymond212 raymond212 commented Jun 30, 2023

Description

❗ This PR is dependent on the changes from #3200, as such, it's in a draft state until that is merged. Please comment any passing/receiving related suggestions in that PR and for the time being only focus on suggestions around the changes listed below in this PR.

Improved FreeKickPlay:

  1. Reimplemented it using FSMs

  2. Used KickTactic instead of AttackerTactic to ensure that we do not dribble

  3. Deleted CornerKickPlay

  4. Update KickFSM and ChipFSM to make sure that the robot is aligned to the kick/chip direction of the latest control params. Also update how far we drive into the ball.

  5. Update GetBehindBallFSM's guard to be more strict on the robot's alignment with the ball. The width of the region has been updated to have the same tolerance that the ball has to be within for it to not hit the side of the dribbler.
    Old region that the robot had to be within to be counted as "behind ball":
    image
    Updated region:
    image

  6. Update some of the constants related to the robots based on the most up to date CAD.

Todo:

  • Add validation for free kick play

Testing Done

Tried free kicks in AI vs AI and updated existing tests

Resolved Issues

resolves #2950, resolves #3205

Length Justification and Key Files to Review

free_kick_play_fsm.h and free_kick_play_fsm.cpp.

Review Checklist

It is the reviewers responsibility to also make sure every item here has been covered

  • Function & Class comments: All function definitions (usually in the .h file) should have a javadoc style comment at the start of them. For examples, see the functions defined in thunderbots/software/geom. Similarly, all classes should have an associated Javadoc comment explaining the purpose of the class.
  • Remove all commented out code
  • Remove extra print statements: for example, those just used for testing
  • Resolve all TODO's: All TODO (or similar) statements should either be completed or associated with a github issue

@nimazareian nimazareian marked this pull request as ready for review July 9, 2024 20:18
@nimazareian nimazareian requested a review from itsarune July 9, 2024 20:18
Copy link
Member

@williamckha williamckha left a comment

Choose a reason for hiding this comment

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

LGTM one comment

Comment on lines 28 to 37
// Passing robot
updateAlignToBallTactic(event.common.world_ptr);
tactics_to_run[0].emplace_back(align_to_ball_tactic);

if (event.common.num_tactics <= 1)
{
LOG(WARNING)
<< "Not enough tactics to setup pass receivers and defenders during free kick";
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

The align_to_ball_tactic will not get set if we have num_tactics == 1

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah you're right. I decided to just remove the check. setReceiverAndDefenderTactics already can handle the case where num_tactics = 1. Though If num_tactics = 1, we just chip it towards the center and run towards it since there are no defenders. I hope we won't have to test that in real life 😅

@nimazareian nimazareian requested a review from williamckha July 9, 2024 21:21
williamckha
williamckha previously approved these changes Jul 9, 2024
Comment on lines +247 to +250
double abs_min_pass_score =
ai_config.shoot_or_pass_play_config().abs_min_pass_score();
double min_perfect_pass_score =
ai_config.shoot_or_pass_play_config().min_perfect_pass_score();
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the plan here for when #3246 is merged in? I believe ShootOrPassPlayConfig is going to be removed and replaced with ShotConfig, which is very different.

Copy link
Contributor

Choose a reason for hiding this comment

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

Both PRs are being aimed to be merged with master, so which ever one is merged second will need to fix it. I can't update this PR to use ShotConfig, since it doesn't exist on my branch.

Andrewyx
Andrewyx previously approved these changes Jul 9, 2024
Copy link
Contributor

@Andrewyx Andrewyx left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +63 to +64
// Note that getBestReceivingPositions may return fewer positions than requested
// if there are not enough robots, so we will need to check the size of the vector.
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't it guaranteed to be exactly num_tactics? since receiver_positioning_tactics is resized to num_tactics

Copy link
Contributor

Choose a reason for hiding this comment

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

We actually update num_tactics to be a valid number within getBestReceivingPositions.

// Verify that the number of receiver positions requested is valid
if (num_positions >
(world.friendlyTeam().numRobots() - existing_receiver_positions.size()))
{
LOG(WARNING) << "Not enough friendly robots to assign " << num_positions
<< " receiver positions. Assigning "
<< world.friendlyTeam().numRobots() -
existing_receiver_positions.size()
<< " receiver positions instead";
num_positions = static_cast<unsigned int>(world.friendlyTeam().numRobots() -
existing_receiver_positions.size());
}

Comment on lines +118 to +120
// Face towards the center of the left segment of the enemy defense area,
// so we are prepared to take a shot on enemy net, or pass the ball near
// the enemy defense area.
Copy link
Contributor

Choose a reason for hiding this comment

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

why specifically the negative x negative y corner and not just the enemy goal centre?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is similar to the one of the changes that Andrew had in his CreaseDefender PR. We're getting the center of the left segment of the defense area, and not the center of the defense area.

Copy link
Contributor

Choose a reason for hiding this comment

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

why do we specifically choose that segment?

/**
* Guard on whether to abort the pass
*
* @param event the ShootOrPassPlayFSM Update event
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
* @param event the ShootOrPassPlayFSM Update event
* @param event the FreeKickPlayFSM Update event

Copy link
Contributor

Choose a reason for hiding this comment

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

Updated

Copy link
Contributor

@itsarune itsarune left a comment

Choose a reason for hiding this comment

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

looks good, minor nit

@nimazareian nimazareian dismissed stale reviews from Andrewyx and williamckha via 9f394ec July 15, 2024 07:59
nimazareian added a commit that referenced this pull request Jul 15, 2024
// The distance that the ball has to travel for it to be considered in play
// after a kick-off, free kick, or penalty kick.
// https://robocup-ssl.github.io/ssl-rules/sslrules.html#_ball_in_and_out_of_play
static const double BALL_IN_PLAY_DISTANCE_THRESHOLD_METERS = 0.05;
Copy link
Contributor

Choose a reason for hiding this comment

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

in the future, we can probably use this constant in game_state.cpp. It's a good first member ticket

/**
* Updates the kicker to align to the ball
*
* @param world the latest world
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
* @param world the latest world
* @param world_ptr the latest world

Copy link
Contributor

@itsarune itsarune left a comment

Choose a reason for hiding this comment

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

feel free to merge 🥳

@nimazareian nimazareian merged commit 55a4f24 into UBC-Thunderbots:master Jul 16, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Delete CornerKickPlay [Gameplay] Fix FreeKickPlay and convert it into using FSMs
7 participants