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


Python LogConfig.add_variable方法代码示例

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


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

示例1: __init__

# 需要导入模块: from cfclient.utils.logconfigreader import LogConfig [as 别名]
# 或者: from cfclient.utils.logconfigreader.LogConfig import add_variable [as 别名]
class CrazyflieROS:
    Disconnected = 0
    Connecting = 1
    Connected = 2

    """Wrapper between ROS and Crazyflie SDK"""
    def __init__(self, link_uri, tf_prefix, roll_trim, pitch_trim):
        self.link_uri = link_uri
        self.tf_prefix = tf_prefix
        self.roll_trim = roll_trim
        self.pitch_trim = pitch_trim
        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._cmdVel = Twist()
        self._subCmdVel = rospy.Subscriber("cmd_vel", Twist, self._cmdVelChanged)

        #self._pubImu = rospy.Publisher('imu', Imu, queue_size=1)
        #self._pubTemp = rospy.Publisher('temperature', Temperature, queue_size=1)
        #self._pubMag = rospy.Publisher('magnetic_field', MagneticField, queue_size=1)
        #self._pubPressure = rospy.Publisher('pressure', Float32, queue_size=1)
        self._pubBattery = rospy.Publisher('battery', Float32, queue_size=1)

        self._state = CrazyflieROS.Disconnected
        Thread(target=self._update).start()

    def _try_to_connect(self):
        rospy.loginfo("Connecting to %s" % self.link_uri)
        self._state = CrazyflieROS.Connecting
        self._cf.open_link(self.link_uri)

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

        rospy.loginfo("Connected to %s" % link_uri)
        self._state = CrazyflieROS.Connected

        #self._lg_imu = LogConfig(name="IMU", period_in_ms=10)
        #self._lg_imu.add_variable("acc.x", "float")
        #self._lg_imu.add_variable("acc.y", "float")
        #self._lg_imu.add_variable("acc.z", "float")
        #self._lg_imu.add_variable("gyro.x", "float")
        #self._lg_imu.add_variable("gyro.y", "float")
        #self._lg_imu.add_variable("gyro.z", "float")

        #self._cf.log.add_config(self._lg_imu)
        #if self._lg_imu.valid:
            # This callback will receive the data
        #    self._lg_imu.data_received_cb.add_callback(self._log_data_imu)
            # This callback will be called on errors
        #    self._lg_imu.error_cb.add_callback(self._log_error)
            # Start the logging
        #    self._lg_imu.start()
        #else:
        #    rospy.logfatal("Could not add logconfig since some variables are not in TOC")

        self._lg_log2 = LogConfig(name="LOG2", period_in_ms=100)
        self._lg_log2.add_variable("mag.x", "float")
        self._lg_log2.add_variable("mag.y", "float")
        self._lg_log2.add_variable("mag.z", "float")
        self._lg_log2.add_variable("baro.temp", "float")
        self._lg_log2.add_variable("baro.pressure", "float")
        self._lg_log2.add_variable("pm.vbat", "float")

        self._cf.log.add_config(self._lg_log2)
        if self._lg_log2.valid:
            # This callback will receive the data
            self._lg_log2.data_received_cb.add_callback(self._log_data_log2)
            # This callback will be called on errors
            self._lg_log2.error_cb.add_callback(self._log_error)
            # Start the logging
            self._lg_log2.start()
        else:
            rospy.logfatal("Could not add logconfig since some variables are not in TOC")

        p_toc = self._cf.param.toc.toc
        for group in p_toc.keys():
            self._cf.param.add_update_callback(group=group, name=None, cb=self._param_callback)
            for name in p_toc[group].keys():
                ros_param = "~{}/{}".format(group, name)
                cf_param = "{}.{}".format(group, name)
                if rospy.has_param(ros_param):
                    self._cf.param.set_value(cfparam, rospy.get_param(ros_param))
                else:
                    self._cf.param.request_param_update(cf_param)


    def _connection_failed(self, link_uri, msg):
        """Callback when connection initial connection fails (i.e no Crazyflie
        at the speficied address)"""
        rospy.logfatal("Connection to %s failed: %s" % (link_uri, msg))
        self._state = CrazyflieROS.Disconnected

    def _connection_lost(self, link_uri, msg):
        """Callback when disconnected after a connection has been made (i.e
#.........这里部分代码省略.........
开发者ID:gnunoe,项目名称:Cf_ROS,代码行数:103,代码来源:crazyflie.py

示例2: __init__

# 需要导入模块: from cfclient.utils.logconfigreader import LogConfig [as 别名]
# 或者: from cfclient.utils.logconfigreader.LogConfig import add_variable [as 别名]

#.........这里部分代码省略.........
            self.Acceleration_Plot.UpdateGraph(graphname="Y_Earth",pos=[t,self.a[1]])
            self.Acceleration_Plot.UpdateGraph(graphname="Z_Earth",pos=[t,self.a[2]])
            self.Acceleration_Plot.UpdateGraph(graphname="X_Raw",pos=[t,self.aRaw[0]])
            self.Acceleration_Plot.UpdateGraph(graphname="Y_Raw",pos=[t,self.aRaw[1]])
            self.Acceleration_Plot.UpdateGraph(graphname="Z_Raw",pos=[t,self.aRaw[2]])

    def InitializePlotting(self):

        self.Stabilizer_Plot = Debug_Display("Attitude",u"°",x=0,y=0,w=SysInfo.Resolution[0]/2,h=SysInfo.Resolution[1]/3,IndicationInterval=5,IndicationRange=20)

        self.Stabilizer_Plot.addGraph(name="Roll" ,color=Colors["Red"]  ,label=False)
        self.Stabilizer_Plot.addGraph(name="Pitch",color=Colors["Green"],label=False)
        self.Stabilizer_Plot.addGraph(name="Yaw"  ,color=Colors["Blue"] ,label=False)

        self.Velocity_Plot = Debug_Display("Velocity",u"m/s",x=0,y=SysInfo.Resolution[1]/3,w=SysInfo.Resolution[0]/2,h=SysInfo.Resolution[1]/3,IndicationInterval=2,IndicationRange=8)

        self.Velocity_Plot.addGraph(name="X",color=Colors["Red"]  ,label=False)
        self.Velocity_Plot.addGraph(name="Y",color=Colors["Green"],label=False)
        self.Velocity_Plot.addGraph(name="Z",color=Colors["Blue"] ,label=False)

        self.Acceleration_Plot = Debug_Display("Acceleration",u"m/s²",x=0,y=SysInfo.Resolution[1]*2/3,w=SysInfo.Resolution[0]/2,h=SysInfo.Resolution[1]/3,IndicationInterval=2,IndicationRange=8)

        self.Acceleration_Plot.addGraph(name="X_Earth",color=Colors["Red"]  ,label=False)
        self.Acceleration_Plot.addGraph(name="Y_Earth",color=Colors["Green"],label=False)
        self.Acceleration_Plot.addGraph(name="Z_Earth",color=Colors["Blue"] ,label=False)
        self.Acceleration_Plot.addGraph(name="X_Raw",color=Colors["Red"]  *0.5,label=False)
        self.Acceleration_Plot.addGraph(name="Y_Raw",color=Colors["Green"]*0.5,label=False)
        self.Acceleration_Plot.addGraph(name="Z_Raw",color=Colors["Blue"] *0.5,label=False)

    def InitializeLogging(self):
        
        # Attitude (if period_in_ms = <10 -> Invalid -> other Logs start working again?! O.o)
        self.StabilizerLog = LogConfig(name="Stabilizer", period_in_ms=10)
        self.StabilizerLog.add_variable("stabilizer.roll", "float")
        self.StabilizerLog.add_variable("stabilizer.pitch", "float")
        self.StabilizerLog.add_variable("stabilizer.yaw", "float")

        self.Crazyflie.log.add_config(self.StabilizerLog)

        # Battery
        self.BatteryLog = LogConfig(name="Battery", period_in_ms=200)
        self.BatteryLog.add_variable("pm.vbat", "float")

        self.Crazyflie.log.add_config(self.BatteryLog)

        # Barometer
        self.BarometerLog = LogConfig(name="Barometer", period_in_ms=10)
        self.BarometerLog.add_variable("baro.aslLong", "float")

        self.Crazyflie.log.add_config(self.BarometerLog)

        # Accelerometer (if period_in_ms = <10 -> Invalid -> other Logs start working again?! O.o)
        self.AccelerometerLog = LogConfig(name="Accelerometer", period_in_ms=10)
        self.AccelerometerLog.add_variable("acc.x", "float")
        self.AccelerometerLog.add_variable("acc.y", "float")
        self.AccelerometerLog.add_variable("acc.z", "float")

        self.Crazyflie.log.add_config(self.AccelerometerLog)

        # Motors
        self.MotorsLog = LogConfig(name="Motors", period_in_ms=50)
        self.MotorsLog.add_variable("motor.m1", "int32_t")
        self.MotorsLog.add_variable("motor.m2", "int32_t")
        self.MotorsLog.add_variable("motor.m3", "int32_t")
        self.MotorsLog.add_variable("motor.m4", "int32_t")
开发者ID:OpenGelo,项目名称:drone-tracking,代码行数:69,代码来源:CrazyflieControl.py

示例3: __init__

# 需要导入模块: from cfclient.utils.logconfigreader import LogConfig [as 别名]
# 或者: from cfclient.utils.logconfigreader.LogConfig import add_variable [as 别名]
class MyFirstExample:
    """MyExamples"""
    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._cf.open_link(link_uri)
        # Variable used to keep main loop occupied until disconnect
        #self.is_connected = True
        print "Connecting to %s" % link_uri

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

        #setup log config for sensor
        self._log_sensor = LogConfig("Proximity sensor", 200)
        self._log_sensor.add_variable("adc.vProx")
        self._log_sensor.add_variable("baro.aslLong")
        self._cf.log.add_config(self._log_sensor)

        if self._log_sensor.valid:
             # This callback will receive the data
            self._log_sensor.data_received_cb.add_callback(self._log_data)
            # This callback will be called on errors
            self._log_sensor.error_cb.add_callback(self._log_error)
            # Start the logging
            self._log_sensor.start()
        else:
            print("Could not add logconfig since some variables are not in TOC")

        # Start a timer to disconnect in 5s
        t = Timer(10, self._cf.close_link)
        t.start()


        # Start a separate thread to do the motor test.
        # Do not hijack the calling thread!

        #Thread(target=self._ramp_motors).start()


    def _log_data(self, timestamp, data, logconf):
        """Callback froma the log API when data arrives"""

        global myprox
        global ref_baro

        myprox = data["adc.vProx"]
        ref_baro = data["baro.aslLong"]

        #long = float(data["adc.vProx"])

        #if myprox >= 2:
        #    print(myprox, ref_baro)

        #else:
        #    print("Sensor range low", test)


        Thread(target=self._ramp_motors).start()
        #print "[%d][%s]: %s" % (timestamp, logconf.name, data)

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

    def _connection_failed(self, link_uri, msg):
        """Callback when connection initial connection fails (i.e no Crazyflie
        at the speficied address)"""
        print "Connection to %s failed: %s" % (link_uri, msg)
        #self.is_connected = False

    def _connection_lost(self, link_uri, msg):
        """Callback when disconnected after a connection has been made (i.e
        Crazyflie moves out of range)"""
        print "Connection to %s lost: %s" % (link_uri, msg)

    def _disconnected(self, link_uri):
        """Callback when the Crazyflie is disconnected (called in all cases)"""
        print "Disconnected from %s" % link_uri
        #self.is_connected = False


    def _ramp_motors(self):
        thrust_mult = 1
        thrust_step = 100
        thrust = 20000
        pitch = 0
        roll = 0
        yawrate = 0

        print(myprox, ref_baro)

        while thrust >= 20000:
#.........这里部分代码省略.........
开发者ID:gitwikta,项目名称:testing,代码行数:103,代码来源:test_hover_bck.py

示例4: height

# 需要导入模块: from cfclient.utils.logconfigreader import LogConfig [as 别名]
# 或者: from cfclient.utils.logconfigreader.LogConfig import add_variable [as 别名]
class Hover:
	"""
	This will both hover the CF and log/print data concerning the roll,pitch,yaw, etc.
	There are 3 separate PID functions to control: pitch, yaw, and roll. Eventually there will be a 4th to control height (or directly: thrust)
	"""

	def __init__(self, link_uri):
		""" The link_uri is the 'radio address' of the crazyflie """

		#All of the global variables needed for the PID functions
		self.rollsetpoint=0.0
		self.pitchsetpoint=0.0
		self.yawsetpoint=0.0
		self.altitudesetpoint= 20.0
		self.thrust=20000
		
		#Calculated errors
		self.iroll=0.0
		self.droll=0.0
		self.ipitch=0.0
		self.dpitch=0.0
		self.iyaw=0.0
		self.dyaw=0.0
		self.ialtitude=0.0
		self.daltitude=0.0
		
		#The last recorded timestamp (used for dt determination)
		self.lastTime=0
		self.lastRollError=0.0
		self.lastPitchError=0.0
		self.lastYawError=0.0
		self.lastAltitudeError=0.0
		
		#PID coefficients
		self.kp_roll=0.#1.5#1.75
		self.kp_pitch=0.#0.75#2.3#2.5
		self.kp_yaw=0.0
		self.kp_altitude=0.
		self.ki_yaw=0.0
		self.ki_roll=0.0
		self.ki_pitch=0.0#0.000005#0.00000012
		self.ki_altitude=0.0
		self.kd_roll=0.0
		self.kd_pitch=0.0
		self.kd_altitude=0.0
		self.lastVal=7.0

		
		# Create a Crazyflie object
		self._cf = Crazyflie()

		# Connect some callbacks from the Crazyflie API
		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)

		print "Connecting to %s" % link_uri

		# Connect to the Crazyflie
		self._cf.open_link(link_uri)

		# Variable used to keep main loop occupied until disconnect
		self.is_connected = True

	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="HoverLog", period_in_ms=10)
		self._lg_stab.add_variable("stabilizer.pitch", "float")
		self._lg_stab.add_variable("stabilizer.roll","float")
		self._lg_stab.add_variable("stabilizer.yaw", "float")
		self._lg_stab.add_variable("stabilizer.thrust", "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")
		#self._lg_stab.add_variable("baro.aslLong","float")
		
		#self._lg_stab = LogConfig(name="mb", period_in_ms=10)
		self._lg_stab.add_variable("mb.distance","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")
		# Unlock startup thrust protection
		self._cf.commander.send_setpoint(0, 0, 0, 0)
		# Start a timer to disconnect the crazyflie in 25 seconds
		t = Timer(25,self._cf.close_link)
#.........这里部分代码省略.........
开发者ID:manomitbal,项目名称:Smart-Flie,代码行数:103,代码来源:hoverPID.py

示例5: __init__

# 需要导入模块: from cfclient.utils.logconfigreader import LogConfig [as 别名]
# 或者: from cfclient.utils.logconfigreader.LogConfig import add_variable [as 别名]
class TestFlight:

    def __init__(self):
        """
        Initialize the quad copter
        """
        # Log file for Accelerometer
        self.f1 = open('Accelerometer_log.txt', 'w')
        # Log file for Pitch Roll Yaw
        self.f2 = open('Stabalizer_log.txt', 'w')
        # Log file for altitude
        self.f3 = open('Barometer_log.txt', 'w')

        # write data into the log files
        self.f1.write('Accelerometer log\n {date} {acc.x} {acc.y} {acc.z}\n')
        self.f2.write('Stabilizer log\n{date} {Roll} {Pitch} {Yaw} {Thrust}\n')
        self.f3.write('Barometer log\n {data} {ASL}\n')

        # get the Unix time
        self.starttime = time.time()*1000.0
        self.date = time.time()*1000.0 - self.starttime

        # Initialize the crazyflie and get the drivers ready
        self.crazyflie = cflib.crazyflie.Crazyflie()
        print 'Initializing drivers'
        cflib.crtp.init_drivers()

        # Start scanning available devices
        print 'Searching for available devices'
        available = cflib.crtp.scan_interfaces()

        radio = False
        for i in available:
            # Connect to the first device of the type 'radio'
            if 'radio' in i[0]:
                radio = True
                dev = i[0]
                print 'Connecting to interface with URI [{0}] and name {1}'.format(i[0], i[1])
                self.crazyflie.open_link("radio://0/80/250K")
                ## radio://0/80/250K is most well connected radio frequency
                # Heungseok Park, 4.9.2015
                #self.crazyflie.open_link(dev)

                break

        if not radio:
            print 'No quadcopter detected. Try to connect again.'
            exit(-1)

        # Set up the callback when connected
        self.crazyflie.connected.add_callback(self.connectSetupFinished)


    def connectSetupFinished(self, linkURI):
        """
        Set the loggers
        """

        """
        # Log stabilizer
        self.logStab = LogConfig("Stabalizer", 200)
        self.logStab.add_variable("stabilizer.roll", "float")
        self.logStab.add_variable("stabilizer.pitch", "float")
        self.logStab.add_variable("stabilizer.yaw", "float")
        self.logStab.add_variable("stabilizer.thrust", "uint16_t")

        self.crazyflie.log.add_config(self.logStab)

        if self.logStab.valid:
            self.logStab.data_received_cb.add_callback(self.print_stab_data)
            self.logStab.start()
        else:
            print 'Could not setup log configuration for stabilizer after connection!'

        """

        # Log barometer
        # we use only barometer value(ASL Value) to control altitude
        self.logBaro = LogConfig("Baro", 200)
        self.logBaro.add_variable("baro.aslLong", "float")
        self.crazyflie.log.add_config(self.logBaro)
        if  self.logBaro.valid:
            self.logBaro.data_received_cb.add_callback(self.print_baro_data)
            self.logBaro.start()
        else:
            print 'Could not setup log configuration for barometer after connection!'

        """
        # Log Accelerometer
        self.logAccel = LogConfig("Accel",200)
        self.logAccel.add_variable("acc.x", "float")
        self.logAccel.add_variable("acc.y", "float")
        self.logAccel.add_variable("acc.z", "float")

        self.crazyflie.log.add_config(self.logAccel)

        if self.logAccel.valid:
            self.logAccel.data_received_cb.add_callback(self.print_accel_data)
            self.logAccel.start()
        else:
