BATT_AMP_OFFSET=-0.007 - not set automatically on Plane

For a past few days I’ve been working to get current (amps) telemetry on my first Plane build.

I’m using an Orange Cube, AirBot Mini Carrier Board, Mini Power Brick.

I setup the battery monitor as I had on my Copter builds using the Mini Power Brick:

When selecting “Analog Voltage and Current” various other BATT parameters are automatically populated.

For some reason, BATT_AMP_OFFSET was not set - and remained at 0. On my Copter builds, this parameter was set to -0.007. I’m not sure what set this - either Copter or Mission Planner. But on setting up Plane, it wasn’t set, and remained at 0.

As a result, all the telemetry for current was zero. I tried running up the motor to test drawing more current - again nothing.

Comparing the parameters on my Copter builds using the Mini Power Brick, I noticed that they had BATT_AMP_OFFSET=-0.007. It was zero on my Plane parameters.

By setting BATT_AMP_OFFSET=-0.007 the telemetry now reads 0.5 amps with the electronics/motor at idle. And I now get current telemetry when running the motor - but only with a prop attached to increase the current load.

It turns out that the resolution of the Mini Power Brick is too poor to report low levels of current. I remember reading about this when learning Copter - but with four motors, the current was always high enough. It seems with a single motor on a fixed-wing, I may need an more sensitive current sensor.

To illustrate - I graphed the throttle position (PWM) against the current (amps) when running up the motor with the prop on:

Until the ESC receives a PWM signal of about 1450, no current is reported.

I suspect that had I done the test running the motor with the prop on before setting BATT_AMP_OFFSET=-0.007 some current would have been reported at high throttle.

In the Parameter List this the BATT_AMP_OFFSET is mentioned - but I can’t find any information on how to set it properly. I would think that it’s a value that should be offered by the current sensor manufacturer, but I don’t even recall mention of it with my MAUCH sensors.

It would be interesting to know why and how the BATT_AMP_OFFSET parameter got set on my Copter builds. And why it didn’t on Plane.

And if the wiki has information on how to properly set BATT_AMP_OFFSET I need to go back and study that. For now, BATT_AMP_OFFSET=-0.007 produced telemetry - but I have no idea if it’s correct. As I recall, the wiki guides setting BATT_AMP_PERVLT when calibrating current sensors, but I don’t recall reading a mention of BATT_AMP_OFFSET.

ADDENDUM:

The BATT_AMP_OFFSET parameter on my copter using a MAUCH current sensor has this value set to 0. This value works with this sensor.

I’m reaching out to Christian Mauch to see if he has advice on properly setting this value.

While I understand your observation, the only valid conclusion here is that Cube power module current sensors are poor at accurately reporting low current values (which is fairly well known).

BATT_AMP_OFFSET doesn’t magically activate a current sensor, and always offsetting by -7mV probably isn’t a proper conclusion. It is simply an offset used to set the zero point. It is perhaps poorly named, as the unit is volts, and it is a raw offset of the voltage read from the current pin’s ADC. Description per source code documentation:

Voltage offset at zero current on current sensor for Analog Sensors. For Synthetic Current sensor, this offset is the zero throttle system current and is added to the calculated throttle base current.

Single line of code where the value is applied (_curr_amp_offset is the variable to which BATT_AMP_OFFSET is assigned):

_state.current_amps = (_curr_pin_analog_source->voltage_average() - _curr_amp_offset) * _curr_amp_per_volt;

You would set this value per a current sensor’s datasheet (or if you noticed a consistent offset from measured truth data across the entire linear range of measurement).

Lastly, one would not expect this value to be set automatically. Here are the default parameters from the Cube’s hwdef (amp offset being notably and correctly absent):

# setup correct defaults for battery monitoring for cube power brick
BATT2_CURR_PIN 4
BATT2_VOLT_PIN 13
BATT_AMP_PERVLT 39.877
BATT_VOLT_MULT 12.02
BATT2_AMP_PERVLT 39.877
BATT2_VOLT_MULT 12.02
# setup ADSB
ADSB_TYPE 1
SERIAL5_BAUD 57
SERIAL5_PROTOCOL 1
EK2_PRIMARY 1
EK3_PRIMARY 1

Put another way, your value of -0.007 means that you always subtract about 1/4 ampere from the current sensed by a Cube power module (assuming otherwise default BATT parameters).

2 Likes

The offset is usually only used for some very specific current sensors that actually have a small offset, or “deadzone” if you like, near zero. The sensors Mauch use dont require this offset.

Standard resistor/shunt based current sensors dont usually require an offset, and as Yuri says, they are notoriously bad at reporting anything less than say 3 amps (maybe more).
I’ve not seen where a Cube power module requires an offset.

A better solution is to properly calibrate the current sensor:

  • Plug in a fresh battery and do a hover flight for 5 minutes or until you’ve used a significant amount of battery capacity
  • Immediately unplug the battery and charge it, note how many mah’s it took to charge. Let’s say that was 1,500 mah
  • Download your log and look at maximum CurrTot. Let’s say it was 1,300 mah
  • Get your existing BATT_AMP_PERVOLT setting from Mission Planner, let’s say 17
  • NEW_AMPS_PER_VOLT = OLD_AMPS_PER_VOLT x CHARGED_MAH / LOGGED_MAH
    With my example numbers, you’d get
    NEW_AMPS_PER_VOLT = 17 x 1,500 / 1,300 = 19.61
  • Set the new value in the BATT_AMP_PERVOLT parameter and save to your copter
  • Fly to check, repeat until you’re happy the new value gives consistent readings
