ArduCopter: BATT_PIN parameter added to allow you to select which pin is used for voltage and current measurements

To save a parameter, the current sensor pin is assumed to always be 1 higher than the voltage pin.
This commit is contained in:
rmackay9 2012-10-02 22:16:19 +09:00
parent 09d8a8a2d1
commit 770aa0b56b
4 changed files with 15 additions and 8 deletions

View File

@ -114,8 +114,9 @@ public:
k_param_ch7_option, k_param_ch7_option,
k_param_auto_slew_rate, k_param_auto_slew_rate,
k_param_sonar_type, k_param_sonar_type,
k_param_super_simple = 155, k_param_super_simple,
k_param_axis_enabled = 157, k_param_battery_pin,
k_param_axis_enabled,
k_param_copter_leds_mode, k_param_copter_leds_mode,
k_param_ahrs, // AHRS group k_param_ahrs, // AHRS group
@ -236,6 +237,7 @@ public:
AP_Int8 optflow_enabled; AP_Int8 optflow_enabled;
AP_Float low_voltage; AP_Float low_voltage;
AP_Int8 super_simple; AP_Int8 super_simple;
AP_Int8 battery_pin;
AP_Int16 rtl_approach_alt; AP_Int16 rtl_approach_alt;
AP_Int8 tilt_comp; AP_Int8 tilt_comp;
AP_Int8 axis_enabled; AP_Int8 axis_enabled;

View File

@ -98,6 +98,13 @@ const AP_Param::Info var_info[] PROGMEM = {
// @User: Standard // @User: Standard
GSCALAR(super_simple, "SUPER_SIMPLE", SUPER_SIMPLE), 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 // @Param: APPROACH_ALT
// @DisplayName: RTL Approach Altitude // @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. // @Description: This is the altitude the vehicle will move to as the final stage of Returning to Launch. Set to zero to land.

View File

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

View File

@ -77,11 +77,11 @@ static void read_battery(void)
} }
if(g.battery_monitoring == 3 || g.battery_monitoring == 4) { if(g.battery_monitoring == 3 || g.battery_monitoring == 4) {
static AP_AnalogSource_Arduino bat_pin(BATTERY_PIN_1); static AP_AnalogSource_Arduino bat_pin(g.battery_pin);
battery_voltage1 = BATTERY_VOLTAGE(bat_pin.read_average()); battery_voltage1 = BATTERY_VOLTAGE(bat_pin.read_average());
} }
if(g.battery_monitoring == 4) { if(g.battery_monitoring == 4) {
static AP_AnalogSource_Arduino current_pin(CURRENT_PIN_1); 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()); current_amps1 = CURRENT_AMPS(current_pin.read_average());
current_total1 += current_amps1 * 0.02778; // called at 100ms on average, .0002778 is 1/3600 (conversion to hours) current_total1 += current_amps1 * 0.02778; // called at 100ms on average, .0002778 is 1/3600 (conversion to hours)
} }