Communication with multiple Crazyflies

Firmware/software/electronics
zotoli
Beginner
Posts: 3
Joined: Mon Apr 07, 2014 3:56 am

Re: Communication with multiple Crazyflies

Post by zotoli » Mon Apr 07, 2014 4:30 am

Hi All,

First of all thank you very much for the multilink branch. I am working on the same project with cookednoodle and I just had the chance to implement the multilink. I am able to send commands to multiple crazyflies with both a single radio and multiple radios. However I think I am having some latency issues because my original controller that was set up for a single copter is not working properly with the new code.

Story time: Previously I built up on some example code fetched from somewhere in the forums. It has the server and client setup where the server opens the link to the quad and listens to the client. The client gets the position data from the vicon motion tracking system, filters and estimates stuff and produces a control input, sends it to the server which in turn is sends it to the crazyflie.

The server input loop looks like this:

Code: Select all

    def input_loop(self):
        while True:
            data, peer_addr = self.socket.recvfrom(4096)

            if self.peer_addr != peer_addr:
                print "Connected to %s:%d" % peer_addr

            self.peer_addr = peer_addr
            self.last_peer_time = time.time()

            try:
                input = json.loads(data)
            except ValueError:
                input = {}


            okay = False

            if 'point' in input:
                okay = True
                point = input['point']
                try:
                    tick = time.clock()
                    self.crazyflie.commander.send_setpoint(
                        point['roll'],
                        point['pitch'],
                        point['yaw'],
                        point['thrust']
                    )
                    tock = time.clock()
                    print 1/(tock-tick)
                except:
                    self.send_data({'debug': 'error processing point data'})

            if 'ping' in input:
                okay = True
                self.send_data({'pong': input['ping']})

            if not okay:
                self.send_data({'debug': 'no recognised commands'})

        self.crazyflie.commander.send_setpoint(0, 0, 0, 0)
        time.sleep(0.1)
        self.crazyflie.close_link()
Now that we are controlling multiple crazys I want to move everything to the server and get rid of the client. The estimation and controller algorithms are exactly the same and they run on a separate thread. The input loop is also simplified quite a bit which I thought would speed up the things and looks like this:

Code: Select all

    def input_loop(self):
        print "input loop running"
        while (self.done == False):
            self.crazyflie.commander.send_setpoint(self.roll, self.pitch, self.yawrate, self.thrust)
This messes up the controller quite a bit and the send_setpoint function runs slower at about 300 Hz on average. My question is how does the send_packet function handles the overload of commands? I tried looking into it and got lost after I reached the drivers. From my understanding, in the case of a command signal, it doesn't wait for a packet return from the quad. Is it a good idea to run it in a loop like this without a frequency correction like adding a sleep function? Also python is not very efficient in handling threads so maybe that is slowing it down but I am not sure on this.

Using the old server I was able to fly one quad in closed loop successfully and give step inputs to the other using 2 radios. I tried the same thing using only one radio and the resulting crash was painful to watch. It seems we became attached to these little guys.

Sorry for the long post, any help is appreciated and thanks again for the implementation.



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

Re: Communication with multiple Crazyflies

Post by arnaud » Mon Apr 07, 2014 6:17 pm

Hi,

There is some buffering possible if you send packets too fast. In the radio link driver this queue will contains up to 50 packets: https://github.com/bitcraze/crazyflie-c ... er.py#L139

You can try to set the queue length to 1 to see if it solves your latency problems.

300Hz sounds about right to me, the limitation is caused by the way the channel is set in the radio: it is using a kind of USB message that takes 2ms to complete. plus 1ms for the actual packet it takes minimum 3ms to send one packet, hence the 300Hz. I actually find that quite fast (I would have expected even less, something like 150Hz). I plan to enhance the USB protocol at some point to fix that (by concatenating all commands/data in the same USB packet), then the limit will be air-time available.

zotoli
Beginner
Posts: 3
Joined: Mon Apr 07, 2014 3:56 am

Re: Communication with multiple Crazyflies

Post by zotoli » Mon Apr 14, 2014 10:12 pm

Just wanted to give an update, setting the queue to 1 worked and I had 2 of them flying closed loop on the same radio and they were quite stable. We will be ordering new ones and I will see what is the ideal number per radio. I think we are close to having a swarm of these guys flying. Thanks again for your help.

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

Re: Communication with multiple Crazyflies

Post by arnaud » Thu Apr 17, 2014 9:00 am

Sounds great! I will be updating the radio to make it more efficient with multiple copter. I will post a message in this thread when I have something that works.

adadawuhehe
Beginner
Posts: 8
Joined: Sun Oct 20, 2013 11:19 am

Re: Communication with multiple Crazyflies

Post by adadawuhehe » Thu Jun 05, 2014 9:37 am

Hi,

Kind of repeating stuff, probably I miss out something, appreciate any helps thanks.
I have two dongle as well as two crazyflies. My intention is one dongle for one crazyflie.
So, I set the links as:

quad0= //0/30/2M
quad1= //1/35/2M