#.........这里部分代码省略.........
开发者ID:Daomaster,项目名称:Crazyflie-DDrone,代码行数:103,代码来源:backup_Dance_Test.py

示例6: __init__

# 需要导入模块: from cfclient.utils.logconfigreader import LogConfig [as 别名]
# 或者: from cfclient.utils.logconfigreader.LogConfig import add_variable [as 别名]
class LoggingExample:
    """
    Simple logging example class that logs the Stabilizer from a supplied
    link uri and disconnects after 5s.
    """

    def __init__(self, link_uri):
        """ Initialize and run the example with the specified link_uri """

        # Create a Crazyflie object without specifying any cache dirs
        self._cf = Crazyflie()

        # Connect some callbacks from the Crazyflie API
        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)

        print("Connecting to %s" % link_uri)

        # Try to connect to the Crazyflie
        self._cf.open_link(link_uri)

        # Variable used to keep main loop occupied until disconnect
        self.is_connected = True

    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("acc.zw", "float")
        self._lg_stab.add_variable("rangefinder.range")

        # 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()

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

    def _stab_log_data(self, timestamp, data, logconf):
        """Callback froma the log API when data arrives"""
        print("[%d][%s]: %s" % (timestamp, logconf.name, data))

    def _connection_failed(self, link_uri, msg):
        """Callback when connection initial connection fails (i.e no Crazyflie
        at the speficied address)"""
        print("Connection to %s failed: %s" % (link_uri, msg))
        self.is_connected = False

    def _connection_lost(self, link_uri, msg):
        """Callback when disconnected after a connection has been made (i.e
        Crazyflie moves out of range)"""
        print("Connection to %s lost: %s" % (link_uri, msg))

    def _disconnected(self, link_uri):
        """Callback when the Crazyflie is disconnected (called in all cases)"""
        print("Disconnected from %s" % link_uri)
        self.is_connected = False
