Re: Communication with multiple Crazyflies
Posted: 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:
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:
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.
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()
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)
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.