Hello guest, if you read this it means you are not registered. Click here to register in a few simple steps, you will enjoy all features of our Forum.
This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Virtual Current Sensor with Cleanflight / Betaflight
#1
I always considered current sensor, amps and mAh measurements out-of-reach concepts, left for specialized / proprietary hardware for big-brand builds like the Vortex, DJI etc. I knew Cleanflight Configurator supports the concept and browsing through the docs few weeks back, I stumbled on the Virtual Current Sensor description It looked simple enough so I tried it, seems to work pretty well, so I decided to share my quick setup.

DISCLAIMER: Standing near an armed multi-rotor running at full throttle is dangerous! Do at your own risk. Check and re-check your straps or other stabilization system and ensure the craft cannot lift, tilt, fall off or cut through the restraints. Make sure the propellers and other moving parts are not at risk of snagging/cutting something.

As the docs state, the virtual sensor needs to be calibrated with an offset and scale parameters using two recommended methods:
  1. Actual Current Measurement - with a power analuzer, current meter, etc
  2. Battery Charger Measurement - with a charger that show accurately how much mAh were charged.

I went for #1 as I recently acquired a power analyzer tool for my thrust test setup.

Setup
[Image: 2016-04-16-12.41.35.jpg]
  • Power analyzer or any other convenient way to measure the LiPo current when disarmed and at full throttle

  • High-C charged LiPo capable of sustaining full throttle of your quad for a few seconds.

  • Quad running Cleanflight or Betaflight

  • OSD - MinimOSD running MW-WII firmware. Oscar Liang has an excellent tutorial for how to configure this OSD

  • Propellers - choose the most common of your
Secure The Craft Down

This is the most important step. Ensure your quad will not endanger anybody or cause damage when running at full throttle. I strapped mine down to a heavy saw-horse as shown below and ensured the blades spin free and the LiPo/power analyzer are safely out of the day.

[Image: 2016-04-16-12.39.49.jpg][Image: 2016-04-16-12.41.35.jpg]

Measure The Current

The Cleanflight docs indicate to measure current at disarm Imin and at full throttle Imax. If your VTX requires additional button to power-on, press it. I personally chose to ignore the initial current spike at full throttle, and waited a second or so to settle before taking the value. I am not sure if motor-stop is factored anywhere, as it doubles the Imin value, I guess this is question for the firmware developers.



Calculate The Parameters

In addition to the current measurements, you need your max_throttle value - available in the Configuration tab or via CLI:

Code:
# get max_throttle
max_throttle = 1850


This value substracted by 1000 will give you TMax. The formula is available from the Cleanflight docs - https://github.com/cleanflight/cleanflig...asurements
Since the formula is a bit long and I have several quads, I created this spreadsheet that gives the final numbers easily. Feel free to download and share: https://www.dropbox.com/s/4b6l1yuyb7xk7k....xlsx?dl=0

Configure Flight Controller

Enable the current sensor and enter the calculated offset and scale parameters

[Image: CleanflgihtConfig-1.png]

Alternatively via CLI:

Code:
feature CURRENT_METER
set current_meter_scale = 350
set current_meter_offset = 40


Final step is to set the current meter type to virtual. I did not see a GUI version for this and the CLI value differs between Cleanflight and Betaflight as follows:

Code:
# Cleanflight:
set current_meter_type = 2
# Betaflight:
set current_meter_type = VIRTUAL


Configure OSD

Enable amperage display in the MW-OSD GUI and select FC as the source. When all is working, the OSD will reflect the estimated current and mAh drained from the battery.

[Image: Screen-Shot-2016-04-16-at-2.12.41-PM.png][Image: Screen-Shot-2016-04-16-at-1.08.09-PM.png]



Things to keep in mind
  • This method will provide only estimated current measurements.
  • The calculated parameters are unique to your individual build
  • Changing electronics, motors or even propellers will require re-calibration
I recommend measuring with some of your more aggressive propellers, in my case 5045BN, perhaps even tri-blades. This way at-least you are over-estimating the current, which I believe is better than under.  Hope you all found this helpful. Please send feedback and questions.