开发者ID:javieryu,项目名称:crazyflie-scripts,代码行数:84,代码来源:basiclog.py

示例7: __init__

# 需要导入模块: from cfclient.utils.logconfigreader import LogConfig [as 别名]
# 或者: from cfclient.utils.logconfigreader.LogConfig import add_variable [as 别名]
class logs:

     def __init__(self, cf):

        #self.log_file_next_stuff = open("log_file_next.txt", "w+")
        #self.log_file_stab = open("log_file_stab.txt", "w+")

        #local copy of crazy_Auto
         self._cf = cf

        # Roll, Pitch, Yaw
         self.init_state = [0,0,0]
         self.state = [0,0,0]
         self.next_state = [0,0]
         # X, Y, Z, Mag
         self.init_accel_state = [0,0,0,0]
         self.accel_state = [0,0,0,0]

         # X, Y, Z
         self.init_gyro_state = [0,0,0]
         self.gyro_state = [0,0,0]

         # ground average, current
         self.altitude = [0,0]

        #current battery voltage
         self.battery_state = 0

         #[roll,pitch,yaw,altitude,acc.x,acc.y,acc.z,acc.mag,gyro.x, gyro.y, gyro.z, batteryV]
         self.measurements = [0 for i in range(12)]

         self.logging_count = 0

         #Setup logs once connection to crazyflie has been established
         self._cf._cf.connected.add_callback(self._init_flight_var)

         # specifying the size of the state and the observation space
         #self.transition_matrices = np.array([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]])
         #self.transition_matrices.resize(4,1)
         #self.kf = KalmanFilter(transition_matrices=self.transition_matrices, n_dim_obs= 4) #transition_matrices=self.transition_matrices,


         #self._cf.connected.add_callback(self._init_flight_var) #fill in base parameters for flight



     def _init_flight_var(self, link_uri):

         print ("Connected to %s" % link_uri)

         self.RPY_log = LogConfig(name="Stabilizer", period_in_ms=10)

         self.RPY_log.add_variable("stabilizer.roll", "float")
         self.RPY_log.add_variable("stabilizer.pitch", "float")
         self.RPY_log.add_variable("stabilizer.yaw", "int16_t")

         self.RPY_log.add_variable("baro.asl", "float") #barometer above sea level

         self.RPY_log.add_variable("gyro.x", "float")
         self.RPY_log.add_variable("gyro.y", "float")
         self.RPY_log.add_variable("gyro.z", "float")
         self.battery_log = LogConfig(name="Battery", period_in_ms=1000)
         self.battery_log.add_variable("pm.vbat", "float")

         self.acc_log = LogConfig(name="Acc", period_in_ms = 10)
         self.acc_log.add_variable("acc.x", "float")
         self.acc_log.add_variable("acc.y", "float")
         self.acc_log.add_variable("acc.z", "float")

         self._cf._cf.log.add_config(self.RPY_log) #add the log to the CrazyFlie
         self._cf._cf.log.add_config(self.battery_log)
         self._cf._cf.log.add_config(self.acc_log)

         self.RPY_log.data_received_cb.add_callback(self.update_flight_params)
         self.RPY_log.error_cb.add_callback(self.update_error)
         self.battery_log.data_received_cb.add_callback(self.update_battery)
         self.battery_log.error_cb.add_callback(self.update_error)

         self.acc_log.data_received_cb.add_callback(self.update_acc)
         self.acc_log.error_cb.add_callback(self.update_error)


         self.RPY_log.start()
         self.battery_log.start()
         self.acc_log.start()
         print ("Logging Started\n")

         self._cf._cf.connected.add_callback(self._cf._connected)

     def update_error(self, logconf, msg):
         print ("Error when logging %s: %s" % (logconf.name, msg))

     def update_battery(self, timestamp, data, logconf):
         self.battery_state = data["pm.vbat"]
     def update_acc(self, timestamp, data, logconf):
         if not self._cf.is_flying:
             self.init_accel_state[0] = data["acc.x"]
             self.init_accel_state[1] = data["acc.y"]
             self.init_accel_state[2] = data["acc.z"]
             self.init_accel_state[3] = data["acc.mag2"]
