Skip to content

Commit

Permalink
AP_Common: make Location.cpp compile without AP::ahrs() available
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbarker committed Sep 27, 2023
1 parent bd16608 commit 5ef88a1
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions libraries/AP_Common/Location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Location::Location(int32_t latitude, int32_t longitude, int32_t alt_in_cm, AltFr
set_alt_cm(alt_in_cm, frame);
}

#if AP_AHRS_ENABLED
Location::Location(const Vector3f &ekf_offset_neu, AltFrame frame)
{
zero();
Expand All @@ -48,6 +49,7 @@ Location::Location(const Vector3f &ekf_offset_neu, AltFrame frame)
offset(ekf_offset_neu.x * 0.01, ekf_offset_neu.y * 0.01);
}
}
#endif

void Location::set_alt_cm(int32_t alt_cm, AltFrame frame)
{
Expand Down Expand Up @@ -141,12 +143,17 @@ bool Location::get_alt_cm(AltFrame desired_frame, int32_t &ret_alt_cm) const
alt_abs = alt;
break;
case AltFrame::ABOVE_HOME:
#if AP_AHRS_ENABLED
if (!AP::ahrs().home_is_set()) {
return false;
}
alt_abs = alt + AP::ahrs().get_home().alt;
#else
return false;
#endif
break;
case AltFrame::ABOVE_ORIGIN:
#if AP_AHRS_ENABLED
{
// fail if we cannot get ekf origin
Location ekf_origin;
Expand All @@ -156,6 +163,9 @@ bool Location::get_alt_cm(AltFrame desired_frame, int32_t &ret_alt_cm) const
alt_abs = alt + ekf_origin.alt;
}
break;
#else
return false;
#endif
case AltFrame::ABOVE_TERRAIN:
alt_abs = alt + alt_terr_cm;
break;
Expand All @@ -167,12 +177,17 @@ bool Location::get_alt_cm(AltFrame desired_frame, int32_t &ret_alt_cm) const
ret_alt_cm = alt_abs;
return true;
case AltFrame::ABOVE_HOME:
#if AP_AHRS_ENABLED
if (!AP::ahrs().home_is_set()) {
return false;
}
ret_alt_cm = alt_abs - AP::ahrs().get_home().alt;
#else
return false;
#endif
return true;
case AltFrame::ABOVE_ORIGIN:
#if AP_AHRS_ENABLED
{
// fail if we cannot get ekf origin
Location ekf_origin;
Expand All @@ -182,13 +197,17 @@ bool Location::get_alt_cm(AltFrame desired_frame, int32_t &ret_alt_cm) const
ret_alt_cm = alt_abs - ekf_origin.alt;
return true;
}
#else
return false;
#endif
case AltFrame::ABOVE_TERRAIN:
ret_alt_cm = alt_abs - alt_terr_cm;
return true;
}
return false; // LCOV_EXCL_LINE - not reachable
}

#if AP_AHRS_ENABLED
bool Location::get_vector_xy_from_origin_NE(Vector2f &vec_ne) const
{
Location ekf_origin;
Expand Down Expand Up @@ -216,6 +235,7 @@ bool Location::get_vector_from_origin_NEU(Vector3f &vec_neu) const

return true;
}
#endif

// return horizontal distance in meters between two locations
ftype Location::get_distance(const Location &loc2) const
Expand Down

0 comments on commit 5ef88a1

Please sign in to comment.