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

Tune Pass Speed with Pass Distance #2918

Merged

Conversation

sauravbanna
Copy link
Contributor

Please fill out the following before requesting review on this PR

Description

Before, we would have the problem of a robot passing the ball to another robot too fast. This causes the ball to just bounce off of the receiver's dribbler instead of being caught by it. So, we need to ensure that the pass is received at an acceptable speed.

To do this, this PR makes changes to the Pass Generator to pick an initial speed for a pass such that its final speed is less than the maximum acceptable speed to prevent the bouncing off.

Testing Done

Added a new simulated test just for passing which allows us to test these changes in isolation. Created a new validation to test for the speed at which a pass is received.

Resolved Issues

Resolved #2904

Length Justification and Key Files to Review

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

Copy link
Contributor

@LiCody LiCody left a comment

Choose a reason for hiding this comment

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

LGTM pending nits
edit: oops didnt see that it was a draft

src/proto/parameters.proto Show resolved Hide resolved
pass_destination.y() - ball_position.y());
double pass_distance_length = pass_distance.length();

double deceleration = -0.5;
Copy link
Contributor

Choose a reason for hiding this comment

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

can we pull this out to either a file-level constant or global constant

Comment on lines 426 to 429
power = qBound(
0.05f,
m_sslCommand.kick_speed() - (ball->speed().length() / SIMULATOR_SCALE),
m_specs.shot_linear_max());
Copy link
Contributor

Choose a reason for hiding this comment

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

on saturday, we talked about doing this bound only if the ball's current speed is lower than some threshold

Comment on lines 425 to 432
// we subtract the current speed of the ball from the intended kick speed
// this ensures the ball leaves the robot at exactly the speed we want
power = qBound(0.05f,
ball->speed().length() < kickSpeedBoundThreshold
? m_sslCommand.kick_speed() -
(ball->speed().length() / SIMULATOR_SCALE)
: m_sslCommand.kick_speed(),
m_specs.shot_linear_max());
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Could you split the lower bound into a separate if statement?

Comment on lines 428 to 436
if (ball->speed().length() < kickSpeedBoundThreshold)
{
lowerBound =
m_sslCommand.kick_speed() - (ball->speed().length() / SIMULATOR_SCALE)
}
else
{
lowerBound = m_sslCommand.kick_speed()
}
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
if (ball->speed().length() < kickSpeedBoundThreshold)
{
lowerBound =
m_sslCommand.kick_speed() - (ball->speed().length() / SIMULATOR_SCALE)
}
else
{
lowerBound = m_sslCommand.kick_speed()
}
if (ball->speed().length() < kickSpeedBoundThreshold)
{
lowerBound =
m_sslCommand.kick_speed() - (ball->speed().length() / SIMULATOR_SCALE);
}
else
{
lowerBound = m_sslCommand.kick_speed();
}

nimazareian
nimazareian previously approved these changes May 25, 2024
Copy link
Contributor

@nimazareian nimazareian left a comment

Choose a reason for hiding this comment

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

🔥

* @param field The field from which we determine the friendly half
* @param pass The pass to rate
* @param passing_config The passing config used for tuning
* @return
Copy link
Contributor

Choose a reason for hiding this comment

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

return description missing

Comment on lines +42 to +55
double ratePassBackwardsQuality(const Field& field, const Pass& pass,
TbotsProto::PassingConfig& passing_config)
{
if (field.pointInFriendlyHalf(pass.receiverPoint()) &&
field.pointInEnemyHalf(pass.passerPoint()))
{
double pass_distance = (pass.receiverPoint() - pass.passerPoint()).length();
if (pass_distance > passing_config.backwards_pass_distance())
{
return 0;
}
}

return 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be better to approach 0 as the pass distance increases instead of straight up returning a 0. There may be some times when a long backwards pass is actually a good option (maybe its the only way to avoid turning over possession), so the other cost functions might have very high ratings that would be annihilated by this cost function returning 0.

@sauravbanna sauravbanna merged commit f021404 into UBC-Thunderbots:master May 29, 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.

Gameplay: Tune pass speed with pass distance
7 participants