Fixed command frequency

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

Fixed command frequency

Post by zotoli »

Hello again,

On the "Communication with multiple Crazyflies" thread we established the packet send frequency is about 300 Hz. To design a better controller I have to fix this frequency as exact as possible and even 100 - 20 Hz would do. I can't come up with a better idea than timing the send_setpoint function but I am not sure if this is giving me the actual frequency of the signals. If the queue is set to 1 as we previously discussed does it mean that every time I call send_setpoint, it will wait until that packet is sent? If that is the case I can do something simple like this to fix the frequency to 100 Hz:

Code: Select all

    def input_loop(self):
        print "input loop running"
        while (self.done == False):
            tick = time.clock()
            self.crazyflie.commander.send_setpoint(self.roll, self.pitch, self.yawrate, self.thrust)
            time.sleep(0.01 - (time.clock()-tick))
It would be also great to have a way to check if a packet is sent or when it is sent and also if the copter received the packet and when it did so I can time the latency and all that stuff. Anyways any help is appreciated, thanks in advance.
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Fixed command frequency

Post by arnaud »

The send_packet function will return immediately unless the queue is full (so, if one packet is already waiting to be sent). However timing the commander loop is the way to go.

As for knowing if the packet has been sent and received, this is known at low level: upload to the copter is safe because we receive an ack radio packet for every sent packet. And the ack is sent by the copter only if the CRC matches. So when, at the USB dongle interface, a packet is ack-ed it is "for sure" arrived and processed in the copter. Unfortunately currently this info is not communicated back to the higher stack.

The way sending packet is currently implemented the question is not if but when a packet is sent. The communication loop will try over and over to send the same packet until RETRYCOUNT_BEFORE_DISCONNECT is reached.

If you want some kind of "delivery notification" the easiest may be to add a callback, or a semaphore, in the CRTPPacket object and to call it around here: https://github.com/bitcraze/crazyflie-c ... er.py#L327 (in this context the variable outPacket is the packet that has just been sent).
Post Reply