Mellinger controller on Python

Firmware/software/electronics/mechanics
EduardoAguilar
Beginner
Posts: 27
Joined: Tue May 05, 2020 2:05 am

Mellinger controller on Python

Post by EduardoAguilar »

Hi guys

I have a problem when i try to run some example from cflib, when i try to run the position_commander_demo.py code my crazyflie just conneting with the crazyradio but the crazyflie dont run the task, just connected and after a little time it disconected, like if the crazyflie was finished his task.

On the firmware i'm using the mellinger controller.
In the moment just want to use the mellinger controller on Python, maybe after i will to use the mellinger controller on ROS.

Can someone help me?

thank you!!
kristoffer
Bitcraze
Posts: 630
Joined: Tue Jun 30, 2015 7:47 am

Re: Mellinger controller on Python

Post by kristoffer »

Hi!

What kind of positioning system are you using?

You can get this effect if the estimated position (height) is wrong, for instance if the estimated height on the floor is 1.0 m and the set point sent to the Crazyflie has z=0.5. The PositionHlCommander uses absolute set points which can give this problem.

Have you tried the autonomous_sequence_high_level.py script? It uses relative set points instead and should work better if the estimated position is a bit off.
EduardoAguilar
Beginner
Posts: 27
Joined: Tue May 05, 2020 2:05 am

Re: Mellinger controller on Python

Post by EduardoAguilar »

Hi kristoffer, thanks for the answer


I'm using flow deck, i proof the autonomous_sequence_high_level.py script
and i have the same problem.
This is the messages on Python IDE

Code: Select all

usr/bin/python3.6 /home/eduardo/Escritorio/crazyflie-lib-python-master/examples/autonomous_sequence_high_level.py
Connecting to radio://0/80/250K
Connected to radio://0/80/250K
Uploading data
Data uploaded
The sequence is 7.3 seconds long
Waiting for estimator to find position...
Process finished with exit code 0
I will to try upload the firmware with mellinger controller again and i will to tray other once,
do you have a better idea?

Thank you again
EduardoAguilar
Beginner
Posts: 27
Joined: Tue May 05, 2020 2:05 am

Re: Mellinger controller on Python

Post by EduardoAguilar »

Hi

I reloaded upload the firmware 2020.04 with mellinger controller and have the same problem, i was
trying to run both scripts (position_commander_demo.py and autonomous_sequence_high_level.py )
and the Crazyflie just connecting but didnt make the task.

thank you!!
kristoffer
Bitcraze
Posts: 630
Joined: Tue Jun 30, 2015 7:47 am

Re: Mellinger controller on Python

Post by kristoffer »

Unfortunately I don't have a flow deck to try with (working from home due to Corona), I will see if anyone else can try it out.
I will to try upload the firmware with mellinger controller again and i will to tray other once
I'm not sure what you mean, but there is no need to upload or flash any special firmware to use the mellinger controller, it is part of the stock firmware. you can active it by setting the 'stabilizer.controller' paramter to 2 (like this https://github.com/bitcraze/crazyflie-l ... #L134-L135). If you are using the PositionHlCommander you can activate it when creating the PositionHlCommander instance by passing in controller=PositionHlCommander.CONTROLLER_MELLINGER (like this https://github.com/bitcraze/crazyflie-l ... emo.py#L50)
kristoffer
Bitcraze
Posts: 630
Joined: Tue Jun 30, 2015 7:47 am

Re: Mellinger controller on Python

Post by kristoffer »

Kimberly tested to run the scripts with the flow deck and it works, even though the mellinger may be a bit aggressive.

Have you tried the motion commander (motion_commander_demo.py)?

The flow deck is measuring the relative motion in X/Y, while the system tries to integrate the deltas to maintain an absolute position (relative to the starting point). The motion commander uses velocity set points which works better with the flow deck, as opposed to the High level commander scripts that uses position set points. Both should work though.

Not sure what the problem might be. Could you also log the output from the distance sensor on the flow deck to make sure it is healthy? The variable to log is range.zrange.

