@@ -214,31 +214,27 @@ bool AP_Follow::get_target_position_and_velocity(Vector3p &pos_ned, Vector3f &ve
214
214
}
215
215
216
216
// get distance vector to target (in meters) and target's velocity all in NED frame
217
- // FIXME: use the target_position_ned vector!
218
217
bool AP_Follow::get_target_dist_and_vel_ned (Vector3f &dist_ned, Vector3f &dist_with_offs, Vector3f &vel_ned)
219
218
{
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)) {
223
221
clear_dist_and_bearing_to_target ();
224
- return false ;
222
+ return false ;
225
223
}
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)) {
231
227
clear_dist_and_bearing_to_target ();
232
228
return false ;
233
229
}
234
230
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 ;
239
236
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;
242
238
243
239
// fail if too far
244
240
if (is_positive (_dist_max.get ()) && (dist_vec.length () > _dist_max)) {
0 commit comments