Skip to content

Commit

Permalink
Copter: lock home altitude to origin altitude if home was set on arming
Browse files Browse the repository at this point in the history
  • Loading branch information
jschall committed Feb 23, 2015
1 parent fd9538a commit f83c39a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
3 changes: 2 additions & 1 deletion ArduCopter/ArduCopter.pde
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@ static union {
uint8_t system_time_set : 1; // 20 // true if the system time has been set from the GPS
uint8_t gps_base_pos_set : 1; // 21 // true when the gps base position has been set (used for RTK gps only)
enum HomeState home_state : 2; // 22,23 - home status (unset, set, locked)
uint8_t in_ground_effect : 1; // 24
uint8_t home_set_by_ap : 1; // 24
uint8_t in_ground_effect : 1; // 25
};
uint32_t value;
} ap;
Expand Down
11 changes: 7 additions & 4 deletions ArduCopter/commands.pde
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static void update_home_from_GPS()
}

// move home to current gps location (this will set home_state to HOME_SET)
set_home(gps.location());
set_home_to_current_location();
}

// set_home_to_current_location - set home to current GPS location
Expand All @@ -44,7 +44,7 @@ static bool set_home_to_current_location() {
}

// set home to latest gps location
return set_home(gps.location());
return set_home(gps.location(), true);
}

// set_home_to_current_location_and_lock - set home to current location and lock so it cannot be moved
Expand All @@ -61,8 +61,9 @@ static bool set_home_to_current_location_and_lock()
// unless this function is called again
static bool set_home_and_lock(const Location& loc)
{
if (set_home(loc)) {
if (set_home(loc, false)) {
set_home_state(HOME_SET_AND_LOCKED);
ap.home_set_by_ap = false;
return true;
}
return false;
Expand All @@ -71,13 +72,15 @@ static bool set_home_and_lock(const Location& loc)
// set_home - sets ahrs home (used for RTL) to specified location
// initialises inertial nav and compass on first call
// returns true if home location set successfully
static bool set_home(const Location& loc)
static bool set_home(const Location& loc, bool set_by_ap)
{
// check location is valid
if (loc.lat == 0 && loc.lng == 0) {
return false;
}

ap.home_set_by_ap = set_by_ap;

// set ahrs home (used for RTL)
ahrs.set_home(loc);

Expand Down
2 changes: 1 addition & 1 deletion ArduCopter/commands_logic.pde
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ static void do_set_home(const AP_Mission::Mission_Command& cmd)
set_home_to_current_location();
} else {
if (!far_from_EKF_origin(cmd.content.location)) {
set_home(cmd.content.location);
set_home(cmd.content.location, false);
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion ArduCopter/position_vector.pde
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ float pv_alt_above_origin(float alt_above_home_cm)
float pv_alt_above_home(float alt_above_origin_cm)
{
const struct Location &origin = inertial_nav.get_origin();
return alt_above_origin_cm + (origin.alt - ahrs.get_home().alt);
struct Location home = ahrs.get_home();

if(ap.home_set_by_ap && origin.alt != home.alt) {
home.alt = origin.alt;
ahrs.set_home(home);
}

return alt_above_origin_cm + (origin.alt - home.alt);
}

// pv_get_bearing_cd - return bearing in centi-degrees between two positions
Expand Down

0 comments on commit f83c39a

Please sign in to comment.