本文整理汇总了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
示例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
示例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
示例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