And, I have tried this up with multiramp.py taken from https://github.com/bitcraze/crazyflie-c ... _multilink

Code: Select all

# Current implementation (as of Crazyradio 0.52) will divide the available
# bandwidth by 3 if used in that way so go easy on the log messages ;-)
# Future Crazyradio firmware will make that a bit more efficient
Main("radio://0/30/2M")
time.sleep(4)
Main("radio://1/35/2M")
Two dongles are working fine but the problem is I have to wait for the first radio://0/30/2M" to settle down first before the second radio://1/35/2M may have a chance to be get executed. If I change the time.sleep to a shorter period, the first radio don't have a chance to be get executed. Is there any way that I can start/ramp the crazyflie simultaneously and independently. Thanks, looking forward to reply.


EDIT: Just to add on, I found out that there is a way to change the VID/PID of the dongle, may I know is there possible to do so such that the driver will handle two dongle connected to my computer separately, eg. each new PID for each dongle?

adadawuhehe
Beginner
Posts: 8
Joined: Sun Oct 20, 2013 11:19 am

Re: Communication with multiple Crazyflies

Post by adadawuhehe » Fri Jun 06, 2014 9:29 am

adadawuhehe wrote:Hi,

Kind of repeating stuff, probably I miss out something, appreciate any helps thanks.
I have two dongle as well as two crazyflies. My intention is one dongle for one crazyflie.
So, I set the links as:

quad0= //0/30/2M
quad1= //1/35/2M

And, I have tried this up with multiramp.py taken from https://github.com/bitcraze/crazyflie-c ... _multilink

Code: Select all

# Current implementation (as of Crazyradio 0.52) will divide the available
# bandwidth by 3 if used in that way so go easy on the log messages ;-)
# Future Crazyradio firmware will make that a bit more efficient
Main("radio://0/30/2M")
time.sleep(4)
Main("radio://1/35/2M")
Two dongles are working fine but the problem is I have to wait for the first radio://0/30/2M" to settle down first before the second radio://1/35/2M may have a chance to be get executed. If I change the time.sleep to a shorter period, the first radio don't have a chance to be get executed. Is there any way that I can start/ramp the crazyflie simultaneously and independently. Thanks, looking forward to reply.


EDIT: Just to add on, I found out that there is a way to change the VID/PID of the dongle, may I know is there possible to do so such that the driver will handle two dongle connected to my computer separately, eg. each new PID for each dongle?

So sorry for my ignorance, I had solved this issue. The problem lies on I din't replace my old cflib from the path 'python27>site packages' with the new cflib from the source of multilink https://github.com/bitcraze/crazyflie-c ... _multilink. Thanks :mrgreen:

omwdunkley
Expert
Posts: 162
Joined: Thu Jun 06, 2013 9:56 pm
Location: Munich

Re: Communication with multiple Crazyflies

Post by omwdunkley » Sat Jun 21, 2014 7:39 am

Any updates here? Sounds interesting :)

formica
Beginner
Posts: 11
Joined: Tue Apr 28, 2015 2:30 pm

Re: Communication with multiple Crazyflies

Post by formica » Tue Apr 28, 2015 2:43 pm

Hi all. I'm a CrazyFlie newbie.
My research project aims to control a group of crazyflies.

I have some questions about:
1) Can I control different crazyflies with one dongle? If yes, what I have to use?
I must set different addresses for each quad? If yes, how can I do it?
Is the radio uri (radio://1//2//3) referred to the dongle, to the copter or to the available "radio channels"?

2) Does anybody know if it is possible to make a mesh network among different CFs using the internal radio?
My goal is to have a first communication channel between dongle and CF to communicate only the position (measured with a Motion Capture) and a second communication channel among the quads. Is it possible to implement this using the Nordic radio onboard?

Regards
Roberto

chad
Expert
Posts: 555
Joined: Sun Sep 28, 2014 12:54 am
Location: New York, USA
Contact:

Re: Communication with multiple Crazyflies

Post by chad » Tue Apr 28, 2015 3:36 pm

Hi Roberto! Welcome to the forum. You may benefit from a read of Wolfgang Hoenig's (whoenig) recent guest blog post... Sounds a lot like what you're doing.
Crazyflier - my CF journal...
4x Crazyflie Nano (1.0) 10-DOF + NeoPixel Ring mod.
3x Crazyflie 2.0 + Qi Charger and LED Decks.
Raspberry Pi Ground Control.
Mac OS X Dev Environment.
Walkera Devo7e, ESky ET6I, PS3 and iOS Controllers.

formica
Beginner
Posts: 11
Joined: Tue Apr 28, 2015 2:30 pm

Re: Communication with multiple Crazyflies

Post by formica » Wed Apr 29, 2015 11:07 am

Thanks Chad. AWESOME!

I didn't still understand if I have to compile and flash on the CFs the latest version of the firmware to use the addressing feature explained in the blog's post.
Any Idea?

Is it specifically needed to re-program the nrf51?

Post Reply