本文整理汇总了Python中sense_hat.SenseHat.get_orientation_degrees方法的典型用法代码示例。如果您正苦于以下问题:Python SenseHat.get_orientation_degrees方法的具体用法?Python SenseHat.get_orientation_degrees怎么用?Python SenseHat.get_orientation_degrees使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sense_hat.SenseHat
的用法示例。
在下文中一共展示了SenseHat.get_orientation_degrees方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gyroGame
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_orientation_degrees [as 别名]
def gyroGame(maxDegs):
sense = SenseHat()
while 1:
orientation = sense.get_orientation_degrees()
if orientation['pitch'] < maxDegs:
realpitch=orientation['pitch']
else:
realpitch=-1*(360-orientation['pitch'])
if orientation['roll'] < maxDegs:
realroll=orientation['roll']
else:
realroll=-1*(360-orientation['roll'])
x_pos=7-int(round(((maxDegs+realpitch)/(2.0*maxDegs))*8.0,0))
y_pos=int(round(((maxDegs+realroll)/(2.0*maxDegs))*8.0,0))
if x_pos > 7:
x_pos = 7
if x_pos < 0:
x_pos = 0
if y_pos > 7:
y_pos = 7
if y_pos < 0:
y_pos = 0
sense.clear()
if (1 <= x_pos <=6) and (1 <= y_pos <=6):
sense.set_pixel(x_pos,y_pos,0,0,255)
else:
sense.set_pixel(x_pos,y_pos,255,0,0)
示例2: Start
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_orientation_degrees [as 别名]
def Start():
sense=SenseHat()
rospy.init_node('sense_hat', anonymous=True)
#TODO
#temp_pub = rospy.Publisher("/sensehat/temperature", Temperature, queue_size= 10)
#humidity_pub = rospy.Publisher("/sensehat/humidity", RelativeHumidity, queue_size= 10)
pose_pub = rospy.Publisher("/sensehat/pose", Imu, queue_size= 10)
compass_pub = rospy.Publisher("/sensehat/compass", MagneticField, queue_size=10)
r = rospy.Rate(10) # 10hz
while not rospy.is_shutdown():
gyro = Imu()
gyro.angular_velocity.x = sense.get_gyroscope()['pitch']
gyro.angular_velocity.y = sense.get_gyroscope()['roll']
gyro.angular_velocity.z = sense.get_gyroscope()['yaw']
gyro.orientation.x = sense.get_orientation_degrees()['pitch']
gyro.orientation.y = sense.get_orientation_degrees()['roll']
gyro.orientation.z = sense.get_orientation_degrees()['yaw']
gyro.linear_acceleration.x = sense.get_accelerometer_raw()['x']
gyro.linear_acceleration.y = sense.get_accelerometer_raw()['y']
gyro.linear_acceleration.z = sense.get_accelerometer_raw()['z']
#rospy.loginfo("Sending IMU data:%s", gyro)
r.sleep()
示例3: SenseHat
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_orientation_degrees [as 别名]
from sense_hat import SenseHat
from time import sleep
import math
sense = SenseHat()
sense.set_imu_config(False, False, True)
#start by setting a "level" state
base_level=sense.get_orientation_degrees()
base_pitch=base_level['pitch']
base_roll=base_level['roll']
#base_yaw=base_level['yaw']
bx=3
by=4
diffV=1
X=[255,100,0]
S=[0,0,0]
field=[S]*64
while(True):
orien = sense.get_orientation_degrees()
pdiff=orien['pitch']-base_pitch
rdiff=orien['roll']-base_roll
print '{} {} {}'.format(orien['pitch'],base_pitch,pdiff)
print '{} {} {}'.format(orien['roll'],base_roll,rdiff)
#print '{} {}'.format(orien['yaw'],base_yaw)
print'######################################'
if(pdiff> diffV):
if(bx>0):
bx-=1
elif(pdiff < -diffV):
if(bx<7):
bx+=1
if(rdiff >diffV):
示例4: round
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_orientation_degrees [as 别名]
oldZAceleration=0
m_x_old=0
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)
示例5: count
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_orientation_degrees [as 别名]
#sense.show_message("*",scroll_speed=0.05)
tmp_res = json.loads(getData("http://localhost:9090/cmd","select count(*) from collect"))
now_count = str(tmp_res['Content']['content'])
sense.show_message( now_count[2:-2] + " rows", scroll_speed=0.05)
sense.load_image("logo8.png")
sense.set_pixel(7, 6, 20*(count%10)+50, 110, 20*(count%10)+50)
sense.set_pixel(7, 7, 20*(count%10)+50, 110, 20*(count%10)+50)
sense.set_pixel(6, 6, 20*(count%10)+50, 110, 20*(count%10)+50)
sense.set_pixel(6, 7, 20*(count%10)+50, 110, 20*(count%10)+50)
humidity = sense.get_humidity()
temp = sense.get_temperature()
pressure = sense.get_pressure()
orientation = sense.get_orientation_degrees()
pitch = orientation['pitch']
roll = orientation['roll']
yaw = orientation['yaw']
acceleration = sense.get_accelerometer_raw()
acc_x = acceleration['x']
acc_y = acceleration['y']
acc_z = acceleration['z']
#now = strftime("%Y-%m-%d %H:%M:%S", gmtime())
now = strftime("%Y-%m-%d %H:%M:%S", localtime())
stmt = "insert into collect values('" + now + "','"
stmt = stmt + str(humidity) + "','" + str(temp) + "','" + str(pressure) + "','" + str(pitch)
stmt = stmt + "','" + str(roll) + "','" + str(yaw) + "','" + str(acc_x)
stmt = stmt + "','" + str(acc_y) + "','" + str(acc_z) + "')"
示例6: SenseHat
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_orientation_degrees [as 别名]
#!/usr/bin/python
import sys
import json
from sense_hat import SenseHat
sense = SenseHat()
print json.dumps(sense.get_orientation_degrees())
示例7: PiSenseHat
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_orientation_degrees [as 别名]
class PiSenseHat(object):
"""Raspberry Pi 'IoT Sense Hat API Driver Class'."""
# Constructor
def __init__(self):
self.sense = SenseHat()
# enable all IMU functions
self.sense.set_imu_config(True, True, True)
# pixel display
def set_pixel(self,x,y,color):
# red = (255, 0, 0)
# green = (0, 255, 0)
# blue = (0, 0, 255)
self.sense.set_pixel(x, y, color)
# clear pixel display
def clear_display(self):
self.sense.clear()
# Pressure
def getPressure(self):
return self.sense.get_pressure()
# Temperature
def getTemperature(self):
return self.sense.get_temperature()
# Humidity
def getHumidity(self):
return self.sense.get_humidity()
def getHumidityTemperature(self):
return self.sense.get_temperature_from_humidity()
def getPressureTemperature(self):
return self.sense.get_temperature_from_pressure()
def getOrientationRadians(self):
return self.sense.get_orientation_radians()
def getOrientationDegrees(self):
return self.sense.get_orientation_degrees()
# degrees from North
def getCompass(self):
return self.sense.get_compass()
def getAccelerometer(self):
return self.sense.get_accelerometer_raw()
def getEnvironmental(self):
sensors = {'name' : 'sense-hat', 'environmental':{}}
return sensors
def getJoystick(self):
sensors = {'name' : 'sense-hat', 'joystick':{}}
return sensors
def getInertial(self):
sensors = {'name' : 'sense-hat', 'inertial':{}}
def getAllSensors(self):
sensors = {'name' : 'sense-hat', 'environmental':{}, 'inertial':{}, 'joystick':{}}
sensors['environmental']['pressure'] = { 'value':self.sense.get_pressure(), 'unit':'mbar'}
sensors['environmental']['temperature'] = { 'value':self.sense.get_temperature(), 'unit':'C'}
sensors['environmental']['humidity'] = { 'value':self.sense.get_humidity(), 'unit': '%RH'}
accel = self.sense.get_accelerometer_raw()
sensors['inertial']['accelerometer'] = { 'x':accel['x'], 'y':accel['y'], 'z': accel['z'], 'unit':'g'}
orientation = self.sense.get_orientation_degrees()
sensors['inertial']['orientation'] = { 'compass':self.sense.get_compass(), 'pitch':orientation['pitch'], 'roll':orientation['roll'], 'yaw': orientation['yaw'], 'unit':'degrees'}
return sensors