-
Notifications
You must be signed in to change notification settings - Fork 190
Improved free kick routine #2450
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
base: ros2
Are you sure you want to change the base?
Changes from 7 commits
8e19b8c
e2db7ca
b284f1a
460a588
5b72143
4b59f16
c23d979
478b1e8
b519e76
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 |
|---|---|---|
|
|
@@ -11,11 +11,51 @@ std::optional<RobotIntent> FreeKicker::derived_get_task(RobotIntent intent) { | |
|
|
||
| // SPDLOG_INFO("Free Kicker {} is running", this->robot_id_); | ||
|
|
||
| rj_geometry::Point goal_corner{ | ||
| this->field_dimensions_.their_goal_loc().x() + 0.5 * this->field_dimensions_.goal_width(), | ||
| this->field_dimensions_.their_goal_loc().y()}; | ||
| // Read positions of their team | ||
| std::vector<RobotState> const their_robots = this->last_world_state_->their_robots; | ||
| rj_geometry::Point enemy_goalie_location = this->field_dimensions_.their_goal_loc(); | ||
|
|
||
| planning::LinearMotionInstant target{goal_corner}; | ||
| for (const RobotState& enemy : their_robots) { | ||
| // Get position of their goalie | ||
| if (this->field_dimensions_.their_defense_area().hit(enemy.pose.position())) { | ||
| enemy_goalie_location = enemy.pose.position(); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| constexpr double BALL_WIDTH = 0.025; | ||
|
||
| constexpr double BALL_WIDTH_OFFSET = BALL_WIDTH * 3; | ||
|
||
| rj_geometry::Point const right_goal_post = | ||
| this->field_dimensions_.their_goal_loc() + | ||
| rj_geometry::Point((this->field_dimensions_.goal_width() / 2.0) - BALL_WIDTH_OFFSET, 0.0); | ||
|
|
||
| rj_geometry::Point const left_goal_post = | ||
| this->field_dimensions_.their_goal_loc() - | ||
| rj_geometry::Point((this->field_dimensions_.goal_width() / 2.0) - BALL_WIDTH_OFFSET, 0.0); | ||
| rj_geometry::Point best_shot = right_goal_post; | ||
| double best_distance = -1.0; | ||
| rj_geometry::Point ball_position = this->last_world_state_->ball.position; | ||
|
|
||
| int num_samples = 20; | ||
|
||
|
|
||
| for (int i = 0; i < num_samples; ++i) { | ||
| double t = i / static_cast<double>(num_samples - 1); | ||
| rj_geometry::Point shot_target = left_goal_post + (right_goal_post - left_goal_post) * t; | ||
|
|
||
| double distance = | ||
| std::abs((enemy_goalie_location - ball_position).cross(shot_target - ball_position)) / | ||
| (shot_target - ball_position).mag(); | ||
|
|
||
| if (distance > best_distance) { | ||
| best_distance = distance; | ||
| best_shot = shot_target; | ||
| } | ||
| } | ||
|
|
||
| SPDLOG_INFO("Free Kicker {} shooting at point {}, {}", this->robot_id_, best_shot.x(), | ||
| best_shot.y()); | ||
|
|
||
| planning::LinearMotionInstant target{best_shot}; | ||
| auto line_kick_cmd = planning::MotionCommand{"line_kick", target}; | ||
| intent.motion_command = line_kick_cmd; | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.