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


Python SenseHat.get_gyroscope_raw方法代码示例

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


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

示例1: __init__

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_gyroscope_raw [as 别名]
class SenseLogger:
    def __init__(self):
        self.sense = SenseHat()
        self.filename = "./logs/Senselogg-"+str(datetime.now())+".csv"
        self.file_setup(self.filename)

    def write_line(self, line):
        with open(self.filename, "a") as f:
            f.write(line + "\n")
        
    def log_data(self):
        sense_data = self.get_sense_data()
        line = ",".join(str(value) for value in sense_data)
        self.write_line(line)

    def file_setup(self, filename):
        header = ["datetime", "temp_h", "temp_p", "humidity", "pressure", "pitch",
                  "roll", "yaw", "mag_x", "mag_y", "mag_z",
                  "accel_x", "accel_y", "accel_z",
                  "gyro_x", "gyro_y", "gyro_z"]

        with open(filename, "w") as f:
            f.write(",".join(str(value) for value in header)+ "\n")

    def get_sense_data(self):
        sense_data = []
        sense_data.append(datetime.now())
        sense_data.append(self.sense.get_temperature_from_humidity())
        sense_data.append(self.sense.get_temperature_from_pressure())
        sense_data.append(self.sense.get_humidity())
        sense_data.append(self.sense.get_pressure())

        o = self.sense.get_orientation()
        yaw = o["yaw"]
        pitch = o["pitch"]
        roll = o["roll"]
        sense_data.extend([pitch, roll, yaw])

        mag = self.sense.get_compass_raw()
        x = mag["x"]
        y = mag["y"]
        z = mag["z"]
        sense_data.extend([x, y, z])    

        acc = self.sense.get_accelerometer_raw()
        x = acc["x"]
        y = acc["y"]
        z = acc["z"]
        sense_data.extend([x, y, z])  

        gyro = self.sense.get_gyroscope_raw()
        x = gyro["x"]
        y = gyro["y"]
        z = gyro["z"]
        sense_data.extend([x, y, z])

        return sense_data
开发者ID:PaulSolheim,项目名称:Robotkurs,代码行数:59,代码来源:senselogger.py

示例2: Back

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_gyroscope_raw [as 别名]
	if GPIO.input(LEFT) == False:
		Back() #If the left button (from the 4 button diamond shape arangement) is pressed the Back() function will run
	if GPIO.input(RIGHT) == False:
		Forwards() #If the right button is pressed then the Forwards() function will run
	if GPIO.input(UP) == False:
		Plus() #If the up button (the one at the top) is pressed then the Plus() function will run
	if GPIO.input(DOWN) == False:
		Less() #If the down button (the one at the bottom) is pressed then the Less() function will run
	if GPIO.input(A) == False:
		Prev() #If button A (the left button of the pair of buttons beneath the first 4) is pressed then the Prev() function will run
	if GPIO.input(B) == False:
		Next(1) #If button B (to the right of button A) is pressed then the Next(1) function will run

	#shake routines to call prev and next
	pitch, roll, yaw = sense.get_gyroscope_raw().values()
	if yaw > threshold:
		pitch = round(pitch, 1) #This sets the variable 'pitch' to the gyroscope measurement of pitch rounded to one place
		roll = round(roll, 1) #This sets the variable 'roll' to the gyroscope measurement of roll rounded to one place
		yaw = round(yaw, 1) #This sets the variable 'yaw' to the gyroscope measurement of yaw rounded to one place      
		print ("%s %s %s" % (pitch, roll, yaw)) 
		sense.set_pixels(less)
		Less() #If the MP3 Music Player is tilted right from a 90 degrees position with the screen facing the user the Less() function will run 
	if yaw < -threshold:	
		pitch = round(pitch, 1)
		roll = round(roll, 1)
		yaw = round(yaw, 1)      
		print ("%s %s %s" % (pitch, roll, yaw)) 
		sense.set_pixels(plus)
		Plus() #If the MP3 Music Player is tilted left from a 90 degrees position with the screen facing the user the Plus() function will run
	#Could be used to replicate other functionality
开发者ID:astro-pi,项目名称:mp3-player-using-gyros,代码行数:32,代码来源:AstroPi_MP3MusicPlayer.py

示例3: while

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_gyroscope_raw [as 别名]
start = time.time()
current = time.time()
i = 0
video = 0

#SET MAX LOG DURATION IN SECONDS
while (current-start) < 5:
	
	current = time.time()

	t = sense.get_temperature()
	p = sense.get_pressure()
	h = sense.get_humidity()
	pitch, roll, yaw = sense.get_orientation().values()
	xc, yc, zc = sense.get_compass_raw().values()
	xg, yg, zg = sense.get_gyroscope_raw().values()
	xa, ya, za = sense.get_accelerometer_raw().values()

	f = open('./hat-log/hat.csv', 'a', os.O_NONBLOCK)
	line = "%d, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f\n" % (1000*time.time(),t,p,h,pitch,roll,yaw,xc,yc,zc,xg,yg,zg,xa,ya,za)
	f.write(line)
	f.flush
	f.close()

	#set za threshold to the number of g you would expect at launch
	if video == 0 and (za > 1.1 or za < -1.1):
		video = 1
		call(["./video", ""])

	#print i
	i = i+1
开发者ID:JacopoPan,项目名称:oronos-payload,代码行数:33,代码来源:hat.py

示例4:

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_gyroscope_raw [as 别名]
    SH_orientation_z = SH_orientation.get('z')

    # Magnetometer data
    #sense.set_imu_config(True,False,False)
    time.sleep(0.01) # sleep for 10 ms after changing IMU configuration
    SH_compass_north = sense.get_compass()      # direction of magnetometer from North, in degrees
    SH_compass_raw = sense.get_compass_raw()    # magnetic intensity of x, y, z axes in microteslas
    SH_compass_raw_x = SH_compass_raw.get('x')
    SH_compass_raw_y = SH_compass_raw.get('y')
    SH_compass_raw_z = SH_compass_raw.get('z')

    # Gyro Data
    #sense.set_imu_config(False,True,False)
    time.sleep(0.01) # sleep for 10 ms after changing IMU configuration
    #SH_gyro = sense.get_gyroscope()             # orientation of pitch, roll, yaw axes in degrees
    SH_gyro_raw = sense.get_gyroscope_raw()     # rotational velocity of pitch, roll, yaw axes in radians per sec
    SH_gyro_raw_x = SH_gyro_raw.get('x')
    SH_gyro_raw_y = SH_gyro_raw.get('y')
    SH_gyro_raw_z = SH_gyro_raw.get('z')

    # Accelerometer data
    #sense.set_imu_config(False,False,True)
    time.sleep(0.01) # sleep for 10 ms after changing IMU configuration
    #SH_accel = sense.get_accelerometer()        # orientation of pitch, roll, yaw axes in degrees
    SH_accel_raw = sense.get_accelerometer_raw()    # acceleration intensity of pitch, roll, yaw axes in 'G's
    SH_accel_raw_x = SH_accel_raw.get('x')
    SH_accel_raw_y = SH_accel_raw.get('y')
    SH_accel_raw_z = SH_accel_raw.get('z')

    ## Readings from the BMP180 installed in the sealed box
    BMP_pressure = BMP_sensor.read_pressure()   # value in Pascals
开发者ID:Student-Space-Technology-Association,项目名称:ssta-hab3,代码行数:33,代码来源:hab3_sensors.py


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