This is a cross-post from my blog: http://jaisor.net/index.php/2016/04/16/c...-tutorial/
The next build will be perfect! | Fleet and build info | YouTube Channel |
Reply
Login to remove this ad | Register Here
#2
That is a great Tutorial Smile , Thanks for taking the time to do all the hard yards and share with us mere mortals.
My youtube channel

Reply
#3
That's very inspiring!!
Somehow I have always been ignoring this great virtual current sensor feature in Cleanflight!

Some might wonder how accurate this would be since it's only based on throttle level... it's just based on estimation... won't be as accurate as actual current sensor... but it's good for those who want to have some sort of current monitoring... but unable to get a real one... some might have better luck than others in terms of accuracy... I am just going to give it a try myself see how good it is Smile
Don't be a LOS'er, be an FPV'er :)  My Gear - Facebook - Instagram - Twitter
Reply
#4
Wow that's great. Always been working with actual current sensors, one more to throw off the quad Smile
Reply
#5
Aw, thanks fellas Smile Glad you like it. I need to put in an addition for Taranis with SBUS/SmartPort telemetry. With such setup the current and consumption measurements are already available on the radio, if you change the current sensor to FAS. At that point it was easy to setup a logical function and some "Play Value" to alarm at certain intervals when the consumption is above a desired value.
The next build will be perfect! | Fleet and build info | YouTube Channel |
Reply
#6
This is a pretty decent approximation for a fixed setup, it is actually called linearization as we are approximating the I(throttle) curve with a line equation :-)
The virtual sensor in CF seems to approximate the curve with a secant between min and max throttle points. I think that approximating around the hover point might give better results, will experiment with that when have enough time.
Reply
#7
The way I calibrated my virtual current measurement in MWOSD (I guess this is somewhat the same as the virtual current measurement on the FC) was by the 2nd method (flying, charging the battery and compare).

1. note the current calibration factor in MWOSD, lets say as an example the factor is 115.
2. take a fully charged battery and fly it (for more accurate estimation, fly at least a couple of batteries).
3. after each flight, take a note of how many mAh is shown on the screen (better not fly the battery empty but I guess this is common sense).
4. Charge the battery/batteries and make a note of how many mAh they where charged to.
5. calculate new current factor: NEW_OSD_FACTOR=OLD_OSD_FACTOR*CHARGED_mAh/OSD_mAh.

Here is an example from my setup:

OSD_factor=115
Current shown on OSD = 591mAh
Battery Charged = 892mAh

NEW_OSD_factor=115*892/591=175

I tested it and it is quite accurate (+/- 50mAh), and for even more accurate OSD factor, it can be done again with the new OSD current factor. Also, my quad uses about 0.5A when not armed, so my zero adjust = 5
Reply
#8
Is it necessary to connect lipo to the VBAT pins to use this feature ? For some reason my osd doesn't show any current measurements from FC (use FC amperage enabled), though I can tune pids without any problems. I'm using betafligh 2.6.1 btw.
Reply
#9
Good question.. I'm not sure. from my understanding, the only thing that is needed for this to work is the throttle signal from the FC, but I could be wrong. I have vbat connected to the osd on my setup so the FC is not dealing with the current or voltage at all
Reply
#10
It's incredibly precise and handy in my case for a blind estimation.
VBAT is not used, but my idea is that heuristically incorporating VBAT into equation could make it even better in case of sudden overloads and voltage sags.
Reply
#11
It should be quite easy to design an accurate and real current sensor.
You measure :
- the resistance on vbat pins
- the resistance of the rest of the circuit
you get the total current being used by the current divider formula!
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Fettec G4 mixed with Betaflight 60 amp 6S esc mattyfleischfpv 0 184 16-Feb-2024, 03:19 PM
Last Post: mattyfleischfpv
  Fix a noisy current sensor V-22 3 1,375 30-Mar-2022, 05:39 PM
Last Post: leestrong
  FC Hoe to restore UART'S in Ports tab betaflight.. whatever 4 1,813 05-Aug-2021, 11:27 PM
Last Post: whatever
  Tutorial How To Calibrate Your Current Sensor SnowLeopardFPV 12 3,658 24-May-2021, 12:02 PM
Last Post: ph2t
  RX Betaflight checcofpv 3 680 17-May-2021, 06:20 PM
Last Post: Kevin2112


Login to remove this ad | Register Here