-
Notifications
You must be signed in to change notification settings - Fork 186
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
Cameron carson/penalty position dribbling #2336
Changes from 7 commits
75edccc
27f938f
d4585c6
e8f50a3
310f2d7
7873e37
7c2126f
260f458
ffc9fc0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,26 +14,39 @@ std::optional<RobotIntent> PenaltyPlayer::derived_get_task(RobotIntent intent) { | |
|
||
PenaltyPlayer::State PenaltyPlayer::update_state() { | ||
switch (latest_state_) { | ||
case LINE_UP: { | ||
case START: { | ||
// if penalty playing and restart penalty in playstate we switch to shooting | ||
if (current_play_state_.is_ready() && | ||
(current_play_state_.is_penalty() || current_play_state_.is_kickoff())) { | ||
return SHOOTING_START; | ||
return SMALL_KICK; | ||
} | ||
break; | ||
} | ||
case SHOOTING_START: { | ||
case SMALL_KICK: { | ||
if (distance_from_enemy_goal() < kDistanceToGoalThreshold) { | ||
return LINE_UP; | ||
} | ||
break; | ||
} | ||
case LINE_UP: { | ||
if (check_is_done()) { | ||
return SHOOTING; | ||
return SHOOTING_START; | ||
} | ||
if (distance_to_ball() < kOwnBallRadius) { | ||
return SHOOTING_START; | ||
} | ||
break; | ||
} | ||
case SHOOTING_START: { | ||
if (check_is_done()) { | ||
return SHOOTING; | ||
} | ||
CameronLyon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
break; | ||
} | ||
case SHOOTING: { | ||
if (check_is_done()) { | ||
return LINE_UP; | ||
return START; | ||
} | ||
break; | ||
} | ||
|
@@ -43,14 +56,41 @@ PenaltyPlayer::State PenaltyPlayer::update_state() { | |
|
||
std::optional<RobotIntent> PenaltyPlayer::state_to_task(RobotIntent intent) { | ||
switch (latest_state_) { | ||
case LINE_UP: { | ||
case START: { // First, gets the robot to the ball to begin penalty dribbling-shooting | ||
SPDLOG_INFO("START"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like some logging was left here! |
||
double y_pos = last_world_state_->ball.position.y(); | ||
y_pos -= kRobotRadius + 0.3; // added the 0.01 as a buffer space | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this doing--Why 0.3? Also, comment says 0.01. |
||
rj_geometry::Point target_pt{last_world_state_->ball.position.x(), y_pos}; | ||
rj_geometry::Point target_vel{0.0, 0.0}; | ||
// Face ball | ||
planning::PathTargetFaceOption face_option{planning::FaceBall{}}; | ||
|
||
// Create Motion Command | ||
planning::LinearMotionInstant goal{target_pt, target_vel}; | ||
intent.motion_command = | ||
planning::MotionCommand{"path_target", goal, planning::FaceBall{}}; | ||
break; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpicking but you use |
||
} | ||
case SMALL_KICK: { // less of a kick, more of a "follow" ball closely | ||
// SPDLOG_INFO("SMALL_KICK"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's clean these comments up too |
||
rj_geometry::Point center_goal = field_dimensions_.their_goal_loc(); | ||
auto line_kick_cmd = | ||
planning::MotionCommand{"line_kick", planning::LinearMotionInstant{center_goal}}; | ||
|
||
intent.motion_command = line_kick_cmd; | ||
intent.shoot_mode = RobotIntent::ShootMode::KICK; | ||
intent.trigger_mode = RobotIntent::TriggerMode::ON_BREAK_BEAM; | ||
intent.kick_speed = 0.0; | ||
// the point of making a 0 kick speed is to fake dribble since we cannot get the vaccum | ||
// behavior to work | ||
|
||
return intent; | ||
CameronLyon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
case LINE_UP: { // gets the robot behind the ball with a certain distance (usually | ||
// immediatly skipped if the robot is already close) | ||
// SPDLOG_INFO("LINE_UP"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above on cleaning up comments |
||
double y_pos = last_world_state_->ball.position.y(); | ||
// if ball is above goal, increase y_pos, else decrease | ||
// if (y_pos - field_dimensions_.their_goal_loc().y() > 0) { | ||
// y_pos += kRobotRadius - 0.15; | ||
// } else { | ||
y_pos -= kRobotRadius + 0.3; | ||
// } | ||
y_pos -= kRobotRadius + 0.1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the 0.1 doing? Can we relate this to the radius as a ratio or something? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you mean |
||
rj_geometry::Point target_pt{last_world_state_->ball.position.x(), y_pos}; | ||
rj_geometry::Point target_vel{0.0, 0.0}; | ||
// Face ball | ||
|
@@ -62,9 +102,12 @@ std::optional<RobotIntent> PenaltyPlayer::state_to_task(RobotIntent intent) { | |
planning::LinearMotionInstant goal{target_pt, target_vel}; | ||
intent.motion_command = | ||
planning::MotionCommand{"path_target", goal, face_option, ignore_ball}; | ||
break; | ||
|
||
return intent; | ||
} | ||
case SHOOTING_START: { | ||
case SHOOTING_START: { // Positions the robot behind the ball at a certain angle so that it | ||
// has a straight shot towards the goal | ||
// SPDLOG_INFO("SHOOTING_START"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this log comment |
||
target_ = calculate_best_shot(); | ||
rj_geometry::Point ball_position = last_world_state_->ball.position; | ||
auto current_pos = last_world_state_->get_robot(true, robot_id_).pose.position(); | ||
|
@@ -77,7 +120,9 @@ std::optional<RobotIntent> PenaltyPlayer::state_to_task(RobotIntent intent) { | |
|
||
return intent; | ||
} | ||
case SHOOTING: { | ||
case SHOOTING: { // Kicks the ball with a now much higher speed (basically SMALL_KICK but | ||
// power set to 4) | ||
// SPDLOG_INFO("SHOOTING"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this log comment |
||
auto line_kick_cmd = | ||
planning::MotionCommand{"line_kick", planning::LinearMotionInstant{target_}}; | ||
|
||
|
@@ -87,7 +132,6 @@ std::optional<RobotIntent> PenaltyPlayer::state_to_task(RobotIntent intent) { | |
intent.kick_speed = 4.0; | ||
|
||
return intent; | ||
break; | ||
} | ||
} | ||
|
||
|
@@ -124,11 +168,16 @@ double PenaltyPlayer::distance_from_their_robots(rj_geometry::Point tail, | |
rj_geometry::Point PenaltyPlayer::calculate_best_shot() const { | ||
// Goal location | ||
rj_geometry::Point their_goal_pos = field_dimensions_.their_goal_loc(); | ||
double goal_width = field_dimensions_.goal_width(); // 1.0 meters | ||
double goal_width = | ||
field_dimensions_.goal_width(); // 1.0 meters // BALL SEEMS TO OCCASIONALLY MISS SHOT ON | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra double slash here. Let's change this comment to TODO format. |
||
// EDGE, CONSIDER CHANGING THIS? | ||
|
||
// Ball location | ||
rj_geometry::Point ball_position = this->last_world_state_->ball.position; | ||
|
||
// Iterates across 19 possible shot locations along the goal width in 0.05-meter increments. | ||
// For each location, it calculates the clearance distance from opponent robots and updates the | ||
// best shot position if a better (less obstructed) option is found. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think an extended description like this would be better as a docstring for the function |
||
rj_geometry::Point best_shot = their_goal_pos; | ||
double best_distance = -1.0; | ||
rj_geometry::Point increment(0.05, 0); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Combine this into one if statement