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 » Thu Aug 13, 2015 2:20 pm

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: 310
Joined: Mon Oct 27, 2014 2:55 am

Re: Control with UDP

Post by whoenig » Thu Aug 13, 2015 7:41 pm

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 » Fri Aug 14, 2015 8:08 am

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: 2024
Joined: Tue Feb 06, 2007 12:36 pm

Re: Control with UDP

Post by arnaud » Wed Aug 26, 2015 6:22 pm

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: 2024
Joined: Tue Feb 06, 2007 12:36 pm

Re: Control with UDP

Post by arnaud » Thu Aug 27, 2015 8:54 am

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 » Sat Sep 12, 2015 7:23 pm

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 » Wed Sep 16, 2015 2:24 pm

Hi Roberto,

I'd love to see the matlab zmq input script you've got working.

marcus
Bitcraze
Posts: 599
Joined: Mon Jan 28, 2013 7:02 pm
Location: Sweden
Contact:

Re: Control with UDP

Post by marcus » Thu Sep 17, 2015 9:02 am

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 » Wed Nov 04, 2015 4:39 pm

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