#.........这里部分代码省略.........
开发者ID:vigneshrajmohan,项目名称:CrazyflieControl,代码行数:103,代码来源:minortangent.py

示例8: __init__

# 需要导入模块: from cfclient.utils.logconfigreader import LogConfig [as 别名]
# 或者: from cfclient.utils.logconfigreader.LogConfig import add_variable [as 别名]
class MyCF:
    def __init__(self,uri):
        self.cf=Crazyflie()
        self.cf.connected.add_callback(self.connected)
        self.cf.disconnected.add_callback(self.disconnected)
        self.cf.open_link(uri)
        self.uri=uri

        self.is_connected=True

    def connected(self,uri):
        print("Connected to {}".format(uri))
        # Thread(target=self.motor).start()
        self.log_thread()

    def disconnected(self,uri):
        print("disconnected from {}".format(uri))

    def close(self):
        self.cf.close_link()

    def log_thread(self):
        self.log = LogConfig(name="acc", period_in_ms=100)
        self.log.add_variable("acc.x", "float")
        self.log.add_variable("acc.y", "float")
        self.log.add_variable("acc.z", "float")

        try:
            self.cf.log.add_config(self.log)
            # This callback will receive the data
            self.log.data_received_cb.add_callback(self.log_received)
            # # This callback will be called on errors
            self.log.error_cb.add_callback(self.log_error)
            # Start the logging
            self.log.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."

        t=Timer(5,self.close)

    def log_received(self,timestamp, data, logconf):
        # self.x.setText("x: {}".format["acc.x"])
        # self.y.setText("y: {}".format["acc.y"])
        # self.z.setText("z: {}".format["acc.z"])
        print("{}, {} = {} on {}".format(timestamp,logconf.name,data["acc.x"],self.uri))


    def log_error(self,logconf, msg):
        print("error while loggoing {}\n{}".format(logconf.name,msg))


    def motor(self):
        thrust_mult = 1
        thrust_step = 50
        thrust = 20000
        pitch = 0
        roll = 0
        yawrate = 0

        #Unlock startup thrust protection
        self.cf.commander.send_setpoint(0, 0, 0, 0)



        while thrust >= 20000:
            self.cf.commander.send_setpoint(roll, pitch, yawrate, thrust)
            sleep(0.1)
            if thrust >= 25000:
                thrust_mult = -1
            thrust += thrust_step * thrust_mult
        self.cf.commander.send_setpoint(0, 0, 0, 0)
        # Make sure that the last packet leaves before the link is closed
        # since the message queue is not flushed before closing
        sleep(0.1)
        self.close()
