Skip to content
Snippets Groups Projects
Commit ae9599eb authored by 488_MP-4's avatar 488_MP-4
Browse files

created LogfileHandler class

parent 14671622
No related branches found
No related tags found
5 merge requests!106Adding Pycrocart 2.1,!104adding cflib to this branch,!103Updating develop to current state of master branch,!98Pycrocart 2.1 will,!94Merge cflib adapter into main
from datetime import datetime
from email.utils import localtime
from time import time
from typing import List
import time
import struct
import cflib.crtp
from cflib.crazyflie import Crazyflie
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
from queue import Queue
#import groundstation_socket as gs
import uCartCommander
from groundstation_socket import MessageTypeID
from SetpointHandler import SetpointHandler, FlightMode
from cflib.crazyflie.log import LogConfig
import numpy as np
class LogfileHandler:
"""
Handles all interactions with cflib.
"""
def __init__(self):
"""
Initialize the start time, the logging queue which is given to the
plotting window, and set the synchronous crazyflie connection by
default to None. This should be set to the crazyflie when connecting
to one.
"""
# Get the start time, so that the timestamp returned to the user will
# be in seconds since startup.
self.start_time = time.time()
# self.logging_queue = Queue()
self.scf = None
self.is_connected = False
self.param_callback_count = 0
self.logging_configs = []
def add_log_config(self, name: str, period: int, variables: List[str]):
""" Add a logging config. Used from logging tab when refreshing
logging variables. Add callback to route logged data to logging
queue. """
print("Name: " + name + ", period: " + str(period) + ", variables: "
+ str(variables))
logging_group = LogConfig(name=name, period_in_ms=period)
for variable in variables:
logging_group.add_variable(variable, 'float')
self.logging_configs.append(logging_group)
self.logging_configs[-1].data_received_cb.add_callback(
self.logging_callback)
self.scf.cf.log.add_config(self.logging_configs[-1])
def refresh_logging_configs() :
raise Exception
def load_logging_configs() :
raise Exception
def clear_logging_configs(self):
""" Stop logging and clear configuration. Used when refreshing
logging to stop anything that has configured to be logged from
logging. """
self.stop_logging()
self.logging_configs = []
# done refreshing toc is a callback function that is triggered when
# refresh toc is done executing.
self.scf.cf.log.refresh_toc(
self.done_refreshing_toc, self.scf.cf.log._toc_cache)
# Blocks until toc is done refreshing.
while self.param_callback_count < 1:
time.sleep(0.01)
self.param_callback_count = 0
# grabs new toc values
self.scf.wait_for_params()
def resume_logging_configs():
raise Exception
def pause_logging_configs():
raise Exception
def enable_logging(self):
""" Begins logging all configured logging blocks. This is used from
the controls tab when hitting begin logging. """
for i in range(0, len(self.logging_configs)):
self.logging_configs[i].start()
def disable_logging(self):
""" Stops logging all configured logging blocks. This is used from
the controls tab when hitting pause logging. """
for i in range(0, len(self.logging_configs)):
self.logging_configs[i].stop()
...@@ -304,56 +304,3 @@ class CrazyflieConnection: ...@@ -304,56 +304,3 @@ class CrazyflieConnection:
file.close() file.close()
return filename return filename
def add_log_config(self, name: str, period: int, variables: List[str]):
""" Add a logging config. Used from logging tab when refreshing
logging variables. Add callback to route logged data to logging
queue. """
print("Name: " + name + ", period: " + str(period) + ", variables: "
+ str(variables))
logging_group = LogConfig(name=name, period_in_ms=period)
for variable in variables:
logging_group.add_variable(variable, 'float')
self.logging_configs.append(logging_group)
self.logging_configs[-1].data_received_cb.add_callback(
self.logging_callback)
self.scf.cf.log.add_config(self.logging_configs[-1])
def clear_logging_configs(self):
""" Stop logging and clear configuration. Used when refreshing
logging to stop anything that has configured to be logged from
logging. """
self.stop_logging()
self.logging_configs = []
# done refreshing toc is a callback function that is triggered when
# refresh toc is done executing.
self.scf.cf.log.refresh_toc(
self.done_refreshing_toc, self.scf.cf.log._toc_cache)
# Blocks until toc is done refreshing.
while self.param_callback_count < 1:
time.sleep(0.01)
self.param_callback_count = 0
# grabs new toc values
self.scf.wait_for_params()
def done_refreshing_toc(self, *_args):
""" Callback for flow control, increments param callback count to
allow exit of while loop. """
self.param_callback_count = 1
def start_logging(self):
""" Begins logging all configured logging blocks. This is used from
the controls tab when hitting begin logging. """
for i in range(0, len(self.logging_configs)):
self.logging_configs[i].start()
def stop_logging(self):
""" Stops logging all configured logging blocks. This is used from
the controls tab when hitting pause logging. """
for i in range(0, len(self.logging_configs)):
self.logging_configs[i].stop()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment