Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions ArduSub/Sub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,18 +428,7 @@ float Sub::get_alt_rel() const

// get relative position
float posD;
if (ahrs.get_relative_position_D_origin_float(posD)) {
if (ahrs.home_is_set()) {
// adjust to the home position
auto home = ahrs.get_home();
posD -= static_cast<float>(home.alt) * 0.01f;
}
} else {
// fall back to the barometer reading
posD = -AP::baro().get_altitude();
}

// convert down to up
ahrs.get_relative_position_D_home(posD);
return -posD;
}

Expand Down
1 change: 0 additions & 1 deletion ArduSub/Sub.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,6 @@ class Sub : public AP_Vehicle {
void userhook_SlowLoop();
void userhook_SuperSlowLoop();
void update_home_from_EKF();
void set_home_to_current_location_inflight();
bool set_home_to_current_location(bool lock) override WARN_IF_UNUSED;
bool set_home(const Location& loc, bool lock) override WARN_IF_UNUSED;
float get_alt_rel() const WARN_IF_UNUSED;
Expand Down
25 changes: 2 additions & 23 deletions ArduSub/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,8 @@ void Sub::update_home_from_EKF()
if (ahrs.home_is_set()) {
return;
}

// special logic if home is set in-flight
if (motors.armed()) {
set_home_to_current_location_inflight();
} else {
// move home to current ekf location (this will set home_state to HOME_SET)
if (!set_home_to_current_location(false)) {
// ignore this failure
}
}
}

// set_home_to_current_location_inflight - set home to current GPS location (horizontally) and EKF origin vertically
void Sub::set_home_to_current_location_inflight()
{
// get current location from EKF
Location temp_loc;
Location ekf_origin;
if (ahrs.get_location(temp_loc) && ahrs.get_origin(ekf_origin)) {
temp_loc.copy_alt_from(ekf_origin);
if (!set_home(temp_loc, false)) {
// ignore this failure
}
if (!set_home_to_current_location(false)) {
// ignore this failure
}
}

Expand Down
Loading