本文整理汇总了Python中cflib.crazyflie.log.LogConfig类的典型用法代码示例。如果您正苦于以下问题:Python LogConfig类的具体用法?Python LogConfig怎么用?Python LogConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LogConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start
def start(self, cf):
self._lc_stab = LogConfig(name="Log-Stab", period_in_ms=50)
self._lc_stab.add_variable("stabilizer.roll", "float")
self._lc_stab.add_variable("stabilizer.pitch", "float")
self._lc_stab.add_variable("stabilizer.yaw", "float")
self._lc_stab.add_variable("stabilizer.thrust", "float")
self._lc_motor = LogConfig(name="Log-Motor", period_in_ms=50)
self._lc_motor.add_variable("pm.vbat", "float")
self._lc_motor.add_variable("motor.m1", "float") # Front (green)
self._lc_motor.add_variable("motor.m2", "float") # Right
self._lc_motor.add_variable("motor.m3", "float") # Back (red)
self._lc_motor.add_variable("motor.m4", "float") # Left
cf.log.add_config(self._lc_stab)
cf.log.add_config(self._lc_motor)
if self._lc_stab.valid and self._lc_motor.valid:
self._lc_stab.data_received_cb.add_callback(self._log_data)
self._lc_stab.error_cb.add_callback(self._log_error)
self._lc_stab.start()
self._lc_motor.data_received_cb.add_callback(self._log_data)
self._lc_motor.error_cb.add_callback(self._log_error)
self._lc_motor.start()
logger.info("Starting CFLog")
else:
logger.error("Could not add logconfig since some variables are not in TOC")
示例2: _read_config_files
def _read_config_files(self):
"""Read and parse log configurations"""
configsfound = [os.path.basename(f) for f in
glob.glob(sys.path[1] + "/log/[A-Za-z_-]*.json")]
new_dsList = []
for conf in configsfound:
try:
logger.info("Parsing [%s]", conf)
json_data = open(sys.path[1] + "/log/%s" % conf)
self.data = json.load(json_data)
infoNode = self.data["logconfig"]["logblock"]
logConf = LogConfig(infoNode["name"],
int(infoNode["period"]))
for v in self.data["logconfig"]["logblock"]["variables"]:
if v["type"] == "TOC":
logConf.add_variable(str(v["name"]), v["fetch_as"])
else:
logConf.add_variable("Mem", v["fetch_as"],
v["stored_as"],
int(v["address"], 16))
new_dsList.append(logConf)
json_data.close()
except Exception as e:
logger.warning("Exception while parsing logconfig file: %s", e)
self.dsList = new_dsList
示例3: _handle_logging
def _handle_logging(self, data):
resp = {"version": 1}
if data["action"] == "create":
lg = LogConfig(data["name"], data["period"])
for v in data["variables"]:
lg.add_variable(v)
lg.started_cb.add_callback(self._logging_started)
lg.added_cb.add_callback(self._logging_added)
try:
lg.data_received_cb.add_callback(self._logdata_callback)
self._logging_configs[data["name"]] = lg
self._cf.log.add_config(lg)
lg.create()
self._log_added_queue.get(block=True, timeout=LOG_TIMEOUT)
resp["status"] = 0
except KeyError as e:
resp["status"] = 1
resp["msg"] = str(e)
except AttributeError as e:
resp["status"] = 2
resp["msg"] = str(e)
except queue.Empty:
resp["status"] = 3
resp["msg"] = "Log configuration did not start"
if data["action"] == "start":
try:
self._logging_configs[data["name"]].start()
self._log_started_queue.get(block=True, timeout=LOG_TIMEOUT)
resp["status"] = 0
except KeyError as e:
resp["status"] = 1
resp["msg"] = "{} config not found".format(str(e))
except queue.Empty:
resp["status"] = 2
resp["msg"] = "Log configuration did not stop"
if data["action"] == "stop":
try:
self._logging_configs[data["name"]].stop()
self._log_started_queue.get(block=True, timeout=LOG_TIMEOUT)
resp["status"] = 0
except KeyError as e:
resp["status"] = 1
resp["msg"] = "{} config not found".format(str(e))
except queue.Empty:
resp["status"] = 2
resp["msg"] = "Log configuration did not stop"
if data["action"] == "delete":
try:
self._logging_configs[data["name"]].delete()
self._log_added_queue.get(block=True, timeout=LOG_TIMEOUT)
resp["status"] = 0
except KeyError as e:
resp["status"] = 1
resp["msg"] = "{} config not found".format(str(e))
except queue.Empty:
resp["status"] = 2
resp["msg"] = "Log configuration did not stop"
return resp
示例4: createConfigFromSelection
def createConfigFromSelection(self):
logconfig = LogConfig(str(self.configNameCombo.currentText()),
self.period)
for node in self.getNodeChildren(self.varTree.invisibleRootItem()):
parentName = node.text(NAME_FIELD)
for leaf in self.getNodeChildren(node):
varName = leaf.text(NAME_FIELD)
varType = str(leaf.text(CTYPE_FIELD))
completeName = "%s.%s" % (parentName, varName)
logconfig.add_variable(completeName, varType)
return logconfig
示例5: _connected
def _connected(self, linkURI):
self._update_ui_state(UIState.CONNECTED, linkURI)
Config().set("link_uri", str(linkURI))
lg = LogConfig("Battery", 1000)
lg.add_variable("pm.vbat", "float")
try:
self.cf.log.add_config(lg)
lg.data_received_cb.add_callback(self.batteryUpdatedSignal.emit)
lg.error_cb.add_callback(self._log_error_signal.emit)
lg.start()
except KeyError as e:
logger.warning(str(e))
示例6: connectionDone
def connectionDone(self, linkURI):
self.setUIState(UIState.CONNECTED, linkURI)
GuiConfig().set("link_uri", linkURI)
lg = LogConfig("Battery", 1000)
lg.add_variable("pm.vbat", "float")
self.cf.log.add_config(lg)
if lg.valid:
lg.data_received_cb.add_callback(self.batteryUpdatedSignal.emit)
lg.error_cb.add_callback(self._log_error_signal.emit)
lg.start()
else:
logger.warning("Could not setup loggingblock!")
示例7: _register_logblock
def _register_logblock(self, logblock_name, variables, data_cb, error_cb,
update_period=UPDATE_PERIOD_LOG):
"""Register log data to listen for. One logblock can contain a limited
number of parameters (6 for floats)."""
lg = LogConfig(logblock_name, update_period)
for variable in variables:
if self._is_in_log_toc(variable):
lg.add_variable('{}.{}'.format(variable[0], variable[1]),
variable[2])
self._helper.cf.log.add_config(lg)
lg.data_received_cb.add_callback(data_cb)
lg.error_cb.add_callback(error_cb)
lg.start()
return lg
示例8: _connected
def _connected(self, link_uri):
lg = LogConfig("GPS", 1000)
lg.add_variable("gps.lat", "float")
lg.add_variable("gps.long", "float")
lg.add_variable("gps.alt", "float")
self._cf.log.add_config(lg)
if lg.valid:
lg.data_received_cb.add_callback(self._log_data_signal.emit)
lg.error_cb.add_callback(self._log_error_signal.emit)
lg.start()
else:
logger.warning("Could not setup logging block for GPS!")
示例9: _connected
def _connected(self, link_uri):
#initial time to be shown in the screen
self.init_time = time.time()
#Threat 1 that will control the quadridrone
Thread(target=self._ramp_motors).start()
#Thread 2 that will show results in the screen
Thread(target=self._show_values).start()
self._lg_stab = LogConfig(name='Stabilizer', period_in_ms=30)
#self._lg_stab.addVariable(LogVariable("stabilizer.thrust", "uint16_t"))
self._lg_stab.add_variable('stabilizer.roll', 'float')
self._lg_stab.add_variable('stabilizer.pitch', 'float')
self._lg_stab.add_variable('stabilizer.yaw', 'float')
self._lg_stab.add_variable('stabilizer.thrust', "uint16_t")
# Adding the configuration cannot be done until a Crazyflie is
# connected, since we need to check that the variables we
# would like to log are in the TOC.
try:
self._cf.log.add_config(self._lg_stab)
# This callback will receive the data
self._lg_stab.data_received_cb.add_callback(self._stab_log_data)
# This callback will be called on errors
self._lg_stab.error_cb.add_callback(self._stab_log_error)
#Thread 3 that will read from the TOC table, and start the logging
self._lg_stab.start()
except KeyError as e:
print('Could not start log configuration, {} not found in TOC'.format(str(e)))
except AttributeError:
print('Could not add Stabilizer log config, bad configuration.')
示例10: makeLog
def makeLog(self):
""" Makes a log. All ative children are added """
#print " -> Making new Log with %d ms interval"
if self.lg:
print " ---> Previous Log detected, removing first"
self.lg.delete()
self.fm = FreqMonitor(window=max(10, int(1.2*float(self.text(2)))))
self.lg = LogConfig(self.name, 1000/int(float(self.text(2))))
#print " ---> Adding children to new log"
for x in range(self.childCount()):
c = self.child(x)
if c.isChecked():
name = c.log.group+"."+c.log.name
self.lg.add_variable(name, c.log.ctype)
#print " --- --> Adding child[%d]: [%s] to new log"%(x, name)
#print " ---> Checking log with TOC"
self.treeWidget().cf.log.add_config(self.lg)
if self.lg.valid:
#print " --- --> PASS"
self.lg.data_received_cb.add_callback(self.logDataCB)
self.lg.started_cb.add_callback(self.logStartedCB)
self.lg.error_cb.add_callback(self.treeWidget().sig_logError.emit)
self.lg.error_cb.add_callback(self.errorLog)
#print " --- --> callbacks added, starting new log NOW"
self.lg.start()
else:
#print " --- --> FAIL"
self.errorLog(None, "Invalid Config")
self.lg = None
示例11: _connected
def _connected(self, link_uri):
""" This callback is called form the Crazyflie API when a Crazyflie
has been connected and the TOCs have been downloaded."""
print "Connected to %s" % link_uri
self._cf.commander.send_setpoint(0, 0, 0, 20000)
# The definition of the logconfig can be made before connecting
self._lg_stab = LogConfig(name="Logger", period_in_ms=10)
self._lg_stab.add_variable("stabilizer.roll", "float")
self._lg_stab.add_variable("stabilizer.pitch", "float")
self._lg_stab.add_variable("stabilizer.yaw", "float")
self._lg_stab.add_variable("stabilizer.thrust", "uint16_t")
self._lg_stab.add_variable("gyro.x", "float")
self._lg_stab.add_variable("gyro.y", "float")
self._lg_stab.add_variable("gyro.z", "float")
# Adding the configuration cannot be done until a Crazyflie is
# connected, since we need to check that the variables we
# would like to log are in the TOC.
self._cf.log.add_config(self._lg_stab)
if self._lg_stab.valid:
# This callback will receive the data
self._lg_stab.data_received_cb.add_callback(self._stab_log_data)
# This callback will be called on errors
self._lg_stab.error_cb.add_callback(self._stab_log_error)
# Start the logging
self._lg_stab.start()
else:
print("Could not add logconfig since some variables are not in TOC")
示例12: _connected
def _connected(self, link_uri):
""" This callback is called form the Crazyflie API when a Crazyflie
has been connected and the TOCs have been downloaded."""
print('Connected to %s' % link_uri)
# The definition of the logconfig can be made before connecting
self._lg_stab = LogConfig(name='Stabilizer', period_in_ms=10)
self._lg_stab.add_variable('stabilizer.roll', 'float')
self._lg_stab.add_variable('stabilizer.pitch', 'float')
self._lg_stab.add_variable('stabilizer.yaw', 'float')
# Adding the configuration cannot be done until a Crazyflie is
# connected, since we need to check that the variables we
# would like to log are in the TOC.
try:
self._cf.log.add_config(self._lg_stab)
# This callback will receive the data
self._lg_stab.data_received_cb.add_callback(self._stab_log_data)
# This callback will be called on errors
self._lg_stab.error_cb.add_callback(self._stab_log_error)
# Start the logging
self._lg_stab.start()
except KeyError as e:
print('Could not start log configuration,'
'{} not found in TOC'.format(str(e)))
except AttributeError:
print('Could not add Stabilizer log config, bad configuration.')
# Start a timer to disconnect in 10s
t = Timer(5, self._cf.close_link)
t.start()
示例13: _connected
def _connected(self, linkURI):
self._update_ui_state(UIState.CONNECTED, linkURI)
Config().set("link_uri", str(linkURI))
lg = LogConfig("Battery", 1000)
lg.add_variable("pm.vbat", "float")
try:
self.cf.log.add_config(lg)
lg.data_received_cb.add_callback(self.batteryUpdatedSignal.emit)
lg.error_cb.add_callback(self._log_error_signal.emit)
lg.start()
except KeyError as e:
logger.warning(str(e))
mem = self.cf.mem.get_mems(MemoryElement.TYPE_DRIVER_LED)[0]
mem.write_data(self._led_write_done)
示例14: __init__
def __init__(self, link_uri):
""" Initialize and run the example with the specified link_uri """
self._cf = Crazyflie()
self._cf.connected.add_callback(self._connected)
self._cf.disconnected.add_callback(self._disconnected)
self._cf.connection_failed.add_callback(self._connection_failed)
self._cf.connection_lost.add_callback(self._connection_lost)
self._lg_stab = LogConfig(name="Logger", period_in_ms=10)
self._lg_stab.add_variable('acc.x', "float")
self._lg_stab.add_variable('acc.y', "float")
self._lg_stab.add_variable('acc.zw', "float")
self._lg_stab.add_variable('gyro.x', "float")
self._lg_stab.add_variable('gyro.y', "float")
self._lg_stab.add_variable('gyro.z', "float")
# PID for Z velocity??
# self._lg_stab.add_variable('acc.z', "float")
# self._lg_stab.add_variable("", "float")
self._cf.open_link(link_uri)
print("Connecting to %s" % link_uri)
self._acc_x = 0.0
self._acc_y = 0.0
self._acc_zw = 0.0
self._gyro_x = 0.0
self._gyro_y = 0.0
self._gyro_z = 0.0
# self._acc_z = 0.0
# self._vel_z = 0.0
# ROLL/PITCH
maxangle = 0.25
kpangle = 2.0
kiangle = 0.0
kdangle = 0.1
self._acc_pid_x = pid.PID(
0, 0, kpangle, kiangle, kdangle, -maxangle, maxangle)
self._acc_pid_y = pid.PID(
0, 0, kpangle, kiangle, kdangle, -maxangle, maxangle)
self._acc_pid_z = pid.PID(0, 0, 10, 0.0005, 0.1, 1/6, 2)
self._gyro_x_pid = pid.PID(
0, 0, kpangle, kiangle, kdangle, -maxangle, maxangle)
self._gyro_y_pid = pid.PID(
0, 0, kpangle, kiangle, kdangle, -maxangle, maxangle)
# self._gyro_z_pid = pid.PID(
# 0, 0, kpangle, kiangle, kdangle, -maxangle, maxangle)
self._is_connected = True
# self._acc_log = []
self.exit = False
示例15: start_position_printing
def start_position_printing(scf):
log_conf = LogConfig(name='Position', period_in_ms=500)
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()