Skip to content

Commit

Permalink
Copter: add SONAR_GAIN to tune reaction to sonar
Browse files Browse the repository at this point in the history
Some users report the response to sonar is too violent, this allows that
reaction to be reduced
  • Loading branch information
rmackay9 committed Apr 20, 2013
1 parent 50515e2 commit 745df9b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ArduCopter/Attitude.pde
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ get_throttle_surface_tracking(int16_t target_rate)
target_sonar_alt += target_rate * 0.02f;

distance_error = (target_sonar_alt-sonar_alt);
sonar_induced_slew_rate = constrain(fabsf(THR_SURFACE_TRACKING_P * distance_error),0,THR_SURFACE_TRACKING_VELZ_MAX);
sonar_induced_slew_rate = constrain(fabsf(g.sonar_gain * distance_error),0,THR_SURFACE_TRACKING_VELZ_MAX);

// do not let target altitude get too far from current altitude above ground
// Note: the 750cm limit is perhaps too wide but is consistent with the regular althold limits and helps ensure a smooth transition
Expand Down
4 changes: 3 additions & 1 deletion ArduCopter/Parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ class Parameters {
k_param_wp_yaw_behavior,
k_param_acro_trainer_enabled,
k_param_pilot_velocity_z_max,
k_param_circle_rate, // 29
k_param_circle_rate,
k_param_sonar_gain, // 30

// 65: AP_Limits Library
k_param_limits = 65,
Expand Down Expand Up @@ -262,6 +263,7 @@ class Parameters {
AP_Int8 sonar_type; // 0 = XL, 1 = LV,
// 2 = XLL (XL with 10m range)
// 3 = HRLV
AP_Float sonar_gain;
AP_Int8 battery_monitoring; // 0=disabled, 3=voltage only,
// 4=voltage and current
AP_Float volt_div_ratio;
Expand Down
8 changes: 8 additions & 0 deletions ArduCopter/Parameters.pde
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ const AP_Param::Info var_info[] PROGMEM = {
// @User: Standard
GSCALAR(sonar_type, "SONAR_TYPE", AP_RANGEFINDER_MAXSONARXL),

// @Param: SONAR_GAIN
// @DisplayName: Sonar gain
// @Description: Used to adjust the speed with which the target altitude is changed when objects are sensed below the copter
// @Range: 0.01 0.5
// @Increment: 0.01
// @User: Standard
GSCALAR(sonar_gain, "SONAR_GAIN", SONAR_GAIN_DEFAULT),

// @Param: BATT_MONITOR
// @DisplayName: Battery monitoring
// @Description: Controls enabling monitoring of the battery's voltage and current
Expand Down
6 changes: 3 additions & 3 deletions ArduCopter/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,12 @@
# define SONAR_ALT_HEALTH_MAX 3 // number of good reads that indicates a healthy sonar
#endif

#ifndef THR_SURFACE_TRACKING_P
# define THR_SURFACE_TRACKING_P 0.2 // gain for controlling how quickly sonar range adjusts target altitude (lower means slower reaction)
#ifndef SONAR_GAIN_DEFAULT
# define SONAR_GAIN_DEFAULT 0.2 // gain for controlling how quickly sonar range adjusts target altitude (lower means slower reaction)
#endif

#ifndef THR_SURFACE_TRACKING_VELZ_MAX
# define THR_SURFACE_TRACKING_VELZ_MAX 30 // max speed number of good reads that indicates a healthy sonar
# define THR_SURFACE_TRACKING_VELZ_MAX 30 // max vertical speed change while surface tracking with sonar
#endif

//////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 745df9b

Please sign in to comment.