本文整理汇总了Python中sense_hat.SenseHat.get_compass_raw方法的典型用法代码示例。如果您正苦于以下问题:Python SenseHat.get_compass_raw方法的具体用法?Python SenseHat.get_compass_raw怎么用?Python SenseHat.get_compass_raw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sense_hat.SenseHat
的用法示例。
在下文中一共展示了SenseHat.get_compass_raw方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sense_data
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_compass_raw [as 别名]
def sense_data():
sense = SenseHat()
comx, comy, comz = sense.get_compass_raw().values()
accx, accy, accz = sense.get_accelerometer_raw().values()
gyrox, gyroy, gyroz = sense.get_accelerometer_raw().values()
temperature = sense.get_temperature_from_humidity()
humidity = sense.get_humidity()
pressure = sense.get_pressure()
timestamp = datetime.now().isoformat()
if accy > 0.1 :
drop_flg = 1
else:
drop_flg = 0
message = { "deviceid": deviceid, \
"timestamp" : timestamp, \
"temperature" : temperature, \
"humidity" : humidity, \
"pressure" : pressure, \
"comx" : comx, \
"comy" : comy, \
"comz" : comz, \
"gyrox" : gyrox, \
"gyroy" : gyroy, \
"gyroz" : gyroz, \
"accx" : accx, \
"accy" : accy, \
"accz" : accz, \
"drop" : drop_flg
}
print accx, accy, accz, drop_flg
return message
示例2: __init__
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_compass_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
示例3: round
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_compass_raw [as 别名]
m_y_old=0
m_z_old=0
oldYaw=0
oldNorma=0
oldNormaW=0
while True:
temperature = sense.get_temperature()
pressure = sense.get_pressure()
humidity = sense.get_humidity()
pitch, roll, yaw = sense.get_orientation_degrees().values()
x, y, z = sense.get_accelerometer_raw().values()
m_x, m_y, m_z = sense.get_compass_raw().values()
# Rotation
pitch = round(pitch, 3)
roll = round(roll, 3)
yaw = round(yaw, 3)
# Enviromental
temperature = round(temperature, 1)
pressure = round(pressure, 1)
humidity = round(humidity, 1)
# Accelerometer
示例4: SenseHat
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_compass_raw [as 别名]
import time
import datetime
from sense_hat import SenseHat
sense = SenseHat()
red = (255, 0, 0)
blue = (0, 0, 255)
while True:
temp = sense.get_temperature()
humidity = sense.get_humidity()
pressure = sense.get_pressure()
gyro = sense.get_gyroscope()
rawMag = sense.get_compass_raw()
timestamp = time.ctime()
accel_only = sense.get_accelerometer()
north = sense.get_compass()
print("____________________________________________________________________")
print("Temperature: %s C" % temp)
print("Humidity: %s %%rH" % humidity)
print("Pressure: %s Millibars" % pressure)
print("North: %s" % north)
print("Magnetometer x: {x}, y: {y}, z: {z}".format(**rawMag))
print("Gyro: p: {pitch}, r: {roll}, y: {yaw}".format(**gyro))
print("Accel: p: {pitch}, r: {roll}, y: {yaw}".format(**accel_only))
log_record = "%s : temp=%s humidity=%s pressure=%s gyro=%s accel=%s mag=%s" % (
timestamp,
示例5: while
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_compass_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
示例6:
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_compass_raw [as 别名]
SH_pressure = sense.get_pressure() * 100 # convert output from millibars to Pascals for consistency
SH_humidity = sense.get_humidity() # % relative humidity
# Orientation
sense.set_imu_config(True,True,True) # Enable compass, gyro, and accelerometer
SH_orientation = sense.get_orientation() # orientation of pitch, roll, yaw axes in degrees
SH_orientation_x = SH_orientation.get('x')
SH_orientation_y = SH_orientation.get('y')
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)
示例7: SenseHat
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_compass_raw [as 别名]
from sense_hat import SenseHat
import time
hat = SenseHat()
fill = (255, 0, 0)
while True:
reading = int(hat.get_compass_raw()['z'])
if reading > 200:
hat.clear(fill)
time.sleep(0.2)
else:
hat.clear()