I have successfully completed the task of automatic swarm flight using the swarmSequence.py, but now I want to print the crazyflie's position.
I tried to change the code, but still failed.Here is the code I added
Code: Select all
def position_callback(timestamp, data, logconf):
x = data['kalman.stateX']
y = data['kalman.stateY']
z = data['kalman.stateZ']
print('pos: ({},{},{})'.format(x, y, z))
with open('/home/gabriela/Área de Trabalho/Gabriel' +datetime.datetime.now().strftime('%Y-%m-%d-%H_')+'Callback_position.csv', 'a') as cvsfile:
writer = csv.writer(csvfile,delimiter=',')
writer.writerow([x, y, z, timestamp])
csvfile.close()
def start_position_printing(scf):
log_conf = LogConfig(name='Position', period_in_ms=50)
log_conf.add_variable('kalman.stateX', 'float')
log_conf.add_variable('kalman.stateY', 'float')
log_conf.add_variable('kalman.stateZ', 'float')
scf.cf.log.add_config(log_conf)
log_conf.data_received_cb.add_callback(position_callback)
log_conf.start()
This is definitely wrong, someone can help me?I think a lot of people need this function.
thanks!