Current sensors can be easily added.
Examples are the one from Sparkfun (AttoPilot Voltage and Current Sense Breakout Current sensor) or a linear hall-effect device such as the Allegro ACS755 or ACS715. The Novak Sentry current sensor is based on the ACS755LCB-100 hall-effect sensor and has a range of 100A. The smaller and lighter Pololu Current Sensor Carrier is based on the ACS715 with a current of up to 30A.
Typically, the current sensor is used to measure the current flowing through the main battery (rather than the motor). Connect the + and - pole of the sensor through the battery red lead. The + and - have to be soldered directly.
On the Sparkfun breakout board, a wire is connected to the "VI" pin. It must have a voltage between 0 and 3.3V. On a TWOG v1 or Tiny v2 board, the current sense output wire ("IA" on the Sparkfun sensor) is connected to the ADC_3 (or ADC_4) pin.
On the Novak Sentry current sensor, the red wire is connected to +5 volts. The black wire is ground. The yellow wire is the output (40mV/amp. 0.6v=0amps, 5.0v=110amps) and is connected to the ADC_3 (or ADC_4) pin.
Following code needs to be added to the airframe conf:
<firmware name="fixedwing"> ... <define name="USE_ADC"/> <define name="USE_ADC_3"/> <!-- motor current--> </firmware> ... <section name="BAT"> ... <define name="ADC_CHANNEL_CURRENT" value="ADC_3" /> <define name="MilliAmpereOfAdc(adc)" value="Max(0,adc*88)"/> <section/>
The Max(0,x) ensures that instead of getting a negative current when using a motor brake it is set to zero, thus not corrupting your energy estimate. If you have a setup where the current can become negative (e.g. charging the battery via solar cells) don't use Max.
Remove the line:
<define name="MILLIAMP_AT_FULL_THROTTLE" value="12000" unit="mA"/>
The correct multiplier for the raw measurement conversion depends on the current sensor. The Sparkfun sensor returns a linear voltage of 0 V - 3.3 V and at 90.15 A it reaches the maximum of 3.3 V. The TWOG v1 or Tiny v2 have a A/D converter with 10-bit precision (1024 different values) to represent the voltage. So you can calculate the multiplier with the following formula:
1000 / precision * A_at_max_voltage
For the Sparkfun sensor, the precision is 1024 and A_at_max_voltage is 90.15 => 1000/1024*90.15 = 88.037
For the ACS755LCB-100 sensor, there is a 0.6 volts offset. At 3.3v, the current is 67.5A. The formula is thus: value="(80.55*(adc-185))"
For the ACS755LCB-50 sensor, there is a 0.6 volts offset. At 3.3v, the current is 45.A. The formula is thus: value="(43.94*(adc-185))"
Values By AGRESSiVA:
For the ACS755LCB-50 sensor using resistive divisor (1k8/3k3). The formula is thus: value="(68.017*(adc-120))" (not confirmed / tested)
For the ACS755LCB-100 sensor using resistive divisor (1k8/3k3). The formula is thus: value="(122.5*(adc-120))"
Display on Ground Control Station (GCS)
Use the Messages application to show it.
The total energy consumed during the flight (in mAh) is sent in the "BAT" message.
The actual current flowing through the sensor (in mA) is sent in the "fbw_status" message.
You can display the energy or current on the GCS by just dragging and dropping them on the 2d map.
Current / Voltage Sensor
If you would like to install the autopilot on a bigger airframe, you can face the problem, that the nominal voltage of the battery-pack is higher then allowed for the autopilot. (i.e. 6 cell LiPo and TWOG ) But if you use a voltage regulator, then the autopilot has no information on the real voltage of the battery-pack. The GCS will show the autopilot input voltage, which is irrelevant regarding the remaining capacity of the battery-pack.
Fortunately the AttoPilot Voltage and Current Sensor (Sparkfun) provides a voltage signal scaled down to 3.3V, too. This can be connected to a general analog input of the autopilot (for example ADC_4) similar to the current signal. If you configure the airframe file in the following way, the autopilot will provide all of the warnings (i.e. Battery Low) and calculations (i.e. power consumption) as it does in case of a direct connection between autopilot and battery-pack.
Further information can be found on Airframe_Configuration#Battery.
<firmware name="fixedwing"> ... <define name="USE_ADC"/> <define name="USE_ADC_4"/> <!-- Battery voltage--> <define name="ADC_CHANNEL_VSUPPLY" value="ADC_4"/> </firmware> ... <section name="BAT"> ... <define name="VOLTAGE_ADC_A" value="0.05"/> <define name="VOLTAGE_ADC_B" value="1"/> <define name="VoltageOfAdc(adc)" value="(VOLTAGE_ADC_A * adc + VOLTAGE_ADC_B)"/> <section/>
Don't need to load the adc_generic module! You will get wrong values in the energy messages!
(The above method was tested with Sparkfun Attopilot Current Sensor and TWOG.)