ArduCopter: added BATT_VOLT_PIN and BATT_CURR_PIN parameters to allow support for new 3DR IV battery voltage and current monitor

This commit is contained in:
rmackay9 2012-10-13 18:40:46 +09:00
parent 8e19e7d0b2
commit 71c773801a
4 changed files with 31 additions and 22 deletions

View File

@ -114,9 +114,8 @@ public:
k_param_ch7_option,
k_param_auto_slew_rate,
k_param_sonar_type,
k_param_super_simple,
k_param_battery_pin,
k_param_axis_enabled,
k_param_super_simple = 155,
k_param_axis_enabled = 157,
k_param_copter_leds_mode,
k_param_ahrs, // AHRS group
@ -137,6 +136,12 @@ public:
k_param_camera_mount,
k_param_camera_mount2,
//
// Batery monitoring parameters
//
k_param_battery_volt_pin = 168,
k_param_battery_curr_pin, // 169
//
// 170: Radio settings
//
@ -237,14 +242,14 @@ public:
AP_Int8 optflow_enabled;
AP_Float low_voltage;
AP_Int8 super_simple;
AP_Int8 battery_pin;
AP_Int16 rtl_approach_alt;
AP_Int8 tilt_comp;
AP_Int8 axis_enabled;
AP_Int8 copter_leds_mode; // Operating mode of LED
// lighting system
AP_Int8 battery_volt_pin;
AP_Int8 battery_curr_pin;
// Waypoints
//

View File

@ -98,13 +98,6 @@ const AP_Param::Info var_info[] PROGMEM = {
// @User: Standard
GSCALAR(super_simple, "SUPER_SIMPLE", SUPER_SIMPLE),
// @Param: BATT_PIN
// @DisplayName: Battery Voltage sending pin
// @Description: Setting this to 0 ~ 11 will enable battery voltage sending on pins A0 ~ A11. Current will be measured on this pin + 1
// @Values: 99:Disabled, 0:A0, 1:A1, 10:A10
// @User: Standard
GSCALAR(battery_pin, "BATT_PIN", BATTERY_PIN_1),
// @Param: APPROACH_ALT
// @DisplayName: RTL Approach Altitude
// @Description: This is the altitude the vehicle will move to as the final stage of Returning to Launch. Set to zero to land.
@ -122,10 +115,19 @@ const AP_Param::Info var_info[] PROGMEM = {
// @User: Advanced
GSCALAR(tilt_comp, "TILT", TILT_COMPENSATION),
// @Param: BATT_VOLT_PIN
// @DisplayName: Battery Voltage sending pin
// @Description: Setting this to 0 ~ 11 will enable battery voltage sending on pins A0 ~ A11. Current will be measured on this pin + 1
// @Values: 99:Disabled, 0:A0, 1:A1, 10:A13
// @User: Standard
GSCALAR(battery_volt_pin, "BATT_VOLT_PIN", BATTERY_VOLT_PIN),
// @Param: BATT_CURR_PIN
// @DisplayName: Battery Voltage sending pin
// @Description: Setting this to 0 ~ 11 will enable battery voltage sending on pins A0 ~ A11. Current will be measured on this pin + 1
// @Values: 99:Disabled, 0:A0, 1:A1, 10:A12
// @User: Standard
GSCALAR(battery_curr_pin, "BATT_CURR_PIN", BATTERY_CURR_PIN),
GSCALAR(waypoint_mode, "WP_MODE", 0),
GSCALAR(command_total, "WP_TOTAL", 0),

View File

@ -140,7 +140,8 @@
# define USB_MUX_PIN -1
# define CLI_SLIDER_ENABLED DISABLED
# define OPTFLOW_CS_PIN 34
# define BATTERY_PIN_1 0 // Battery voltage on A0, Current on A1
# define BATTERY_VOLT_PIN 0 // Battery voltage on A0
# define BATTERY_CURR_PIN 1 // Battery current on A1
#elif CONFIG_APM_HARDWARE == APM_HARDWARE_APM2
# define A_LED_PIN 27
# define B_LED_PIN 26
@ -152,7 +153,8 @@
# define CLI_SLIDER_ENABLED DISABLED
# define USB_MUX_PIN 23
# define OPTFLOW_CS_PIN A3
# define BATTERY_PIN_1 1 // Battery voltage on A1, Current on A2
# define BATTERY_VOLT_PIN 1 // Battery voltage on A1
# define BATTERY_CURR_PIN 2 // Battery current on A2
#endif
////////////////////////////////////////////////////////////////////////////////

View File

@ -77,12 +77,12 @@ static void read_battery(void)
}
if(g.battery_monitoring == 3 || g.battery_monitoring == 4) {
static AP_AnalogSource_Arduino bat_pin(g.battery_pin);
battery_voltage1 = BATTERY_VOLTAGE(bat_pin.read_average());
static AP_AnalogSource_Arduino batt_volt_pin(g.battery_volt_pin);
battery_voltage1 = BATTERY_VOLTAGE(batt_volt_pin.read_average());
}
if(g.battery_monitoring == 4) {
static AP_AnalogSource_Arduino current_pin(g.battery_pin+1); // current is always read from one pin higher than battery voltage
current_amps1 = CURRENT_AMPS(current_pin.read_average());
static AP_AnalogSource_Arduino batt_curr_pin(g.battery_curr_pin); // current is always read from one pin higher than battery voltage
current_amps1 = CURRENT_AMPS(batt_curr_pin.read_average());
current_total1 += current_amps1 * 0.02778; // called at 100ms on average, .0002778 is 1/3600 (conversion to hours)
}