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
Copter: improved follow at close distances #26138
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,18 +68,7 @@ void ModeFollow::run() | |
|
||
// calculate desired velocity vector in cm/s in NEU | ||
const float kp = g2.follow.get_pos_p().kP(); | ||
desired_velocity_neu_cms.x = (vel_of_target.x * 100.0f) + (dist_vec_offs_neu.x * kp); | ||
desired_velocity_neu_cms.y = (vel_of_target.y * 100.0f) + (dist_vec_offs_neu.y * kp); | ||
desired_velocity_neu_cms.z = (-vel_of_target.z * 100.0f) + (dist_vec_offs_neu.z * kp); | ||
|
||
// scale desired velocity to stay within horizontal speed limit | ||
float desired_speed_xy = safe_sqrt(sq(desired_velocity_neu_cms.x) + sq(desired_velocity_neu_cms.y)); | ||
if (!is_zero(desired_speed_xy) && (desired_speed_xy > pos_control->get_max_speed_xy_cms())) { | ||
const float scalar_xy = pos_control->get_max_speed_xy_cms() / desired_speed_xy; | ||
desired_velocity_neu_cms.x *= scalar_xy; | ||
desired_velocity_neu_cms.y *= scalar_xy; | ||
desired_speed_xy = pos_control->get_max_speed_xy_cms(); | ||
} | ||
desired_velocity_neu_cms = dist_vec_offs_neu * kp; | ||
|
||
// limit desired velocity to be between maximum climb and descent rates | ||
desired_velocity_neu_cms.z = constrain_float(desired_velocity_neu_cms.z, -fabsf(pos_control->get_max_speed_down_cms()), pos_control->get_max_speed_up_cms()); | ||
|
@@ -104,13 +93,24 @@ void ModeFollow::run() | |
const float dist_to_target_xy = Vector2f(dist_vec_offs_neu.x, dist_vec_offs_neu.y).length(); | ||
copter.avoid.limit_velocity_2D(pos_control->get_pos_xy_p().kP().get(), pos_control->get_max_accel_xy_cmss() * 0.5f, desired_velocity_xy_cms, dir_to_target_xy, dist_to_target_xy, copter.G_Dt); | ||
// copy horizontal velocity limits back to 3d vector | ||
desired_velocity_neu_cms.x = desired_velocity_xy_cms.x; | ||
desired_velocity_neu_cms.y = desired_velocity_xy_cms.y; | ||
desired_velocity_neu_cms.xy() = desired_velocity_xy_cms; | ||
|
||
// limit vertical desired_velocity_neu_cms to slow as we approach target (we use 1/2 of maximum deceleration for gentle slow down) | ||
const float des_vel_z_max = copter.avoid.get_max_speed(pos_control->get_pos_z_p().kP().get(), pos_control->get_max_accel_z_cmss() * 0.5f, fabsf(dist_vec_offs_neu.z), copter.G_Dt); | ||
desired_velocity_neu_cms.z = constrain_float(desired_velocity_neu_cms.z, -des_vel_z_max, des_vel_z_max); | ||
|
||
/* | ||
add velocity of the target. We add this at the end as we do | ||
not want to scale it when we get close to the target | ||
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'd say "We add this at the end as we don't want to apply the slowdown calculations to the baseline target velocity too" is a more accurate reasoning. How close we are to the target doesn't play a role in the slowdown calculations. |
||
*/ | ||
desired_velocity_neu_cms.xy() += vel_of_target.xy() * 100; | ||
desired_velocity_neu_cms.z -= vel_of_target.z * 100; | ||
|
||
/* | ||
limit to configured max speed | ||
*/ | ||
desired_velocity_neu_cms.xy().limit_length(pos_control->get_max_speed_xy_cms()); | ||
|
||
// limit the velocity for obstacle/fence avoidance | ||
copter.avoid.adjust_velocity(desired_velocity_neu_cms, pos_control->get_pos_xy_p().kP().get(), pos_control->get_max_accel_xy_cmss(), pos_control->get_pos_z_p().kP().get(), pos_control->get_max_accel_z_cmss(), G_Dt); | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This vertical velocity limitation shouldn't be here, before the slowdown calculations, but after ~L112, like the XY limitations.