I am running a collision avoidance algorithm on the drones that I have and I would like to plot the flight trajectory of each drone.
To this purpose I am trying to log the position of each drone during the flight.
I am using the following script for flight control:
Code: Select all
# imports and other data above...
lg_vars = {
'drone.id' : 'int32_t',
'drone.posX': 'float',
'drone.posY': 'float',
'drone.posZ': 'float',
}
if __name__ == '__main__':
cflib.crtp.init_drivers(enable_debug_driver=False) # initialize drivers
factory = CachedCfFactory(rw_cache='./cache')
with Swarm(uris, factory=factory) as swarm:
lgr = l_and_p.LogAndParam('Position', lg_vars, 100, swarm)
swarm.parallel(lgr.simple_log_async)
# more code below...
Code: Select all
# more code above...
class LogAndParam:
def __init__(self, name_conf, vars, prd, swarm = None):
self.num_of_qds = 5
self.lg_stab = LogConfig(name=name_conf, period_in_ms=prd)
self.recordingLstPos = {str(k) : [] for k in range(0, self.num_of_qds)}
for key in vars:
self.lg_stab.add_variable(key, vars[key])
def log_stab_callback(self, timestamp, data ,logconf):
kys = np.array(list(data.keys()))
self.recordingLstPos[str(data['drone.id'])].append( [ float(data[ kys[1] ]), float(data[ kys[2] ]), float(data[ kys[3] ]) ] )
def simple_log_async(self, scf):
cf = scf.cf
cf.log.add_config(self.lg_stab)
self.lg_stab.data_received_cb.add_callback(self.log_stab_callback)
self.lg_stab.start()
time.sleep(0.1)
# more code below...
Thanks