Battery management module for Python

Firmware/software/electronics/mechanics
Post Reply
nanobot9000
Beginner
Posts: 26
Joined: Mon Apr 11, 2016 4:33 pm

Battery management module for Python

Post by nanobot9000 » Wed Dec 12, 2018 7:25 pm

As in my previous post I am merely a beginner, but by reading the annotated python examples, it helps to fill in the blanks and make changes. I finally got my new Flowdeck V2 and some new props to replace all the ones I broke in random crashes so ready to test out more code. :)

I have searched and read a few different posts in the forum about gathering battery data to use for either logging or for a gentle landing when out of range. I am wondering if any of the python wizards out there have any snippets of code that can be inserted to monitor the battery voltage and based on a value either flash the LEDs or even land when it reaches a certain percentage. I can see that being useful in many of the examples like the multiranger or other autonomous examples. Not sure if it is possible, but if there were a way to have that "module" of code accessible, it could then be invoked in other examples as needed. That way no matter what your are doing with the crazylflie, if you have the "battery power" mode "turned on" it will land when it reaches a set level. I would think this would be useful in all situations to prevent a hard fall.

Hopefully this is doable!

Thanks,
Mike

arnaud
Bitcraze
Posts: 1835
Joined: Tue Feb 06, 2007 12:36 pm

Re: Battery management module for Python

Post by arnaud » Thu Dec 13, 2018 6:30 am

Hi,
Yes this is doable but not with a ready-to-use battery module, though such a module might actually be a good idea to have now that the Crazyflie is more autonomous.

The way to do it for now is like a lot of things with Crazyflie: setting up a log. You can log "pm.batteryLevel" to get a number from 0 to 100 representing the current level of charge of the Crazyflie. Looking at the code there should even be a way to get the info that the Crazyflie is in low power mode (front right LED lit in RED) with "pm.pmState". The code is there: https://github.com/bitcraze/crazyflie-f ... 2f4.c#L395.

As for the python part, if you are already setting up a log you can try to sneak "pm.batteryLevel" in your existing log block (it is only 1 byte). Otherwise the asynchrone log api would be a good fit for this kind of functionality: https://github.com/bitcraze/crazyflie-l ... asiclog.py.

nanobot9000
Beginner
Posts: 26
Joined: Mon Apr 11, 2016 4:33 pm

Re: Battery management module for Python

Post by nanobot9000 » Thu Dec 13, 2018 4:33 pm

Thanks. I will look that over and see what I can come test out. I do agree that it would be good to include that in the default setup given the future of the autonomous options that exist. :D

Post Reply