mirror of https://github.com/ArduPilot/ardupilot
ArduSub: make AP_RANGEFINDER_ENABLED remove more code
This commit is contained in:
parent
c14c2d67d4
commit
a5d7000ffd
|
@ -73,7 +73,7 @@ void GCS_Sub::update_vehicle_sensor_status_flags()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if RANGEFINDER_ENABLED == ENABLED
|
#if AP_RANGEFINDER_ENABLED
|
||||||
const RangeFinder *rangefinder = RangeFinder::get_singleton();
|
const RangeFinder *rangefinder = RangeFinder::get_singleton();
|
||||||
if (sub.rangefinder_state.enabled) {
|
if (sub.rangefinder_state.enabled) {
|
||||||
control_sensors_present |= MAV_SYS_STATUS_SENSOR_LASER_POSITION;
|
control_sensors_present |= MAV_SYS_STATUS_SENSOR_LASER_POSITION;
|
||||||
|
|
|
@ -628,7 +628,7 @@ const AP_Param::Info Sub::var_info[] = {
|
||||||
// @Path: ../libraries/AP_Mission/AP_Mission.cpp
|
// @Path: ../libraries/AP_Mission/AP_Mission.cpp
|
||||||
GOBJECT(mission, "MIS_", AP_Mission),
|
GOBJECT(mission, "MIS_", AP_Mission),
|
||||||
|
|
||||||
#if RANGEFINDER_ENABLED == ENABLED
|
#if AP_RANGEFINDER_ENABLED
|
||||||
// @Group: RNGFND
|
// @Group: RNGFND
|
||||||
// @Path: ../libraries/AP_RangeFinder/AP_RangeFinder.cpp
|
// @Path: ../libraries/AP_RangeFinder/AP_RangeFinder.cpp
|
||||||
GOBJECT(rangefinder, "RNGFND", RangeFinder),
|
GOBJECT(rangefinder, "RNGFND", RangeFinder),
|
||||||
|
|
|
@ -243,7 +243,7 @@ public:
|
||||||
|
|
||||||
AP_Float throttle_filt;
|
AP_Float throttle_filt;
|
||||||
|
|
||||||
#if RANGEFINDER_ENABLED == ENABLED
|
#if AP_RANGEFINDER_ENABLED
|
||||||
AP_Int8 rangefinder_signal_min; // minimum signal quality for good rangefinder readings
|
AP_Int8 rangefinder_signal_min; // minimum signal quality for good rangefinder readings
|
||||||
AP_Float surftrak_depth; // surftrak will try to keep sub below this depth
|
AP_Float surftrak_depth; // surftrak will try to keep sub below this depth
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -625,10 +625,10 @@ public:
|
||||||
// For Lua scripting, so index is 1..4, not 0..3
|
// For Lua scripting, so index is 1..4, not 0..3
|
||||||
uint8_t get_and_clear_button_count(uint8_t index);
|
uint8_t get_and_clear_button_count(uint8_t index);
|
||||||
|
|
||||||
#if RANGEFINDER_ENABLED == ENABLED
|
#if AP_RANGEFINDER_ENABLED
|
||||||
float get_rangefinder_target_cm() const WARN_IF_UNUSED { return mode_surftrak.get_rangefinder_target_cm(); }
|
float get_rangefinder_target_cm() const WARN_IF_UNUSED { return mode_surftrak.get_rangefinder_target_cm(); }
|
||||||
bool set_rangefinder_target_cm(float new_target_cm) { return mode_surftrak.set_rangefinder_target_cm(new_target_cm); }
|
bool set_rangefinder_target_cm(float new_target_cm) { return mode_surftrak.set_rangefinder_target_cm(new_target_cm); }
|
||||||
#endif // RANGEFINDER_ENABLED
|
#endif // AP_RANGEFINDER_ENABLED
|
||||||
#endif // AP_SCRIPTING_ENABLED
|
#endif // AP_SCRIPTING_ENABLED
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -46,10 +46,6 @@
|
||||||
// Rangefinder
|
// Rangefinder
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef RANGEFINDER_ENABLED
|
|
||||||
# define RANGEFINDER_ENABLED ENABLED
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef RANGEFINDER_HEALTH_MAX
|
#ifndef RANGEFINDER_HEALTH_MAX
|
||||||
# define RANGEFINDER_HEALTH_MAX 3 // number of good reads that indicates a healthy rangefinder
|
# define RANGEFINDER_HEALTH_MAX 3 // number of good reads that indicates a healthy rangefinder
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -190,7 +190,7 @@ void Sub::handle_jsbutton_press(uint8_t _button, bool shift, bool held)
|
||||||
case JSButton::button_function_t::k_mode_poshold:
|
case JSButton::button_function_t::k_mode_poshold:
|
||||||
set_mode(Mode::Number::POSHOLD, ModeReason::RC_COMMAND);
|
set_mode(Mode::Number::POSHOLD, ModeReason::RC_COMMAND);
|
||||||
break;
|
break;
|
||||||
#if RANGEFINDER_ENABLED == ENABLED
|
#if AP_RANGEFINDER_ENABLED
|
||||||
case JSButton::button_function_t::k_mode_surftrak:
|
case JSButton::button_function_t::k_mode_surftrak:
|
||||||
set_mode(Mode::Number::SURFTRAK, ModeReason::RC_COMMAND);
|
set_mode(Mode::Number::SURFTRAK, ModeReason::RC_COMMAND);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -426,6 +426,7 @@ void ModeAuto::set_auto_yaw_roi(const Location &roi_location)
|
||||||
// Return true if it is possible to recover from a rangefinder failure
|
// Return true if it is possible to recover from a rangefinder failure
|
||||||
bool ModeAuto::auto_terrain_recover_start()
|
bool ModeAuto::auto_terrain_recover_start()
|
||||||
{
|
{
|
||||||
|
#if AP_RANGEFINDER_ENABLED
|
||||||
// Check rangefinder status to see if recovery is possible
|
// Check rangefinder status to see if recovery is possible
|
||||||
switch (sub.rangefinder.status_orient(ROTATION_PITCH_270)) {
|
switch (sub.rangefinder.status_orient(ROTATION_PITCH_270)) {
|
||||||
|
|
||||||
|
@ -462,6 +463,9 @@ bool ModeAuto::auto_terrain_recover_start()
|
||||||
|
|
||||||
gcs().send_text(MAV_SEVERITY_WARNING, "Attempting auto failsafe recovery");
|
gcs().send_text(MAV_SEVERITY_WARNING, "Attempting auto failsafe recovery");
|
||||||
return true;
|
return true;
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt recovery from terrain failsafe
|
// Attempt recovery from terrain failsafe
|
||||||
|
@ -470,7 +474,6 @@ bool ModeAuto::auto_terrain_recover_start()
|
||||||
void ModeAuto::auto_terrain_recover_run()
|
void ModeAuto::auto_terrain_recover_run()
|
||||||
{
|
{
|
||||||
float target_climb_rate = 0;
|
float target_climb_rate = 0;
|
||||||
static uint32_t rangefinder_recovery_ms = 0;
|
|
||||||
|
|
||||||
// if not armed set throttle to zero and exit immediately
|
// if not armed set throttle to zero and exit immediately
|
||||||
if (!motors.armed()) {
|
if (!motors.armed()) {
|
||||||
|
@ -483,6 +486,8 @@ void ModeAuto::auto_terrain_recover_run()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if AP_RANGEFINDER_ENABLED
|
||||||
|
static uint32_t rangefinder_recovery_ms = 0;
|
||||||
switch (sub.rangefinder.status_orient(ROTATION_PITCH_270)) {
|
switch (sub.rangefinder.status_orient(ROTATION_PITCH_270)) {
|
||||||
|
|
||||||
case RangeFinder::Status::OutOfRangeLow:
|
case RangeFinder::Status::OutOfRangeLow:
|
||||||
|
@ -529,6 +534,10 @@ void ModeAuto::auto_terrain_recover_run()
|
||||||
rangefinder_recovery_ms = 0;
|
rangefinder_recovery_ms = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
gcs().send_text(MAV_SEVERITY_CRITICAL, "Terrain failsafe recovery failure: No Rangefinder!");
|
||||||
|
sub.failsafe_terrain_act();
|
||||||
|
#endif
|
||||||
|
|
||||||
// exit on failure (timeout)
|
// exit on failure (timeout)
|
||||||
if (AP_HAL::millis() > sub.fs_terrain_recover_start_ms + FS_TERRAIN_RECOVER_TIMEOUT_MS) {
|
if (AP_HAL::millis() > sub.fs_terrain_recover_start_ms + FS_TERRAIN_RECOVER_TIMEOUT_MS) {
|
||||||
|
|
|
@ -39,8 +39,10 @@ bool ModeSurftrak::init(bool ignore_checks)
|
||||||
|
|
||||||
if (!sub.rangefinder_alt_ok()) {
|
if (!sub.rangefinder_alt_ok()) {
|
||||||
sub.gcs().send_text(MAV_SEVERITY_INFO, "waiting for a rangefinder reading");
|
sub.gcs().send_text(MAV_SEVERITY_INFO, "waiting for a rangefinder reading");
|
||||||
|
#if AP_RANGEFINDER_ENABLED
|
||||||
} else if (sub.inertial_nav.get_position_z_up_cm() >= sub.g.surftrak_depth) {
|
} else if (sub.inertial_nav.get_position_z_up_cm() >= sub.g.surftrak_depth) {
|
||||||
sub.gcs().send_text(MAV_SEVERITY_WARNING, "descend below %f meters to hold range", sub.g.surftrak_depth * 0.01f);
|
sub.gcs().send_text(MAV_SEVERITY_WARNING, "descend below %f meters to hold range", sub.g.surftrak_depth * 0.01f);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -60,6 +62,7 @@ bool ModeSurftrak::set_rangefinder_target_cm(float target_cm)
|
||||||
{
|
{
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
|
||||||
|
#if AP_RANGEFINDER_ENABLED
|
||||||
if (sub.control_mode != Number::SURFTRAK) {
|
if (sub.control_mode != Number::SURFTRAK) {
|
||||||
sub.gcs().send_text(MAV_SEVERITY_WARNING, "wrong mode, rangefinder target not set");
|
sub.gcs().send_text(MAV_SEVERITY_WARNING, "wrong mode, rangefinder target not set");
|
||||||
} else if (sub.inertial_nav.get_position_z_up_cm() >= sub.g.surftrak_depth) {
|
} else if (sub.inertial_nav.get_position_z_up_cm() >= sub.g.surftrak_depth) {
|
||||||
|
@ -84,6 +87,7 @@ bool ModeSurftrak::set_rangefinder_target_cm(float target_cm)
|
||||||
} else {
|
} else {
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
@ -141,6 +145,7 @@ void ModeSurftrak::control_range() {
|
||||||
*/
|
*/
|
||||||
void ModeSurftrak::update_surface_offset()
|
void ModeSurftrak::update_surface_offset()
|
||||||
{
|
{
|
||||||
|
#if AP_RANGEFINDER_ENABLED
|
||||||
if (sub.rangefinder_alt_ok()) {
|
if (sub.rangefinder_alt_ok()) {
|
||||||
// Get the latest terrain offset
|
// Get the latest terrain offset
|
||||||
float rangefinder_terrain_offset_cm = sub.rangefinder_state.rangefinder_terrain_offset_cm;
|
float rangefinder_terrain_offset_cm = sub.rangefinder_state.rangefinder_terrain_offset_cm;
|
||||||
|
@ -162,4 +167,5 @@ void ModeSurftrak::update_surface_offset()
|
||||||
sub.pos_control.set_pos_offset_target_z_cm(rangefinder_terrain_offset_cm);
|
sub.pos_control.set_pos_offset_target_z_cm(rangefinder_terrain_offset_cm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif // AP_RANGEFINDER_ENABLED
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ void Sub::read_barometer()
|
||||||
|
|
||||||
void Sub::init_rangefinder()
|
void Sub::init_rangefinder()
|
||||||
{
|
{
|
||||||
#if RANGEFINDER_ENABLED == ENABLED
|
#if AP_RANGEFINDER_ENABLED
|
||||||
rangefinder.set_log_rfnd_bit(MASK_LOG_CTUN);
|
rangefinder.set_log_rfnd_bit(MASK_LOG_CTUN);
|
||||||
rangefinder.init(ROTATION_PITCH_270);
|
rangefinder.init(ROTATION_PITCH_270);
|
||||||
rangefinder_state.alt_cm_filt.set_cutoff_frequency(RANGEFINDER_WPNAV_FILT_HZ);
|
rangefinder_state.alt_cm_filt.set_cutoff_frequency(RANGEFINDER_WPNAV_FILT_HZ);
|
||||||
|
@ -28,7 +28,7 @@ void Sub::init_rangefinder()
|
||||||
// return rangefinder altitude in centimeters
|
// return rangefinder altitude in centimeters
|
||||||
void Sub::read_rangefinder()
|
void Sub::read_rangefinder()
|
||||||
{
|
{
|
||||||
#if RANGEFINDER_ENABLED == ENABLED
|
#if AP_RANGEFINDER_ENABLED
|
||||||
rangefinder.update();
|
rangefinder.update();
|
||||||
|
|
||||||
// signal quality ranges from 0 (worst) to 100 (perfect), -1 means n/a
|
// signal quality ranges from 0 (worst) to 100 (perfect), -1 means n/a
|
||||||
|
|
|
@ -129,7 +129,7 @@ void Sub::init_ardupilot()
|
||||||
last_pilot_heading = ahrs.yaw_sensor;
|
last_pilot_heading = ahrs.yaw_sensor;
|
||||||
|
|
||||||
// initialise rangefinder
|
// initialise rangefinder
|
||||||
#if RANGEFINDER_ENABLED == ENABLED
|
#if AP_RANGEFINDER_ENABLED
|
||||||
init_rangefinder();
|
init_rangefinder();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ void Sub::terrain_update()
|
||||||
|
|
||||||
// tell the rangefinder our height, so it can go into power saving
|
// tell the rangefinder our height, so it can go into power saving
|
||||||
// mode if available
|
// mode if available
|
||||||
#if RANGEFINDER_ENABLED == ENABLED
|
#if AP_RANGEFINDER_ENABLED
|
||||||
float height;
|
float height;
|
||||||
if (terrain.height_above_terrain(height, true)) {
|
if (terrain.height_above_terrain(height, true)) {
|
||||||
rangefinder.set_estimated_terrain_height(height);
|
rangefinder.set_estimated_terrain_height(height);
|
||||||
|
|
Loading…
Reference in New Issue