Commands from Simulink to Crazyflie

Post here to get support
Post Reply
die4doby
Beginner
Posts: 6
Joined: Tue Jul 16, 2013 8:31 am

Commands from Simulink to Crazyflie

Post by die4doby »

Hi,

I have a Crazyflie 2.0 and the Loco Positioning System. I am trying to model the drone in Simulink, create some trajectory and send the commands to the drone so that it follows the desired trajectory.

I have been trying to do this for a very long time but I am starting to give up. Many papers related to trajectory planning for Crazyflie but none of them discuss the steps needed to achieve this by using Crazyflie and Loco Positioning System .

What is the best way to send the commands from Simulink to the drone? Should I use ROS to achieve this? Or Python?
What is the best way to read values from the Loco Positioning System into Simulink?

kimberly
Bitcraze
Posts: 470
Joined: Fri Jul 06, 2018 11:13 am

Re: Commands from Simulink to Crazyflie

Post by kimberly »

This has indeed haven't been done before, but shouldn't be impossible. You just need to find a way for the commands to be read out in python, and then send it to the crazyflie through the crazyflie python library. The same the other way around, you will need to get the state estimate of the position from the log variables from the crazyflie (since the crazyflie estimates its position onboard), then you bridge those values from python to matlab to simulink (https://se.mathworks.com/products/matla ... ython.html).

Just in the case that it really doesn't work, you could use Ros in matlab to send the values to the rospackage for the crazyflie, but I would try to avoid that if I where you... last time I tried ROS with matlab it was not great...

You can look at viewtopic.php?f=6&t=4102&p=18899&hilit=matlab#p18899 for pointers on how to connect matlab with the crazyflie firmware, which is using the zmq server. It is pretty high level, but maybe as an inspiration.

Just some general advice: What you want to achieve is pretty challenging and big, which makes it a bit difficult to help you on the forum. What could help you is to try to chop up this problem in smaller chunks and ask advice for each small part.

die4doby
Beginner
Posts: 6
Joined: Tue Jul 16, 2013 8:31 am

Re: Commands from Simulink to Crazyflie

Post by die4doby »

I want to be able to test different control algorithms and I think the best way might be to use Simulink. Below are the different clients for Crazyflie. What are the different possible options to achieve this by using Crazyflie and Loco Positioning System? What are the needed clients to be used to achieve these different options?

- Crazyflie python client: The main graphical client used for flying, logging, bootloading and various other tasks
- Crazyflie command-line bootloader: Used to bootload the Crazyflie from the command line
- Crazyflie headless client: A command line client used for flying. The client doesn't have a UI and is used for the Raspberry Pi image
- Crazyflie iOS client: The iOS client used to pilot the Crazyflie via Bluetooth LE
- Crazyflie Android client: The Android client used to pilot the Crazyflie via Bluetooth LE
- Crazyflie ZMQ server: Server which gives access to the Crazyflie though ZMQ.
Last edited by die4doby on Fri Mar 06, 2020 3:45 pm, edited 2 times in total.

die4doby
Beginner
Posts: 6
Joined: Tue Jul 16, 2013 8:31 am

Re: Commands from Simulink to Crazyflie

Post by die4doby »

kimberly wrote:
Fri Mar 06, 2020 10:36 am
This has indeed haven't been done before, but shouldn't be impossible. You just need to find a way for the commands to be read out in python, and then send it to the crazyflie through the crazyflie python library. The same the other way around, you will need to get the state estimate of the position from the log variables from the crazyflie (since the crazyflie estimates its position onboard), then you bridge those values from python to matlab to simulink (https://se.mathworks.com/products/matla ... ython.html).

Just in the case that it really doesn't work, you could use Ros in matlab to send the values to the rospackage for the crazyflie, but I would try to avoid that if I where you... last time I tried ROS with matlab it was not great...

You can look at viewtopic.php?f=6&t=4102&p=18899&hilit=matlab#p18899 for pointers on how to connect matlab with the crazyflie firmware, which is using the zmq server. It is pretty high level, but maybe as an inspiration.

Just some general advice: What you want to achieve is pretty challenging and big, which makes it a bit difficult to help you on the forum. What could help you is to try to chop up this problem in smaller chunks and ask advice for each small part.
Thanks for your reply.

die4doby
Beginner
Posts: 6
Joined: Tue Jul 16, 2013 8:31 am

Re: Commands from Simulink to Crazyflie

Post by die4doby »

I think if the Crazyflie developers want this drone to be accessible by everyone and not only expert developers and researchers, then a clear step-by-step guide would be really helpful for everyone (like undergrad students, ...etc).

I think I have to give up since I am spending way too much time just thinking about what should be changed in the code in order to enable custom control algorithms. I was really excited about this drone.

tobias
Bitcraze
Posts: 2013
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Commands from Simulink to Crazyflie

Post by tobias »

We agree that the documentation is a bit sparse and this is something we are trying to improve, but our resources are limited.

As we don't have simulink it is also hard for us to develop anything for it. It is a quite expensive package and thus only available to limited audience. Is that then the route to take? Difficult question...

There is a master thesis from M Greiff "Modelling and Control of the Crazyflie Quadrotor for Aggressive and Autonomous Flight by Optical Flow Driven State Estimation, M. Greiff, Master’s thesis, Lund University, 2017" which you can find under publications here. It is a lot of information but describes how Greiff simulated and implemented a controller. Could be one path to try.

keffi
Beginner
Posts: 15
Joined: Mon Feb 25, 2019 10:35 pm

Re: Commands from Simulink to Crazyflie

Post by keffi »

I really understand the wish to be able to develop with Matlab. As control people, we are quite used to develop our stuff with this tool and in an university environment, we usually have some sort of 100% access.

Using the python API to run a low level (stabilizing) controller on a pc which processes logging data and transfers the motor commands to the Crazyflie is very unlikely to work. At least in case your aim is developing a stabilizing inner loop controller due to the required update rates. Some higher level control however should be realizable.

I definitely want to use Matlab/Simulink within the developement process I am trying to establish. There are two possible ways of making use of Matlab/Simulink from my point of view
1) Employing autocode to transfer Matlab code into the crazyflie firmware - it would be interesting to have the right autocode setup here
2) Attach c-code to Matlab/Simulink.

In fact, I am working with my students on the second path, we program our algorithms directly in C but develope our algorithms in Matlab. This is in fact the workflow I am used to from industry. I would be very interested in the first approach, but I decided to go for the second one since I am not sure, how efficient Autocode is in terms of coding efficiency.
Since I want to to do research with this plattform, I have to pass the initial burden (after almost a year now it's getting better but some obstacles still occur here and there... ) but since everything is open/flexible and due to the availability of different decks it seems to be worth it.
Plus, students (also in mechanical engineering) get some clue of C and an Embedded System. And the crazyflie is a very, very effective motivator forcing students to even work theirselves into topics like navigation (I really like what you can show in the context of data fusion).

However, I really hope, that the the community of Crazyflie-interested people using Matlab will be growing, since this would speed up developement and lower the burden for our students to realize their ideas and to use the Crazyflie even in undergraduate teaching. I will encourage my students to make their results open to the public as soon as there is a reasonable achievement.

Post Reply