Skip to content

Commit

Permalink
Sub: move home state into AP_AHRS
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Barker authored and rmackay9 committed Mar 19, 2018
1 parent 7fd859d commit 3af4806
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 41 deletions.
5 changes: 0 additions & 5 deletions ArduSub/AP_Arming_Sub.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
#include "AP_Arming_Sub.h"
#include "Sub.h"

enum HomeState AP_Arming_Sub::home_status() const
{
return sub.ap.home_state;
}

bool AP_Arming_Sub::rc_calibration_checks(bool display_failure)
{
const RC_Channel *channels[] = {
Expand Down
1 change: 0 additions & 1 deletion ArduSub/AP_Arming_Sub.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ class AP_Arming_Sub : public AP_Arming {

protected:
bool ins_checks(bool report) override;
enum HomeState home_status() const override;
};
23 changes: 0 additions & 23 deletions ArduSub/AP_State.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1 @@
#include "Sub.h"

// set_home_state - update home state
void Sub::set_home_state(enum HomeState new_home_state)
{
// if no change, exit immediately
if (ap.home_state == new_home_state) {
return;
}

// update state
ap.home_state = new_home_state;

// log if home has been set
if (new_home_state == HOME_SET_NOT_LOCKED || new_home_state == HOME_SET_AND_LOCKED) {
Log_Write_Event(DATA_SET_HOME);
}
}

// home_is_set - returns true if home positions has been set (to GPS location, armed location or EKF origin)
bool Sub::home_is_set()
{
return (ap.home_state == HOME_SET_NOT_LOCKED || ap.home_state == HOME_SET_AND_LOCKED);
}
4 changes: 2 additions & 2 deletions ArduSub/GCS_Mavlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ void GCS_MAVLINK_Sub::handleMessage(mavlink_message_t* msg)
new_home_loc.alt = packet.z * 100;
// handle relative altitude
if (packet.frame == MAV_FRAME_GLOBAL_RELATIVE_ALT || packet.frame == MAV_FRAME_GLOBAL_RELATIVE_ALT_INT) {
if (sub.ap.home_state == HOME_UNSET) {
if (!AP::ahrs().home_is_set()) {
// cannot use relative altitude if home is not set
break;
}
Expand Down Expand Up @@ -1194,7 +1194,7 @@ void GCS_MAVLINK_Sub::handleMessage(mavlink_message_t* msg)
break;

case MAV_CMD_GET_HOME_POSITION:
if (sub.ap.home_state != HOME_UNSET) {
if (AP::ahrs().home_is_set()) {
send_home(sub.ahrs.get_home());
Location ekf_origin;
if (sub.ahrs.get_origin(ekf_origin)) {
Expand Down
2 changes: 1 addition & 1 deletion ArduSub/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ void Sub::Log_Write_Home_And_Origin()
}

// log ahrs home if set
if (ap.home_state != HOME_UNSET) {
if (ahrs.home_is_set()) {
DataFlash.Log_Write_Origin(LogOriginType::ahrs_home, ahrs.get_home());
}
}
Expand Down
3 changes: 0 additions & 3 deletions ArduSub/Sub.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ class Sub : public AP_HAL::HAL::Callbacks {
uint8_t initialised : 1; // true once the init_ardupilot function has completed. Extended status to GCS is not sent until this completes
uint8_t system_time_set : 1; // true if the system time has been set from the GPS
uint8_t gps_base_pos_set : 1; // true when the gps base position has been set (used for RTK gps only)
enum HomeState home_state : 2; // home status (unset, set, locked)
uint8_t at_bottom : 1; // true if we are at the bottom
uint8_t at_surface : 1; // true if we are at the surface
uint8_t depth_sensor_present: 1; // true if there is a depth sensor detected at boot
Expand Down Expand Up @@ -459,8 +458,6 @@ class Sub : public AP_HAL::HAL::Callbacks {
void update_turn_counter();
void read_AHRS(void);
void update_altitude();
void set_home_state(enum HomeState new_home_state);
bool home_is_set();
float get_smoothing_gain();
void get_pilot_desired_lean_angles(float roll_in, float pitch_in, float &roll_out, float &pitch_out, float angle_max);
float get_pilot_desired_yaw_rate(int16_t stick_angle);
Expand Down
9 changes: 5 additions & 4 deletions ArduSub/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
void Sub::update_home_from_EKF()
{
// exit immediately if home already set
if (ap.home_state != HOME_UNSET) {
if (ahrs.home_is_set()) {
return;
}

Expand Down Expand Up @@ -73,11 +73,12 @@ bool Sub::set_home(const Location& loc, bool lock)
ahrs.set_home(loc);

// init inav and compass declination
if (ap.home_state == HOME_UNSET) {
if (!ahrs.home_is_set()) {
// update navigation scalers. used to offset the shrinking longitude as we go towards the poles
scaleLongDown = longitude_scale(loc);
// record home is set
set_home_state(HOME_SET_NOT_LOCKED);
ahrs.set_home_status(HOME_SET_NOT_LOCKED);
Log_Write_Event(DATA_SET_HOME);

// log new home position which mission library will pull from ahrs
if (should_log(MASK_LOG_CMD)) {
Expand All @@ -90,7 +91,7 @@ bool Sub::set_home(const Location& loc, bool lock)

// lock home position
if (lock) {
set_home_state(HOME_SET_AND_LOCKED);
ahrs.set_home_status(HOME_SET_AND_LOCKED);
}

// log ahrs home and ekf origin dataflash
Expand Down
4 changes: 2 additions & 2 deletions ArduSub/motors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ bool Sub::init_arm_motors(bool arming_from_gcs)

initial_armed_bearing = ahrs.yaw_sensor;

if (ap.home_state == HOME_UNSET) {
if (!ahrs.home_is_set()) {
// Reset EKF altitude if home hasn't been set yet (we use EKF altitude as substitute for alt above home)

// Always use absolute altitude for ROV
// ahrs.resetHeightDatum();
// Log_Write_Event(DATA_EKF_ALT_RESET);
} else if (ap.home_state == HOME_SET_NOT_LOCKED) {
} else if (ahrs.home_status() == HOME_SET_NOT_LOCKED) {
// Reset home position if it has already been set before (but not locked)
set_home_to_current_location(false);
}
Expand Down

0 comments on commit 3af4806

Please sign in to comment.