当前位置: 首页>>代码示例>>Python>>正文


Python LogConfig.stop方法代码示例

本文整理汇总了Python中cflib.crazyflie.log.LogConfig.stop方法的典型用法代码示例。如果您正苦于以下问题:Python LogConfig.stop方法的具体用法?Python LogConfig.stop怎么用?Python LogConfig.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cflib.crazyflie.log.LogConfig的用法示例。


在下文中一共展示了LogConfig.stop方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from cflib.crazyflie.log import LogConfig [as 别名]
# 或者: from cflib.crazyflie.log.LogConfig import stop [as 别名]
class CFLog:
    def __init__(self):
        self.status = CFStatus()

    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")

    def stop(self):
        self._lc_stab.stop()

    def _log_error(self, logconf, msg):
        """Callback from the log API when an error occurs"""
        logger.info("Error when logging %s: %s" % (logconf.name, msg))

    def _log_data(self, timestamp, data, logconf):
        """Callback froma the log API when data arrives"""
        if logconf.name == "Log-Stab":
            self.status.pitch = data["stabilizer.pitch"]
            self.status.roll = data["stabilizer.roll"]
            self.status.yaw = data["stabilizer.yaw"]
            self.status.thrust = data["stabilizer.thrust"]
        else:
            self.status.bat = data["pm.vbat"]
            self.status.motor_1 = data["motor.m1"]
            self.status.motor_2 = data["motor.m2"]
            self.status.motor_3 = data["motor.m3"]
            self.status.motor_4 = data["motor.m4"]

        logger.info("%s" % self.status)
开发者ID:Cyboot,项目名称:Crazyflie,代码行数:55,代码来源:log.py

示例2: __init__

# 需要导入模块: from cflib.crazyflie.log import LogConfig [as 别名]
# 或者: from cflib.crazyflie.log.LogConfig import stop [as 别名]

#.........这里部分代码省略.........
		except Exception as e:
			raise Exception("Couldn't initialize CrazyFlie params to their desired values. Details: {}".format(e.message))

		# Create a log configuration and include all variables that want to be logged
		self.cf_log = LogConfig(name="cf_log", period_in_ms=10)
		self.cf_log.add_variable("stabilizer.roll", "float")
		self.cf_log.add_variable("stabilizer.pitch", "float")
		self.cf_log.add_variable("stabilizer.yaw", "float")
		self.cf_log.add_variable("posEstimatorAlt.estimatedZ", "float")
		self.cf_log.add_variable("posEstimatorAlt.velocityZ", "float")
		try:
			self.crazyflie.log.add_config(self.cf_log)  # Validate the log configuration and attach it to our CF
		except Exception as e:
			raise Exception("Couldn't attach the log config to the CrazyFlie, bad configuration. Details: {}".format(e.message))
		self.cf_log.data_received_cb.add_callback(self.on_cf_log_new_data)  # Register appropriate callbacks
		self.cf_log.error_cb.add_callback(self.on_cf_log_error)
		self.cf_log.start()  # Start logging!

		# Get the CF's initial yaw (should be facing the camera) so we can have PID_yaw maintain that orientation
		if self.ASK_FOR_TARGET_YAW:  # Either ask the user to press Enter to indicate the CF's orientation is ready
			raw_input("\nRotate the drone so it faces the camera, press Enter when you're ready...\n")
		else:  # Or automatically detect the first yaw log packet and set the current orientation as the desired yaw
			while abs(self.cf_yaw) < 0.01:  # Wait until first cf_yaw value is received (cf_yaw=0 by default)
				time.sleep(0.1)
		self.cf_PID_yaw.SetPoint = self.cf_yaw
		print "Target yaw set at {:.2f}.".format(self.cf_yaw)

		self.crazyflie.add_port_callback(CRTPPort.CONSOLE, self.print_cf_console)
		self.crazyflie.commander.send_setpoint(0, 0, 0, 0)  # New firmware version requires to send thrust=0 at least once to "unlock thrust"

	def fly_cf(self):
		"""
		Provides the structure to make the drone fly (actual flight control is done in hover() though).
		hover() is called until user stops the experiment, then hover is called for a few more secs to record more data
		(usually includes information about the CF crashing...)
		:return: Whether or not to keep (store) the logs, based on whether the CF ever actually took off and flew
		"""
		print "Giving you 5s to prepare for take-off..."
		time.sleep(5)

		# t = Timer(20, self.m_CrazyFlie.close_link)  # Start a timer to automatically disconnect in 20s
		# t.start()

		# Prepare for take off: clear PIDs, log start time...
		self.cf_str_status = "TAKING OFF"
		self.t_start = datetime.now()
		self.cf_PID_roll.clear()
		self.cf_PID_pitch.clear()
		self.cf_PID_yaw.clear()
		self.cf_PID_thrust.clear()

		# Alright, let's fly!
		tStop = None
		while tStop is None:  # tStop will remain None while everything's fine
			tStop = self.hover()  # hover returns None while everything's fine; the time to end the experiment otherwise

		# If we get here, either the user stopped the experiment or the code detected something went wrong
		print "AT t={}, A KEY WAS PRESSED -> STOPPING!".format(datetime.now().strftime("%H:%M:%S.%f")[:-3])
		save_logs = (self.cf_str_status != "TAKING OFF")  # Only store the logs if the drone ever started flying (not just took off)
		self.cf_str_status = "STOPPED"  # Updated new drone status

		while datetime.now() < tStop:  # Keep calling hover until tStop, so data is still logged
			self.hover()

		return save_logs  # Return whether or not to keep the logs
开发者ID:CarlosRDomin,项目名称:SensorFlySwarm,代码行数:69,代码来源:full_control_with_cam.py


注:本文中的cflib.crazyflie.log.LogConfig.stop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。