Skip to content

Commit 65f807d

Browse files
committed
AP_Follow: change get_target_dist_and_vel_ned to avoid using location
1 parent b103569 commit 65f807d

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

libraries/AP_Follow/AP_Follow.cpp

+12-16
Original file line numberDiff line numberDiff line change
@@ -214,31 +214,27 @@ bool AP_Follow::get_target_position_and_velocity(Vector3p &pos_ned, Vector3f &ve
214214
}
215215

216216
// get distance vector to target (in meters) and target's velocity all in NED frame
217-
// FIXME: use the target_position_ned vector!
218217
bool AP_Follow::get_target_dist_and_vel_ned(Vector3f &dist_ned, Vector3f &dist_with_offs, Vector3f &vel_ned)
219218
{
220-
// get our location
221-
Location current_loc;
222-
if (!AP::ahrs().get_location(current_loc)) {
219+
Vector3f current_position_NED;
220+
if (!AP::ahrs().get_relative_position_NED_origin(current_position_NED)) {
223221
clear_dist_and_bearing_to_target();
224-
return false;
222+
return false;
225223
}
226-
227-
// get target location and velocity
228-
Location target_loc;
229-
Vector3f veh_vel;
230-
if (!get_target_location_and_velocity(target_loc, veh_vel)) {
224+
Vector3p target_position_NED;
225+
Vector3f veh_vel; // NED
226+
if (!get_target_position_and_velocity(target_position_NED, veh_vel)) {
231227
clear_dist_and_bearing_to_target();
232228
return false;
233229
}
234230

235-
// change to altitude above home
236-
if (target_loc.relative_alt == 1) {
237-
current_loc.change_alt_frame(Location::AltFrame::ABOVE_HOME);
238-
}
231+
// convert from Vector3p to Vector3f as they can't be subtracted:
232+
Vector3f target_position_NED_f;
233+
target_position_NED_f.x = target_position_NED.x;
234+
target_position_NED_f.y = target_position_NED.y;
235+
target_position_NED_f.z = target_position_NED.z;
239236

240-
// calculate difference
241-
const Vector3f dist_vec = current_loc.get_distance_NED(target_loc);
237+
const Vector3f dist_vec = target_position_NED_f - current_position_NED;
242238

243239
// fail if too far
244240
if (is_positive(_dist_max.get()) && (dist_vec.length() > _dist_max)) {

0 commit comments

Comments
 (0)