Page 2 of 3

Re: Communication with multiple Crazyflies

Posted: Mon Apr 07, 2014 4:30 am
by zotoli
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.

Re: Communication with multiple Crazyflies

Posted: Mon Apr 07, 2014 6:17 pm
by arnaud
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.

Re: Communication with multiple Crazyflies

Posted: Mon Apr 14, 2014 10:12 pm
by zotoli
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.

Re: Communication with multiple Crazyflies

Posted: Thu Apr 17, 2014 9:00 am
by arnaud
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.

Re: Communication with multiple Crazyflies

Posted: Thu Jun 05, 2014 9:37 am
by adadawuhehe
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?

Re: Communication with multiple Crazyflies

Posted: Fri Jun 06, 2014 9:29 am
by adadawuhehe
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:

Re: Communication with multiple Crazyflies

Posted: Sat Jun 21, 2014 7:39 am
by omwdunkley
Any updates here? Sounds interesting :)

Re: Communication with multiple Crazyflies

Posted: Tue Apr 28, 2015 2:43 pm
by formica
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

Re: Communication with multiple Crazyflies

Posted: Tue Apr 28, 2015 3:36 pm
by chad
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.

Re: Communication with multiple Crazyflies

Posted: Wed Apr 29, 2015 11:07 am
by formica
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?