Control with UDP

Firmware/software/electronics/mechanics
Post Reply
scamwell
Beginner
Posts: 3
Joined: Thu Aug 13, 2015 2:00 pm

Control with UDP

Post by scamwell »

Hello everyone,

I've been looking for a while to send commands to the crazyflie from simulink. I stumbled across this project:

https://www.youtube.com/watch?v=oKKKeknc3Ek

Which has managed to link up with simulink by sending UDP packets to the crazyflie with commands for thrust, pitch, yaw etc so I know it's possible. I don't really understand much about UDP and how the crazyflie itself would connect via UDP, as far as I understand it must be connected to the internet and have an IP address? If anyone could point me in the right direction to get started that would be much appreciated!

Thanks
whoenig
Expert
Posts: 395
Joined: Mon Oct 27, 2014 2:55 am

Re: Control with UDP

Post by whoenig »

I don't think UDP makes that much sense unless you want to run Matlab on a different machine. I think there are two good approaches:
1. Use ZMQ from Matlab. There seem to be projects on github already (e.g. https://github.com/smcgill3/zeromq-matlab). More information about the ZMQ support in the official cf-client can be found here: https://wiki.bitcraze.io/doc:crazyflie: ... put_device.
2. Call C(++) functions from Matlab. You would need to work on the binding, but there are C++ libraries for the crazyflie already (e.g. https://github.com/fairlight1337/libcflie)
scamwell
Beginner
Posts: 3
Joined: Thu Aug 13, 2015 2:00 pm

Re: Control with UDP

Post by scamwell »

I've done a bit more digging and I think the idea is to use the UDP blocks in simulink to send/receive data to/from a python script (using the CF python library) in real-time. So you have both the simulink model and python script running at the same time communicating with each other via UDP.

My experience with C code is pretty limited at the moment whoenig but thanks for the information. I'll keep this post updated if I make any progress
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Control with UDP

Post by arnaud »

Hi,

ZeroMQ is very similar to UDP in the sense that both program will run independently and ZMQ is optimised to induce as low latency as possible, so if you can use ZMQ from matlab it would be the best as we already have implemented log/param and input drivers for it (and it is documented: https://wiki.bitcraze.io/doc:crazyflie: ... put_device)

As for raw USB, unfortunately there is no implementation. If you want to make one you can add it as an input interface like we did for ZMQ: https://github.com/bitcraze/crazyflie-c ... zmqpull.py. If you know some python it should not be very hard to get a driver working.
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Control with UDP

Post by arnaud »

I have been thinking a bit more about it and I could help you with making a UDP driver, I would really like to solve the matlab issue (we have been asked for how to connect to matlab but we do not use matlab so it is hard for us to really solve the problem).

So I am curious about a couple of things:
- Is UDP commonly used for this kind of application in matlab.
- What format the packet should have? Intuitively I would have used the same JSON as for ZMQ (with a sprintf or fprintf in matlab), would that work?
rshum19
Beginner
Posts: 4
Joined: Thu Jul 30, 2015 10:39 pm

Re: Control with UDP

Post by rshum19 »

Hi whoeining,

I have a simulink "library" that I created from wrapping c++ code. If you are interested let me know and I can share it. I also have a zmq input from matlab working. It's still need some cleaning up but it works very good.

- Roberto
scamwell
Beginner
Posts: 3
Joined: Thu Aug 13, 2015 2:00 pm

Re: Control with UDP

Post by scamwell »

Hi Roberto,

I'd love to see the matlab zmq input script you've got working.
marcus
Bitcraze
Posts: 659
Joined: Mon Jan 28, 2013 7:02 pm
Location: Sweden
Contact:

Re: Control with UDP

Post by marcus »

Glad to hear that it's working. It would be great if you wanted to share your Matlab solution for ZMQ.
meghgopabhat
Beginner
Posts: 1
Joined: Wed Nov 04, 2015 8:21 am

Control with UDP

Post by meghgopabhat »

Hi guys,

I am trying to communicate my crazyflie with simulink model through UDP.
Can someone please provide the code/model? :(

Any help appreciated.

Thank you,
Meghana
Post Reply