开发者ID:Venris,项目名称:crazyflie-multilink,代码行数:80,代码来源:MyCF.py

示例9: get_gyroscope_log_config

# 需要导入模块: from cfclient.utils.logconfigreader import LogConfig [as 别名]
# 或者: from cfclient.utils.logconfigreader.LogConfig import add_variable [as 别名]
 def get_gyroscope_log_config(self):
     log_conf = LogConfig("GyroScope", period_in_ms=100)
     log_conf.add_variable("gyro.x", "float")
     log_conf.add_variable("gyro.y", "float")
     log_conf.add_variable("gyro.z", "float")
     return log_conf
开发者ID:dineshkumar-cse,项目名称:ElateCopter,代码行数:8,代码来源:copter_logger.py

示例10: __init__

# 需要导入模块: from cfclient.utils.logconfigreader import LogConfig [as 别名]
# 或者: from cfclient.utils.logconfigreader.LogConfig import add_variable [as 别名]
class Quad:
    """
    Simple logging example class that logs the Stabilizer from a supplied
    link uri and disconnects after 5s.
    """
    def __init__(self, link_uri):
        """ Initialize and run the example with the specified link_uri """

        # Create a Crazyflie object without specifying any cache dirs
        self._cf = Crazyflie()

        # Connect some callbacks from the Crazyflie API
        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)

        print "Connecting to %s" % link_uri

        # Try to connect to the Crazyflie
        self._cf.open_link(link_uri)

        # Variable used to keep main loop occupied until disconnect
        self.is_connected = True

    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

        Thread(target=self._control).start()
        Thread(target=self._input).start()

        ########################################################################
        # Set up Stabilizer Logger
        ########################################################################
        self._lg_stab = LogConfig(name="Stabilizer", period_in_ms=50)
        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._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._log_stab_data)
            # This callback will be called on errors
            self._lg_stab.error_cb.add_callback(self._log_error)
            # Start the logging
            self._lg_stab.start()
        else:
            print("Could not add logconfig since some variables are not in TOC")

        # ########################################################################
        # # Set up Battery Logger
        # ########################################################################
	self._lg_bat = LogConfig(name="Battery",period_in_ms=50)
	self._lg_bat.add_variable("pm.vbat", "float")
	self._cf.log.add_config(self._lg_bat)
	if self._lg_bat.valid:
	    # This callback will receive the data
            self._lg_bat.data_received_cb.add_callback(self._log_bat_data)
            # This callback will be called on errors
            self._lg_bat.error_cb.add_callback(self._log_error)
            # Start the logging
            self._lg_bat.start()
	else:
	    print("Could not setup loggingblock! You dun goofed")

        # ########################################################################
        # # Set up Acc Logger
        # ########################################################################
        # self._lg_acc = LogConfig(name="Acc", period_in_ms=50)
        # self._lg_acc.add_variable("acc.x", "float")
        # self._lg_acc.add_variable("acc.y", "float")
        # self._lg_acc.add_variable("acc.z", "float")
        # self._cf.log.add_config(self._lg_acc)
        # if self._lg_acc.valid:
        #     # This callback will receive the data
        #     self._lg_acc.data_received_cb.add_callback(self._log_acc_data)
        #     # This callback will be called on errors
        #     self._lg_acc.error_cb.add_callback(self._log_error)
        #     # Start the logging
        #     self._lg_acc.start()
        # else:
        #     print("Could not add logconfig since some variables are not in TOC")

        # ########################################################################
        # # Set up Gyro Logger
        # ########################################################################
        # self._lg_gyro = LogConfig(name="Gyro", period_in_ms=50)
        # self._lg_gyro.add_variable("gyro.x", "float")
        # self._lg_gyro.add_variable("gyro.y", "float")
        # self._lg_gyro.add_variable("gyro.z", "float")
        # self._cf.log.add_config(self._lg_gyro)
        # if self._lg_gyro.valid:
        #     # This callback will receive the data
        #     self._lg_gyro.data_received_cb.add_callback(self._log_gyro_data)
        #     # This callback will be called on errors
        #     self._lg_gyro.error_cb.add_callback(self._log_error)
        #     # Start the logging
        #     self._lg_gyro.start()