2 Likes

There are two reasons I thought BATT_AMP_OFFSET might be set automatically is 1) other parameters are set when selecting the analog current and voltage option - and 2) I have no idea how else that parameter was set my quad-copters that use the Mini Power Brick.

No doubt - the value of “-0.007” has a mystery to it. With it, the reported current at idle is 0.5A. Attaching an inline external amp meter I see that the actual current draw is 0.3A - and to get that reading from the telemetry BAT_AMP_OFFSET has to be set to “-0.0025”.

As I’m realizing now, this is all of little importance. The only reason I dug into this was because I was getting no (well, “0” - is something) current reported and I thought there might be a problem somewhere in the hardware. It wasn’t until I put a prop on the motor and ran it up to over 50% throttle that I got current reported.

The advantage of setting BAT_AMP_OFFSET at a proper value even if the Mini Power Brick only really reports current telemetry at higher currents is that if a non-zero value is reported at idle then it’s know that the current sensor is at least alive.

I went back and read the wiki on calibrating a current sensor and watched Randy MacKay’s excellent old (but still valid) video on calibrating a current sensor. I actually took the opportunity to use my external in-line amp meter top perform the calibration.

Nothing in this process mentions BAT_AMP_OFFSET and I’ve been unable to find it mentioned in the wiki other than the parameter list. It’s not a big deal, except I spent 3 days trying to figure out why my current sensor didn’t have current telemetry. I mistakenly though it was something with the AirBot carrier board - which I’d never used before.

It’s all part of the learning process - and if this entry on this forum helps someone else in the future, then it’s all good.

The proper value for a Cube brick is zero.

1 Like

If that’s true - then something is wrong. Because when I set that parameter to zero, then zero is the reported current telemetry - when in fact, the cube and sensors are drawing 0.3A.

Just curious - where do you find that spec published?

Shawn explains quite succinctly here.

Additionally, I don’t see where it’s published to set anything other than zero, and zero is the default.

I expect that if you set something other than zero, you will introduce error in the range where the sensor is actually valid.

I appreciate all this input. But it conflicts with what’s happening on my workbench.

It would be nice to have some documentation to reference. Especially for the newcomer - and we were all newcomers once.

There is no conflict other than your desire to measure current in a range where this sensor type is notoriously inaccurate/invalid.

2 Likes

Yes - indeed, I calibrate my current sensors using the process you describe. And as most of my copters have MAUCH current sensors - having BATT_AMP_OFFSET set to zero hasn’t been a problem.

The reason why any of this matters is that my fixed wing build reported zero amps - even when I ran the throttle up to full - without the prop. As far as I could tell - the current sensor - or some part of that system - wasn’t working. And as I was using an AirBot Mini Carrier Board for the first time - I erroneously suspected that it was the culprit.

It wasn’t until I put a prop on and ran the motor up to over 50% throttle that the Mini Power Brick reported any current telemetry. And RCOU has to be well over 1500 for current telemetry to be reported.

Remember - this is a fixed wing - running a small motor - as I expect most first fixed wing projects are. So things work a bit differently than on our copters.

While using the mysterious “-0.007” value for BAT_AMP_OFFSET produced a positive value of 0.5A for the flight controller and sensor at idle - my external in-line amp meter showed 0.3A. So I tried values until I found that -0.0025 produced the matching 0.3A on the telemetry.

Yuri’s point that setting BAT_AMP_OFFSET may cause other errors in current reporting - but in my testing with an inline current sensor - it didn’t make any difference to the current telemetry that was reported. It would be helpful if there were some info on the topic in the wiki.

My error in dealing with all of this is not remembering that the Mini Power Brick needed a much higher load to report current telemetry - and I didn’t verify that it was working by running the motor up with the prop on. I spent 3 days investigating all this due that error.

And the only reason I’ve spent so much time reporting on all of this is that I hope the next time someone builds their first small fixed wing, this thread might save them some time.

No doubt - the Mini Power Brick isn’t going to report accurate current telemetry if my fixed wing cruises at throttle setting below about 60% throttle. But it should be fine if such higher throttle settings are used. In the meantime, the Mini Power Brick is an excellent simple BEC for the flight controller. I’d probably still use it even if I had to rely only on voltage for battery failsafe.

This is actually pretty simple math that you can reference via the source code snippet I shared above. If you set an offset, you will change the y-intercept of the current slope. You probably saw no appreciable change because you are only applying a ~1/4 amp offset.

I appreciate the snippet. Thank you.

It’s all coming together…

1 Like

Here there is a good example of when an offset value is needed: ArduCopter 7" Long-Range Standard Build Look at section “15. Current Calibration and Bi-Directional DSHOT Setup”
The measured curve is quite linear but also has an offset of over 2 Amp at 0 rpm.