Are you using the stock firmware? If not, also try on the latest release to see if that works (https://github.com/bitcraze/crazyflie-f ... ag/2020.04).
EduardoAguilar
Beginner
Posts: 27
Joined: Tue May 05, 2020 2:05 am

Re: Mellinger controller on Python

Post by EduardoAguilar »

Hi Kristoffer and Kimberly thank you for the answer and the help
I'm not sure what you mean, but there is no need to upload or flash any special firmware to use the mellinger controller, it is part of the stock firmware.
I was using the steps of this https://www.bitcraze.io/documentation/ ... Uvp6pLOyQ

when i have the folder of crazyflie-firmware i modification the crazyflie-firmware/Makefile

Code: Select all

######### Stabilizer configuration ##########
## These are set by the platform (see tools/make/platforms/*.mk), can be overwritten here
ESTIMATOR          ?= any
CONTROLLER         ?= Any # one of Any, PID, Mellinger, INDI
POWER_DISTRIBUTION ?= stock
i change

Code: Select all

ESTIMATOR ?=   kalmand
CONTROLLER         ?= Mellinger
also in others two files, cf2.mk and tag.mk on crazyflie-firmware/tools/make/platforms
after the modification this 3 files in my terminal i will write the next

Code: Select all

eduardo@eduardo-Aspire-V3-574:~/crazyflie-firmware$ make PLATFORM=cf2
......
eduardo@eduardo-Aspire-V3-574:~/crazyflie-firmware$ make cload
.....
and in a console of the cfclient say that I'm using the ESTIMATOR = kalman
and CONTROLLER = Mellinger

With this i was thinking that i was using mellinger controller if i didn't make this changes i was thinking that every-time i was using PID controller,
for this reason always i modification the 3 files.
Are you using the stock firmware? If not, also try on the latest release to see if that works (https://github.com/bitcraze/crazyflie-f ... ag/2020.04).
Actually I'm using https://github.com/bitcraze/crazyflie-f ... ag/2020.04
and all is working, thank you for the recomendations Kristoffer

But i have a question why my Crazyflie didn't make anything when i used crazyflie-firmware?
i use crazyflie-firmware because i want to do eduardo controller and if i always used firmware stock i think that i cant do eduardo controller

when i say eduardo controller i refer to own my controller.

Can you help me with this?


thank you!!
EduardoAguilar
Beginner
Posts: 27
Joined: Tue May 05, 2020 2:05 am

Re: Mellinger controller on Python

Post by EduardoAguilar »

Hi Kristoffer

for example if i want to put

Code: Select all

static float kp_z = 0;
on mellinger controller how can i do this modification?
with stock firmware ?
or
using crazyflie-firmware and then upload the changes to crazyflie?

I forget to say that also i tray to use mellinger controller without modifications on the 3 files, i just download the packages and then did the config.mk
and i ran some example script on python IDE, but the crazyflie didn't make the task.
kristoffer
Bitcraze
Posts: 630
Joined: Tue Jun 30, 2015 7:47 am

Re: Mellinger controller on Python

Post by kristoffer »

Thanks for the description!

I have added some documentation about the mechanisms for selecting estimator and controller, https://www.bitcraze.io/documentation/r ... ontroller/.

The kalman estimator will be used automatically since you use a Flow deck, so forcing it in the make file is not necessary, but should do no harm.
The Mellinger controller can be either set through a parameter from a script, or at compile time using a flag. It can be done in the make file, like you did, but it is perhaps more convenient to do it in the config.mk file. I also some documentation on how to set compile flags, https://www.bitcraze.io/documentation/r ... ure_build/.

It should not be necessary to modify cf2.mk and tag.mk, your changes can go into Makefile or config.mk. (tag.mk is only used for the Roadrunner)

Anyway, since the console log says you are using kalman + mellinger, that seems to have worked out.
But i have a question why my Crazyflie didn't make anything when i used crazyflie-firmware?
I forget to say that also i tray to use mellinger controller without modifications on the 3 files, i just download the packages and then did the config.mk
and i ran some example script on python IDE, but the crazyflie didn't make the task.
Yes, that is strange. If you have a clean repository, build and flash you should get the same thing as the latest release.
Just to make sure, I added some more documentation on how to flash the newly built binary https://www.bitcraze.io/documentation/r ... /flashing/

I think you should make sure you get the firmware (without any modifications) working first, before you add your own controller. When that is working, you can add your own controller. It is fairly easy to add your controller in parallel with the other controllers, and that way you can switch between controllers.
EduardoAguilar
Beginner
Posts: 27
Joined: Tue May 05, 2020 2:05 am

Re: Mellinger controller on Python

Post by EduardoAguilar »

HI Kristtofer

thank you for your answer, really, the information is perfect.

i checked that all it's ok with the firmware and i did some proofs with my crazyflie,
with cflib, crazyswarm using optitrack and with cfclient.

I try to did a modification to
mellinger controller but when i try to do this
The Mellinger controller can be either set through a parameter from a script, or at compile time using a flag. It can be done in the make file, like you did, but it is perhaps more convenient to do it in the config.mk file. I also some documentation on how to set compile flags, https://www.bitcraze.io/documentation/r ... ure_build/.
i have the next message on my terminal

Code: Select all

eduardo@eduardo-Aspire-V3-574:~/crazyflie-firmware$ make DEBUG=1
  CLEAN_VERSION
  VTMPL version.c
  CC    version.o
  LD    cf2.elf
  COPY  cf2.hex
  COPY  cf2.bin
  DFUse cf2.dfu
Build for the CF2 platform!
Build 2:908c373bdea4 (2020.04 +2) MODIFIED
Version extracted from git
   text	   data	    bss	    dec	    hex	filename
 362528	   5984	 110544	 479056	  74f50	cf2.elf
eduardo@eduardo-Aspire-V3-574:~/crazyflie-firmware$ make cload
Only cload build can be bootloaded. Launch build and cload with CLOAD=1
if I mofied the config.mk

Code: Select all

PLATFORM=CF2
DEBUG=1
CLOAD=1
and all it's okay.



To create my controller, I just add a line with my file name in the same folders as the others controllers files?
or how can I add my controller to the firmware?

I saw some .o files in crazyflie-firmware/bin that I don't know how they are created, could you help me ??

Thank you Kristoffer
Post Reply