#.........这里部分代码省略.........
开发者ID:dreal,项目名称:quadcopter,代码行数:103,代码来源:sustainedflight.py

示例11: get_stabilizer_log_config

# 需要导入模块: from cfclient.utils.logconfigreader import LogConfig [as 别名]
# 或者: from cfclient.utils.logconfigreader.LogConfig import add_variable [as 别名]
 def get_stabilizer_log_config(self):
     stab_log_conf = LogConfig("stabilizer", period_in_ms=100)
     stab_log_conf.add_variable("stabilizer.roll", "float")
     stab_log_conf.add_variable("stabilizer.pitch", "float")
     stab_log_conf.add_variable("stabilizer.yaw", "float")
     return stab_log_conf
开发者ID:dineshkumar-cse,项目名称:ElateCopter,代码行数:8,代码来源:copter_logger.py

示例12: get_accelerometer_log_config

# 需要导入模块: from cfclient.utils.logconfigreader import LogConfig [as 别名]
# 或者: from cfclient.utils.logconfigreader.LogConfig import add_variable [as 别名]
 def get_accelerometer_log_config(self):
     log_conf = LogConfig("Accel", period_in_ms=100)
     log_conf.add_variable("acc.x", "float")
     log_conf.add_variable("acc.y", "float")
     log_conf.add_variable("acc.z", "float")
     return log_conf
