Current and Energy: See microjet5.xml for current estimation example and holiday50.xml for current measurement example

This commit is contained in:
Christophe De Wagter
2009-05-21 07:42:45 +00:00
parent db2c655f25
commit 365f5ab105
8 changed files with 48 additions and 17 deletions
+5 -1
View File
@@ -57,6 +57,8 @@
<define name="GYRO_NB_SAMPLES" value="16"/>
<define name="AIRSPEED" value="ADC_5"/>
<define name="AIRSPEED_NB_SAMPLES" value="32"/>
<define name="CURRENT" value="ADC_6"/> <!-- Current Measurement -->
</section>
<section name="INFRARED" prefix="IR_">
@@ -100,8 +102,10 @@
</section>
<section name="BAT">
<define name="MILLIAMP_PER_PERCENT" value="1.5"/> <!-- 15Amp Full power on Ground -->
<define name="MILLIAMP_AT_FULL_THROTTLE" value="12000"/> <!-- 12Amp Full power on Ground -->
<define name="CATASTROPHIC_BAT_LEVEL" value="9.3" unit="V"/>
<define name="MilliAmpereOfAdc(adc)" value="((adc-508)*50)"/>
</section>
<section name="MISC">
+1 -1
View File
@@ -74,7 +74,7 @@
</section>
<section name="BAT">
<define name="MILLIAMP_PER_PERCENT" value="0.86"/>
<define name="MILLIAMP_AT_FULL_THROTTLE" value="11000" unit="mA"/>
<define name="CATASTROPHIC_BAT_LEVEL" value="9.3" unit="V"/>
</section>
+1
View File
@@ -314,6 +314,7 @@
<field name="rc_status" type="uint8" values="OK|LOST|REALLY_LOST"/>
<field name="mode" type="uint8" values="MANUAL|AUTO|FAILSAFE"/>
<field name="vsupply" type="uint8" unit="decivolt"/>
<field name="current" type="uint16" unit="mA"/>
</message>
<message name="ADC" id="104">
+1 -1
View File
@@ -53,7 +53,7 @@
#define PERIODIC_SEND_COMMANDS() DOWNLINK_SEND_COMMANDS(COMMANDS_NB, commands)
#ifdef RADIO_CONTROL
#define PERIODIC_SEND_FBW_STATUS() DOWNLINK_SEND_FBW_STATUS(&rc_status, &fbw_mode, &fbw_vsupply_decivolt)
#define PERIODIC_SEND_FBW_STATUS() DOWNLINK_SEND_FBW_STATUS(&rc_status, &fbw_mode, &fbw_vsupply_decivolt, &fbw_current_milliamp)
#define PERIODIC_SEND_PPM() DOWNLINK_SEND_PPM(&last_ppm_cpt, PPM_NB_PULSES, ppm_pulses)
#define PERIODIC_SEND_RC() DOWNLINK_SEND_RC(PPM_NB_PULSES, rc_values)
#else // RADIO_CONTROL
+3 -1
View File
@@ -55,7 +55,8 @@ struct fbw_state {
#endif
uint8_t status;
uint8_t nb_err;
uint8_t vsupply; /* 1e-1 V */
uint8_t vsupply; /* 1e-1 V */
uint16_t current; /* milliAmps */
};
struct ap_state {
@@ -121,6 +122,7 @@ static inline void inter_mcu_fill_fbw_state (void) {
#endif // RADIO_CONTROL
fbw_state->vsupply = fbw_vsupply_decivolt;
fbw_state->current = fbw_current_milliamp;
}
/** Prepares date for next comm with AP. Set ::ap_ok to TRUE */
+7 -10
View File
@@ -144,10 +144,6 @@
#define LOW_BATTERY_DECIVOLT (CATASTROPHIC_BAT_LEVEL*10)
#ifndef MILLIAMP_PER_PERCENT
#define MILLIAMP_PER_PERCENT 0
#endif
#ifdef USE_MODULES
#include "modules.h"
#endif
@@ -165,8 +161,6 @@ static const uint16_t version = 1;
uint8_t pprz_mode = PPRZ_MODE_AUTO2;
uint8_t lateral_mode = LATERAL_MODE_MANUAL;
uint8_t vsupply;
static uint8_t mcu1_status;
#if defined RADIO_CONTROL || defined RADIO_CONTROL_AUTO1
@@ -179,7 +173,10 @@ float slider_1_val, slider_2_val;
bool_t launch = FALSE;
float energy; /** Fuel consumption */
uint8_t vsupply; // deciVolt
uint16_t current; // milliAmpere
float energy; // Fuel consumption (mAh)
bool_t gps_lost = FALSE;
@@ -312,6 +309,7 @@ inline void telecommand_task( void ) {
vsupply = fbw_state->vsupply;
current = fbw_state->current;
#ifdef RADIO_CONTROL
if (!estimator_flight_time) {
@@ -402,8 +400,8 @@ static void navigation_task( void ) {
Bound(h_ctl_pitch_setpoint, H_CTL_PITCH_MIN_SETPOINT, H_CTL_PITCH_MAX_SETPOINT);
if (kill_throttle || (!estimator_flight_time && !launch))
v_ctl_throttle_setpoint = 0;
}
energy += (float)v_ctl_throttle_setpoint * (MILLIAMP_PER_PERCENT / MAX_PPRZ * 0.25);
}
energy += ((float)current) / 3600.0f * 0.25f; // mAh = mA * dt (4Hz -> hours)
}
@@ -577,7 +575,6 @@ void periodic_task_ap( void ) {
}
#endif
#if CONTROL_RATE == 20
if (!_20Hz)
#endif
+29 -2
View File
@@ -58,14 +58,25 @@
#include "link_mcu.h"
#endif
#ifndef MILLIAMP_AT_FULL_THROTTLE
#define MILLIAMP_AT_FULL_THROTTLE 0
#endif
#ifdef ADC
struct adc_buf vsupply_adc_buf;
#ifndef VoltageOfAdc
#define VoltageOfAdc(adc) DefaultVoltageOfAdc(adc)
#endif
#ifdef ADC_CHANNEL_CURRENT
struct adc_buf current_adc_buf;
#ifndef MilliAmpereOfAdc
#define MilliAmpereOfAdc(adc) DefaultMilliAmpereOfAdc(adc)
#endif
#endif
#endif
uint8_t fbw_vsupply_decivolt;
uint16_t fbw_current_milliamp;
uint8_t fbw_mode;
@@ -87,6 +98,9 @@ void init_fbw( void ) {
#ifdef ADC
adc_init();
adc_buf_channel(ADC_CHANNEL_VSUPPLY, &vsupply_adc_buf, DEFAULT_AV_NB_SAMPLE);
# ifdef ADC_CHANNEL_CURRENT
adc_buf_channel(ADC_CHANNEL_CURRENT, &current_adc_buf, DEFAULT_AV_NB_SAMPLE);
# endif
#endif
#ifdef ACTUATORS
actuators_init();
@@ -147,6 +161,7 @@ void event_task_fbw( void) {
}
#endif /* MCU_SPI_LINK */
if (inter_mcu_received_ap) {
inter_mcu_received_ap = FALSE;
inter_mcu_event_task();
@@ -202,11 +217,23 @@ void periodic_task_fbw( void ) {
fbw_downlink_periodic_task();
#endif
#ifdef ADC
if (!_10Hz)
fbw_vsupply_decivolt = VoltageOfAdc((10*(vsupply_adc_buf.sum/vsupply_adc_buf.av_nb_sample)));
{
#ifdef ADC
fbw_vsupply_decivolt = VoltageOfAdc((10*(vsupply_adc_buf.sum/vsupply_adc_buf.av_nb_sample)));
# ifdef ADC_CHANNEL_CURRENT
fbw_current_milliamp = MilliAmpereOfAdc((current_adc_buf.sum/current_adc_buf.av_nb_sample));
# endif
#endif
#ifndef ADC_CHANNEL_CURRENT
# ifdef MILLIAMP_PER_PERCENT
# warning "deprecated MILLIAMP_PER_PERCENT --> Please use MILLIAMP_AT_FULL_THROTTLE
# endif
fbw_current_milliamp = Min(((float)commands[COMMAND_THROTTLE]) * ((float)MILLIAMP_AT_FULL_THROTTLE) / ((float)MAX_PPRZ), 65000);
# endif
}
#ifdef ACTUATORS
SetActuatorsFromCommands(commands);
#endif
+1 -1
View File
@@ -41,8 +41,8 @@
extern uint8_t fbw_mode;
extern uint8_t fbw_vsupply_decivolt;
extern uint16_t fbw_current_milliamp;
extern bool_t failsafe_mode;
extern struct adc_buf vsupply_adc_buf;
void init_fbw( void );
void periodic_task_fbw( void );