Page 1 of 1

Trying to log data while also sending setpoints

Posted: Sat Oct 12, 2013 7:55 pm
by andykee
I'm trying to log quite a bit of data (acc.x, acc.y, acc.z, gyro.x, gyro.y, gyro.z, motor.m1, motor.m2, motor.m3, motor.m4) at at least 10Hz, although preferably more frequently. At the same time, I'm also sending the vehicle setpoints through a script I've written. I'm running in to two issues:
  • 1. I've had to set up multiple log packets to deal with the number of values I'm trying to log to overcome the max log packet size.
  • 2. Ideally I'd like to send the vehicle commands at 10Hz and receive log data at 100Hz, but regardless of the frequency I'm sending commands, I can't receive log packets any faster than 1Hz. Anything faster, and the packets never appear.I could settle for sending commands once a second, but really need to log at at least 10Hz.
Any thoughts on how to deal with this issue? I've trued (unsuccessfully) to increase the logging packet size, and have also increased the radio bandwidth from 250k to 1M with no noticeable impact. I'm now wondering if it would be possible to preload my desired input commands directly onboard the vehicle's firmware, therefore avoiding the need to send any commands and hopefully freeing up the radio bandwidth to receive log packets?

Re: Trying to log data while also sending setpoints

Posted: Mon Oct 14, 2013 11:39 am
by omwdunkley
andykee wrote:I'm trying to log quite a bit of data (acc.x, acc.y, acc.z, gyro.x, gyro.y, gyro.z, motor.m1, motor.m2, motor.m3, motor.m4) at at least 10Hz, although preferably more frequently. At the same time, I'm also sending the vehicle setpoints through a script I've written. I'm running in to two issues:
  • 1. I've had to set up multiple log packets to deal with the number of values I'm trying to log to overcome the max log packet size.
  • 2. Ideally I'd like to send the vehicle commands at 10Hz and receive log data at 100Hz, but regardless of the frequency I'm sending commands, I can't receive log packets any faster than 1Hz. Anything faster, and the packets never appear.I could settle for sending commands once a second, but really need to log at at least 10Hz.
Any thoughts on how to deal with this issue? I've trued (unsuccessfully) to increase the logging packet size, and have also increased the radio bandwidth from 250k to 1M with no noticeable impact. I'm now wondering if it would be possible to preload my desired input commands directly onboard the vehicle's firmware, therefore avoiding the need to send any commands and hopefully freeing up the radio bandwidth to receive log packets?
Hi!
Thats strange - I am not sure whats happening!
What you want is def possible. Ive successfully sent a lot more at 100hz while controlling the flie. At some point you log to much and it starts dropping packages.
I use 2M, not tried any thing less.

How are you sending the commands?

Re: Trying to log data while also sending setpoints

Posted: Mon Oct 14, 2013 12:48 pm
by marco.tognon
Hallo!!
I want to understand the maximun performance of the link too, and how to reach it!
I mean how many variables could be sent in the same package? What's the maximun rate? And in this condition what is the maximun rate of the set point request??

Re: Trying to log data while also sending setpoints

Posted: Mon Oct 14, 2013 5:52 pm
by tobias
In the master thesis we where involved in there are some good information about the link and bandwidth.

The packet rate is currently limited by the USB which is 1000 packets/second. Each packet is max 32 bytes data so 32k/s is the current limit. We have not tested high speed logging that much so there might be some bugs there...

Re: Trying to log data while also sending setpoints

Posted: Tue Oct 15, 2013 7:24 am
by marco.tognon
tobias wrote:In the master thesis we where involved in there are some good information about the link and bandwidth.

The packet rate is currently limited by the USB which is 1000 packets/second. Each packet is max 32 bytes data so 32k/s is the current limit. We have not tested high speed logging that much so there might be some bugs there...
Thanks a lot tobias.

Re: Trying to log data while also sending setpoints

Posted: Tue Oct 15, 2013 4:10 pm
by andykee
Great, thanks for the info! For what it's worth, I seem to have resolved my initial logging issue by separating the command and logging calls in to their own threads. I think I may have been running in to a race condition trying to log before/while the setpoint was being sent. Without any additional optimization work, I'm now able to send 250 packets/second (combination of Tx and Rx). Not quite 1000, but should be fast enough for my needs at this point.

Re: Trying to log data while also sending setpoints

Posted: Wed Oct 16, 2013 7:10 am
by marco.tognon
andykee wrote:Great, thanks for the info! For what it's worth, I seem to have resolved my initial logging issue by separating the command and logging calls in to their own threads. I think I may have been running in to a race condition trying to log before/while the setpoint was being sent. Without any additional optimization work, I'm now able to send 250 packets/second (combination of Tx and Rx). Not quite 1000, but should be fast enough for my needs at this point.
could we know what you did exactly?

Re: Trying to log data while also sending setpoints

Posted: Wed Oct 16, 2013 8:34 pm
by andykee
Basically, after the connectSetupFinished callback is called, I create a log file and start a thread for each log I'm building. In this case I have three: motor, accelerometer, and gyro:

Code: Select all

Thread(target = self.motor_log).start()
Thread(target = self.acc_log).start()
Thread(target = self.gyro_log).start()
Each thread calls a function which sets up the log config and starts logging. The accelerometer function looks like this:

Code: Select all

def acc_log(self):
        acc_log_file = open(self.acc_log_filename, 'wb')
        self.acc_writer = csv.writer(acc_log_file)
        self.acc_writer.writerow(['time','acc.x','acc.y','acc.z'])

        acc_log_config = LogConfig('acc', 1000/log_freq)
        acc_log_config.addVariable(LogVariable('acc.x', 'float'))
        acc_log_config.addVariable(LogVariable('acc.y', 'float'))
        acc_log_config.addVariable(LogVariable('acc.z', 'float'))

        self.acc_log = self.crazyflie.log.create_log_packet(acc_log_config)
        if (self.acc_log is not None):
            self.acc_log.data_received.add_callback(self.acc_data)
            self.acc_log.error.add_callback(self.logging_error)
            self.acc_log.start()
        else:
            logger.warning("Could not setup logconfiguration after connection!")
    def acc_data(self, data):
        self.acc_writer.writerow([time.time(), data['acc.x'], data['acc.y'], data['acc.z']])
The other functions have the same format but obviously log different variables.

After logging is running, I start yet another thread for the vehicle commands depending on which flight profile I'm using:

Code: Select all

if args.thrust_profile == 'increasing_step':
            Thread(target=self.increasing_step).start()
        if args.thrust_profile == 'hover':
            Thread(target=self.hover).start()
        if args.thrust_profile == 'prbs':
            Thread(target=self.prbs).start()
My full source code is here: https://github.com/andykee/uclathesis/t ... est_flight