开发者ID:dineshkumar-cse,项目名称:ElateCopter,代码行数:8,代码来源:copter_logger.py

示例13: __init__

# 需要导入模块: from cfclient.utils.logconfigreader import LogConfig [as 别名]
# 或者: from cfclient.utils.logconfigreader.LogConfig import add_variable [as 别名]
class Crazy:
    def __init__(self,ui):

        # zmienne pomocnicze w obsludze GUI
        self.ui=ui

        self.thrust=0
        self.pitch=0
        self.roll=0
        self.yaw=0
        self.startup=True
        self.is_connected=False

        # ustawienia biblioteki cf
        self.cf=Crazyflie()
        self.cf.connected.add_callback(self.connected)
        self.cf.disconnected.add_callback(self.disconnected)

    #funkcja inicjujaca polaczenie
    def connect(self,uri):
        self.cf.open_link(uri)
        self.is_connected=True

    # funkcja wywolywana w chwili odebrania informacji o podlaczeniu sie
    def connected(self,uri):
        self.ui.l_conn.setText("Connected to {}".format(uri))
        print("Connected to {}".format(uri))
        control=Thread(target=self.send_ctrl)
        control.start()
        # self.log_thread()

    # funkcja wywolywana w chwili zakonczenia transmisji
    def disconnected(self,uri):
        self.ui.l_conn.setText("Disconnected")
        print("disconnected from {}".format(uri))
        self.is_connected=False

    # funkcja  konczaca polaczenie
    def close(self):
        self.cf.close_link()

    # ustawienia watku zbierajacego dane
    def log_thread(self):
        self.log = LogConfig(name="logs", period_in_ms=100)
        self.log.add_variable("stabilizer.roll", "float")
        self.log.add_variable("stabilizer.pitch", "float")
        self.log.add_variable("stabilizer.yaw", "float")

        try:
            self.cf.log.add_config(self.log)
            # This callback will receive the data
            self.log.data_received_cb.add_callback(self.log_received)
            # # This callback will be called on errors
            self.log.error_cb.add_callback(self.log_error)
            # Start the logging
            self.log.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."

    # odbieranie danych
    def log_received(self,timestamp, data, logconf):
        self.katy[0]=data["stabilizer.roll"]
        self.katy[1]=data["stabilizer.pitch"]
        self.katy[2]=data["stabilizer.yaw"]
        self.ui.l_pitch_a.setText("Pitch: {:.3f}".format(self.katy[1]))
        self.ui.l_roll_a.setText("Roll: {:.3f}".format(self.katy[0]))
        self.ui.l_yaw_a.setText("Yaw: {:.3f}".format(self.katy[2]))
        # print("{}, {} = {}".format(timestamp,logconf.name,data["acc.x"]))

    def log_error(self,logconf, msg):
        print("error while loggoing {}\n{}".format(logconf.name,msg))

    # zmiana ustawien sterowania
    def update_ctrl(self,thrust,pitch,roll,yaw):
        print("thrust changed to {}".format(thrust))
        print("yaw changed to {}".format(yaw))
        print("pitch changed to {}".format(pitch))
        print("roll changed to {}".format(roll))
        self.thrust=thrust
        self.pitch=pitch
        self.roll=roll
        self.yaw=yaw


    # watek wysylajacy sterowanie
    def send_ctrl(self):

        while True:


            if self.thrust > 60000:
                self.thrust=60000
            if self.thrust < 0:
                self.thrust=0

            #Unlock startup thrust protection
            if self.startup:
#.........这里部分代码省略.........
开发者ID:Venris,项目名称:crazyflie-multilink,代码行数:103,代码来源:CF_class_sterowanie.py

示例14: __init__

