Logging

Data logging in background

Once the drone is connected, it is possible ot automatically record some or all the data (sensor & control values) using the start_data_logging() method. The file name is a manadatory parameter. Additionnaly, you may specify the sampling tile using the sampling_time parameter. The list of sensor to be recorded using the sensor_list parameter and must contains a list of sensor name. You can get the list of available sensor with the meth:~tello_ctrl.tello_ctrl.get_sensor_list method. The list of available data is discussed here : Available sensors and controls. The optional mode parameter allows to specify wether data should be added to an existing file (mode=”a”) or the file shoule be be over written (mode=”w”).

The data are logged in a CSV file where each column is separated using the “;” character.

You must stop the recording using the stop_data_logging() method.

The following code illustrate how to record the data at 10Hz.

from tello_ctrl import *
import time

drone = tello_ctrl()
drone.connect()

# Start logging all the data at 10Hz
drone.start_data_logging('test1.log', sampling_time=0.1)

# Do whatever is needed with the drone
drone.takeoff()
time.sleep(0)
drone.land()

# Stop data logging
drone.stop_data_logging()

# Clean up
drone.quit()

Alternatively, you may want to only record a subset of the data. Here is how to record only the position data at 3Hz.

from tello_ctrl import *
import time

drone = tello_ctrl()
drone.connect()

# Start logging all the data at 3Hz
drone.start_data_logging('test1.log', sensor_list=['posX','posY','posZ'], sampling_time=1/3)

# Do whatever is needed with the drone
drone.takeoff()
time.sleep(0)
drone.land()

# Stop data logging
drone.stop_data_logging()

# Clean up
drone.quit()

Logging tello_ctrl messages in background

Levels

For debugging purpose, you may want to log the internal messages send by the tello_ctrl object. There are four main levels of messages :

  • “ERROR” : messages indicating that something went bad

  • “WARNING” : messages indicating something unexpected, but not an error, occured

  • “INFO” : messages indicating that a method has been exectuted as expected

  • “DEBUG” : messages that allows tracing the internal behavior of the code. There may be a lot of these messages, especially when datalogging or video recording is ongoing

Console logger

When creating a tello_ctrl object, a console logger is automatically created to log the error. You do not have to create it yourself. You may then change its level using the following code:

drone.set_log_level("console","INFO")

If you want you can remove the console logger with the remove_console_logger() method. You can then later add a new console logger with add_console_logger(). Note that you can only have a single console logger, but it can work concurently with a file logger.

File logger

The file logger works similarly to the console logger, execept that the messages are logged into the specified file. You can add a file logger using the add_file_logger() method. It expect the file name as a mandatory parameter. It has optional parameters : level and mode. When using mode=”w”, if the file exists, it is overwritten, when using mode=”a”, data are appended to the file (if it already exist).

You can change the file logger level with drone.set_log_level(“file”, level). You can remove the file logger with the remove_file_logger() method. You are not obliged to remove the logger at the end of the program. Note that you can only have a single file logger, but it can work concurently with a console logger.

The following code demonstrate how to use the file logger.

from tello_ctrl import *
import time

drone = tello_ctrl()

# Add a file logger
drone.add_file_logger('logfile.txt',mode='w',level="DEBUG")

drone.connect()

# Do whatever is needed with the drone
drone.takeoff()
time.sleep(0)

# Change the logger level for the landing
drone.set_log_level('file',level="ERROR")

# Land
drone.land()

# Clean up
drone.quit()