# 需要导入模块: from cfclient.utils.logconfigreader import LogConfig [as 别名]
# 或者: from cfclient.utils.logconfigreader.LogConfig import add_variable [as 别名]
class Main:

    # Initial values, you can use these to set trim etc.
    roll = 0.0
    pitch = 0.0
    yawrate = 0
    thrust = 10001

    # desire asl value, it could be changed current_asl_value + 50
    d_asl = 685


    def __init__(self):
        self.crazyflie = Crazyflie()
        cflib.crtp.init_drivers(enable_debug_driver=False)

        print "Scanning interfaces for Crazyflies..."
        available = cflib.crtp.scan_interfaces()
        print "Crazyflies found: "

        for i in available:
            print i[0]

        # You may need to update this value if your Crazyradio uses a different frequency.

        link_uri = available[0][0]

        #link_uri = available[0][0]
        #self.crazyflie.open_link(link_uri)
        self.crazyflie.open_link("radio://0/80/250K")

        self.crazyflie.connected.add_callback(self._connectSetupFinished)

        #self.crazyflie.disconnected.add_callback(self._disconnected)
        self.crazyflie.connection_failed.add_callback(self._connection_failed)
        self.crazyflie.connection_lost.add_callback(self._connection_lost)



    def _connectSetupFinished(self, linkURI):
        # Keep the commands alive so the firmware kill-switch doesn't kick in.
        Thread(target=self.pulse_command).start()

        hold_flag = True


        # The definition of the logconfig can be made before connecting
        self._lg_alt = LogConfig(name="altitude", period_in_ms=10)
        self._lg_alt.add_variable("baro.asl", "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_alt)
        if self._lg_alt.valid:
            # This callback will receive the data
            self._lg_alt.data_received_cb.add_callback(self._alt_log_data)
            # This callback will be called on errors
            self._lg_alt.error_cb.add_callback(self._alt_log_error)
            # Start the logging
            self._lg_alt.start()
        else:
            print("Could not add logconfig since some variables are not in TOC")




        while 1:

            #self.crazyflie.log.


            self.thrust = int(raw_input("Set thrust (10001-60000):"))

            if self.thrust == 0:
                self.crazyflie.close_link()
                break
            elif self.thrust <= 10000:
                self.thrust = 10001
            elif self.thrust == 40000:
                # Test altitude hold flightmode
                time.sleep(10)
                #self.crazyflie.commander.send_setpoint(0, 0, 0, 0)
                time.sleep(0.05)
                self.param.set_value("flightmode.althold", "True")
                #time.sleep(10)
                #self.param.set_value("flightmode.althold", "False")
            elif self.thrust > 60000:
                self.thrust = 60000







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

#.........这里部分代码省略.........
开发者ID:Daomaster,项目名称:Crazyflie-DDrone,代码行数:103,代码来源:test3.py

示例15: __init__

# 需要导入模块: from cfclient.utils.logconfigreader import LogConfig [as 别名]
# 或者: from cfclient.utils.logconfigreader.LogConfig import add_variable [as 别名]
class TestFlight:
    def __init__(self):
        """
        Initialize the quadcopter
        """
        self.crazyflie = cflib.crazyflie.Crazyflie()
        print 'Initializing drivers' 
        cflib.crtp.init_drivers()
 
        print 'Searching for available devices'
        available = cflib.crtp.scan_interfaces()

        radio = False
        for i in available:
            # Connect to the first device of the type 'radio'
            if 'radio' in i[0]:
                radio = True
                dev = i[0]
                print 'Connecting to interface with URI [{0}] and name {1}'.format(i[0], i[1])
                self.crazyflie.open_link(dev)
                break

        if not radio:
            print 'No quadcopter detected. Try to connect again.'
            exit(-1)

        # Set up the callback when connected
        self.crazyflie.connectSetupFinished.add_callback(self.connectSetupFinished)


    def connectSetupFinished(self, linkURI):
        """
        Set the loggers
        """
        # Log stabilizer
        self.logStab = LogConfig("Stabalizer", 200)
        self.logStab.add_variable("stabilizer.roll", "float")
        self.logStab.add_variable("stabilizer.pitch", "float")
        self.logStab.add_variable("stabilizer.yaw", "float")
        self.logStab.add_variable("stabilizer.thrust", "uint16_t")
 
        self.crazyflie.log.add_config(self.logStab)
 
        if self.logStab.valid:
            self.logStab.data_received_cb.add_callback(self.print_stab_data)
            self.logStab.start()
        else:
            print 'Could not setup log configuration for stabilizer after connection!'

        # Log barometer
        self.logBaro = LogConfig("Baro", 200)
        self.logBaro.add_variable("baro.aslLong", "float")

        self.crazyflie.log.add_config(self.logBaro)
        if self.logBaro.valid:
            self.logBaro.data_received_cb.add_callback(self.print_baro_data)
            self.logBaro.start()
        else:
            print 'Could not setup log configuration for barometer after connection!'

        # Log Accelerometer
        self.logAccel = LogConfig("Accel",200)
        self.logAccel.add_variable("acc.x", "float")
        self.logAccel.add_variable("acc.y", "float")
        self.logAccel.add_variable("acc.z", "float")

        self.crazyflie.log.add_config(self.logAccel)

        if self.logAccel.valid:
            self.logAccel.data_received_cb.add_callback(self.print_accel_data)
            self.logAccel.start()
        else:
            print 'Could not setup log configuration for accelerometer after connection!'



        Thread(target=self.increasing_step).start()



    def print_baro_data(self, ident, data, logconfig):
        #logging.info("Id={0}, Barometer: asl={1:.4f}".format(ident, data["baro.aslLong"]))
        pass
 
    def print_stab_data(self, ident, data, logconfig):
        sys.stdout.write('Id={0}, Stabilizer: Roll={1:.2f}, Pitch={2:.2f}, Yaw={3:.2f}, Thrust={4:.2f}\r'.format(ident, data["stabilizer.roll"], data["stabilizer.pitch"], data["stabilizer.yaw"], data["stabilizer.thrust"]))

    def print_accel_data(self, ident, data, logconfig):
        #logging.info("Id={0}, Accelerometer: x={1:.2f}, y={2:.2f}, z={3:.2f}".format(ident, data["acc.x"], data["acc.y"], data["acc.z"]))
        pass


    def increasing_step(self):
        global key
        start_thrust = 10000 # (blades start to rotate after 10000)
        min_thrust = 10000
        max_thrust = 80000
        thrust_increment = 500

        start_roll = 0
#.........这里部分代码省略.........
开发者ID:patxu,项目名称:attackofthedrones,代码行数:103,代码来源:keyboard_control.py


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