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


Python SenseHat.get_orientation方法代码示例

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


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

示例1: __init__

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_orientation [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: getCurrentReading

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_orientation [as 别名]
def getCurrentReading():

    if (not readingSense.value):
        #   flag the sensehat as busy
        readingSense.value = True
        # get the new reading
        sense = SenseHat()
        orientation = sense.get_orientation()

        #   correct the pitch
        if (orientation['roll'] <= 90 or orientation['roll'] >= 270):
            orientation['pitch'] = 360 - orientation['pitch']
        else:
            orientation['pitch'] = orientation['pitch'] - 180
        
        #   generate the reading
        newReading = {
            'time' : datetime.now(),
            'temperature': round(sense.get_temperature(),1),
            'pressure': round(sense.get_pressure(),1),
            'humidity': round(sense.get_humidity(),1),
            'roll': round(orientation['roll'],1),
            'pitch': round(orientation['pitch'], 1),
            'yaw': round(orientation['yaw'],1)
        }

        #   remove all other readings from the currentReading list
        while (len(currentReading) > 0):
            currentReading.pop()
        
        #   save the current reading
        currentReading.append(newReading)
        #   flag the sensehat as not busy
        readingSense.value = False

    if (len(currentReading) > 0):
        return currentReading[0];
    else:
        return None
开发者ID:alex-cooke,项目名称:senserver,代码行数:41,代码来源:senserver.py

示例3: SenseHat

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_orientation [as 别名]
from sense_hat import SenseHat
import time
import datetime
from time import sleep
from guizero import App, Text, PushButton, Picture

sense = SenseHat()
sense.clear()
orientation=sense.get_orientation()
roll=orientation['roll']


e=(0,0,0)
w=(255,255,255)
r=(255,0,0)
a=(0,0,255)
y=(255,255,0)
o=(255,150,0)
c=(0,150,255)
g=(0,255,0)
dg=(0,125,0)
z=(200,170,120)
cb=(255,150,230)
pp=(170,0,255)
v=(150,100,50)

cold=[
e,e,e,e,e,w,e,e,
e,e,e,e,w,e,e,e,
e,e,e,w,e,e,e,w,
e,w,w,a,e,e,w,e,
开发者ID:Coding4Kids,项目名称:cidadeinteligente,代码行数:33,代码来源:PerfectCrops.py

示例4: check_wall

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_orientation [as 别名]
    return x,y

def check_wall(x,y,new_x,new_y):
    if maze[new_y][new_x] != r:
        return new_x, new_y
    elif maze[new_y][x] != r:
        return x, new_y
    elif maze[y][new_x] != r:
        return new_x, y
    else:
        return x,y

def check_win(x,y):
    global game_over
    if maze[y][x] == g:
        game_over = True
        sense.show_message('You Win')

while not game_over:
    pitch = sense.get_orientation()['pitch']
    roll = sense.get_orientation()['roll']
    x,y = move_marble(pitch,roll,x,y)
    check_win(x,y)
    maze[y][x] = w
    sense.set_pixels(sum(maze,[]))
    sleep(0.01)
    maze[y][x] = b

    

开发者ID:selukov,项目名称:sense-hat-marble-maze,代码行数:29,代码来源:marble-maze.py

示例5: SenseHat

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_orientation [as 别名]
#!/usr/bin/python

from sense_hat import SenseHat
import math

sense = SenseHat()

while True:

    # Get Pi's orientation
    pitch, yaw, roll = sense.get_orientation().values()
    pitch = round(pitch,1)
    yaw = round(yaw,1)
    roll = round(roll,1)

    # Convert degrees to radians (needed for sin(), cos())
    pitch_rad = math.radians(pitch)
    roll_rad = math.radians(roll)

    # Estimate a_gx, a_gy, a_gz from Pi's orientation
    a_gx = 1 * math.sin(roll_rad)
    a_gy = 1 * (-math.sin(pitch_rad))
    a_gz = 1 * math.cos(pitch_rad) * math.cos(roll_rad)

    # Round measurements
    a_gx = round(a_gx,5)
    a_gy = round(a_gy,5)
    a_gz = round(a_gz,5)

    # Get Pi's acceleration from accelerometer
    a_x, a_y, a_z = sense.get_accelerometer_raw().values()
开发者ID:jaimeferragut,项目名称:UnderwaterPi,代码行数:33,代码来源:decompose_acceleration.py

示例6: SenseHat

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_orientation [as 别名]
from sense_hat import SenseHat

sh = SenseHat()

from time import sleep

while True:
    p,r,y = sh.get_orientation().values()
    print("pitch=%s, roll=%s, yaw=%s" % (p,r,y))
    sleep(0.5)
开发者ID:jrgifford,项目名称:sense-hat,代码行数:12,代码来源:orientation.py

示例7:

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_orientation [as 别名]
# Main sensor polling loop
while True:
    # This time is used for logging purposes in the CSV data file
    data_time = time.strftime("%H:%M:%S",time.gmtime())

    ### Readings from the SenseHat
    ## Environment sensors
    SH_temp = sense.get_temperature()           # value in degrees C
    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)
开发者ID:Student-Space-Technology-Association,项目名称:ssta-hab3,代码行数:32,代码来源:hab3_sensors.py

示例8: sensors

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_orientation [as 别名]
class sensors(Thread):
    def __init__(self):
        Thread.__init__(self)
        self.daemon=True
        self.pitch = 0
        self.roll = 0
        self.yaw = 0
        self.compass= 10
        self.temp = 0
        self.humidity = 0
        self.pressure = 0
        self.ax = 0
        self.ay = 0
        self.az = 0
        self.altitude = 0
        # Comment if not running on RPI
        self.sense = SenseHat()
        self.sense.clear()
        self.sense.set_imu_config(True, True, True)

    def joinDelimiter(self, arr):
        tmp=[None]*len(arr)
        for i in range(len(arr)):
            tmp[i]=str(arr[i])
        return ",".join(tmp)

    def getRandomStrArr(self):
        pitch = r.randint(3, 5)
        roll = r.randint(3, 5)
        yaw = r.randint(0, 2)
        compass = r.randint(240, 241)
        temp = r.randint(19, 20)
        humidity = r.randint(43, 46)
        pressure = r.randint(983, 985)
        ax = 0.1
        ay = 0.1
        az = 0.1
        altitude = 286
        return self.joinDelimiter([pitch, roll, yaw, compass, temp, humidity, pressure, ax, ay, az, altitude])

    def run(self):
        while True:
            self.temp = round(self.sense.get_temperature(), 1)
            self.humidity = round(self.sense.get_humidity(), 1)
            self.pressure = round(self.sense.get_pressure(), 2)
            self.sense.set_imu_config(True, True, True)
            pitch, yaw, roll = self.sense.get_orientation().values()
            ax, ay, az = self.sense.get_accelerometer_raw().values()
            self.compass = round(self.sense.get_compass(), 2)
            self.pitch = round(pitch, 2)
            self.roll = round(roll, 2)
            if (self.pitch > 180):
                self.pitch -= 360
            if (self.roll > 180):
                self.roll -=  360
            self.yaw = round(yaw, 2)
            self.ax = round(ax, 2)
            self.ay = round(ay, 2)
            self.az = round(az, 2)
            self.altitude = round((288.15 / -0.0065) * ((self.pressure * 100 / 101325) ** (-(8.31432 * -0.0065) / (9.80665 * 0.0289644)) - 1),2)
            """
            self.pitch = r.randint(3, 5)
            self.roll = r.randint(3, 5)
            self.yaw = r.randint(0, 2)
            self.compass = r.randint(240, 241)
            self.temp = r.randint(19, 20)
            self.humidity = r.randint(43, 46)
            self.pressure = r.randint(983, 985)
            self.ax = 0.1
            self.ay = 0.1
            self.az = 0.1
            self.altitude = 286
            """
            time.sleep(REFRESH_DELAY)


    def getStrArr(self):
        return self.joinDelimiter([self.pitch, self.roll, self.yaw, self.compass, self.temp, self.humidity, self.pressure, self.ax, self.ay,
                                   self.az, self.altitude])
    def getTuple(self):
        return (self.getStrArr(),'')
开发者ID:jeryfast,项目名称:piflyer,代码行数:83,代码来源:sensors.py

示例9: SenseHat

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_orientation [as 别名]
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from sense_hat import SenseHat
from time import sleep

sh = SenseHat()

try:
    while True:
        pitch, roll, yaw = sh.get_orientation().values()

        pitch = round( pitch, 1 )
        roll = round( roll, 1 )
        yaw = round( yaw, 1 )

        print( "Pitch = %s°    Roll = %s°    Yaw = %s°" %(pitch, roll, yaw) )

except KeyboardInterrupt:
    print( "Exiting..." );
开发者ID:fvdbosch,项目名称:PiIoT,代码行数:22,代码来源:motion.py

示例10: print

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_orientation [as 别名]
from sense_hat import SenseHat
from time import strftime
import datetime
sense=SenseHat()
#sense.show_message("running sensors",scroll_speed=0.01)
print('#Time,pitch(deg),roll(deg),yaw(deg),X-Acceleration(g),Y-Acceleration(g),Z-Acceleration(g),Pressure(Millibars),Temperature(deg C),Humidity(%)')
t0=datetime.datetime.now()
while(True):
    pitch,roll,yaw=(ii if ii <180.0 else ii-360.0 for ii in sense.get_orientation().values())#rotations
    #print(list(sense.get_orientation().values())) 
    ax,ay,az=sense.get_accelerometer_raw().values() #accelerations
    p=sense.get_pressure() # pressure
    t=sense.get_temperature() #temperature
    h=sense.get_humidity() #humidity
    delta=datetime.datetime.now()-t0
    #print(type(delta))
    outputs=(delta.total_seconds(),pitch,roll,yaw,ax,ay,az,p,t,h)
    print(','.join('{:5.3f}'.format(ii) for ii in outputs))
开发者ID:lpashwin,项目名称:SenseHat_data_acquisition,代码行数:20,代码来源:sensor_Data.py

示例11: SenseHat_Adapter

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_orientation [as 别名]
class SenseHat_Adapter (adapter.adapters.Adapter):
    """Interface to SenseHat-Adapter using SenseHat-Library """

    mandatoryParameters = { 'poll.interval': '0.1' }

    
    def __init__(self):
        adapter.adapters.Adapter.__init__(self)
        
        self.pixel_Color = self.getRGBFromString('default')  
        self.pixel_X = 0
        self.pixel_Y = 0

    def setActive (self, active):
        if active:
            self.sense = SenseHat() 
            adapter.adapters.Adapter.setActive(self, active)
        else:
            adapter.adapters.Adapter.setActive(self, active)
            self.sense = None
     
    def run(self):
        if debug:
            print("thread started")
        _del = float(self.parameters['poll.interval'])
        
        last_temperature = None
        last_pressure = None
        last_humidity = None
        
        last_orientation_pitch = None
        last_orientation_yaw = None
        last_orientation_roll = None
        #
        # the float values are all different in each send cycle
        # to allow some reduction in value sending, the values are 
        # converted to string and reduced to 2 digital points
        #
        formatString = "{:.1f}"
        
        while not self.stopped():
            #
            # delay 5 sec, but break time in small junks to allow stopping fast
            #
            self.delay(_del)   

            value = self.sense.get_temperature()
            sValue = formatString.format(value)
            if sValue != last_temperature:
                last_temperature = sValue
                self.temperature(sValue) 
            
            value = self.sense.get_pressure()
            sValue = formatString.format(value)
            if sValue != last_pressure:
                last_pressure = sValue
                self.pressure(sValue) 
            
            value = self.sense.get_humidity()
            sValue = formatString.format(value)
            if sValue != last_humidity:
                last_humidity = sValue
                self.humidity(sValue) 
                
            orientation = self.sense.get_orientation()
            
            value = orientation['pitch']
            sValue = formatString.format(value)
            if sValue != last_orientation_pitch:
                last_orientation_pitch = sValue
                self.orientation_pitch(sValue) 
            
            value = orientation['yaw']
            sValue = formatString.format(value)
            if sValue != last_orientation_yaw:
                last_orientation_yaw = sValue
                self.orientation_yaw(sValue) 
            
            value = orientation['roll']
            sValue = formatString.format(value)
            if sValue != last_orientation_roll:
                last_orientation_roll = sValue
                self.orientation_roll(sValue) 
                
    #
    # values from adapter to scratch
    #
    def temperature(self, value):
        """output from adapter to scratch"""
        self.sendValue(value)

    def pressure(self, value):
        """output from adapter to scratch"""
        self.sendValue(value)

    def humidity(self, value):
        """output from adapter to scratch"""
        self.sendValue(value)

    def orientation_pitch(self, value):
#.........这里部分代码省略.........
开发者ID:Naohiro2g,项目名称:scratchClient,代码行数:103,代码来源:senseHat_adapter.py

示例12: SenseHat

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_orientation [as 别名]
i = [] #Define list needed for the plot.
s = []
v = []
w = []
x = [] 
y = []
z = []
angular = 0 #Initial value of the angular displacement.
count = 0
snooze = 2 #Time in seconds for the time.sleep().
velocity = 0

while True:
  try:
    sense = SenseHat()
    orientation = sense.get_orientation() #Reads orientation from SenseHAT.
    xaxis = round(orientation["roll"], 2)
    yaxis = round(orientation["pitch"], 2)
    zaxis = round(orientation["yaw"], 2)
    count += 1
    
    i.append(count) #Updates list for the plot.
    x.append(xaxis)
    y.append(yaxis)
    z.append(zaxis)

    if count >=2: #Calculates the angular displacement, at least two data points are needed.
      angular = round(((x[count-1]-x[count-2])**(2) + (y[count-1]-y[count-2])**(2) + (z[count-1]-z[count-2])**(2))**(0.5), 2)
    w.append(angular)

    velocity = round(angular/snooze, 2) #Calculates the angular velocity.
开发者ID:IkerGarcia,项目名称:DashboardPi,代码行数:33,代码来源:DashboardPi.py

示例13: sensors

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_orientation [as 别名]
class sensors():
    def __init__(self):
        self.pitch = 0
        self.roll = 0
        self.yaw = 0
        self.heading = 10
        self.temp = 0
        self.humidity = 0
        self.pressure = 0
        self.ax = 0
        self.ay = 0
        self.az = 0
        self.altitude = 0
        self.send_timer=0

    def joinDelimiter(self, arr):
        tmp=[None]*len(arr)
        for i in range(len(arr)):
            tmp[i]=str(arr[i])
        return ",".join(tmp)

    def getRandomStrArr(self):
        pitch = r.randint(3, 5)
        roll = r.randint(3, 5)
        yaw = r.randint(0, 2)
        compass = r.randint(240, 241)
        temp = r.randint(19, 20)
        humidity = r.randint(43, 46)
        pressure = r.randint(983, 985)
        ax = 0.1
        ay = 0.1
        az = 0.1
        altitude = 286
        return self.joinDelimiter([pitch, roll, yaw, compass, temp, humidity, pressure, ax, ay, az, altitude])

    def run(self):
        # Comment if not running on RPI
        self.sense = SenseHat()
        self.sense.clear()
        self.sense.set_imu_config(True, True, True)

        while True:
            self.temp = round(self.sense.get_temperature(), 1)
            self.humidity = round(self.sense.get_humidity(), 1)
            self.pressure = round(self.sense.get_pressure(), 1)
            self.sense.set_imu_config(True, True, True)
            orientation = self.sense.get_orientation()
            pitch = orientation['pitch']
            roll = orientation['roll']
            yaw = orientation['yaw']
            ax, ay, az = self.sense.get_accelerometer_raw().values()
            self.heading = round(self.sense.get_compass(), 1)
            if (pitch > 180):
                pitch -= 360
            self.pitch = round(pitch, 1)
            self.roll = round(roll, 1)
            self.yaw = round(yaw, 1)
            self.ax = round(ax, 2)
            self.ay = round(ay, 2)
            self.az = round(az, 2)
            self.altitude = round((288.15 / -0.0065) * ((self.pressure * 100 / 101325) ** (-(8.31432 * -0.0065) / (9.80665 * 0.0289644)) - 1),1)
            """
            self.pitch = r.randint(3, 5)
            self.roll = r.randint(3, 5)
            self.yaw = r.randint(0, 2)
            self.compass = r.randint(240, 241)
            self.temp = r.randint(19, 20)
            self.humidity = r.randint(43, 46)
            self.pressure = r.randint(983, 985)
            self.ax = 0.1
            self.ay = 0.1
            self.az = 0.1
            self.altitude = 286
            """

            # sensors must initialize
            try:
                t=time.time()
                if(time.time()-self.send_timer>delays.BROWSER):
                    sensors_publisher.send_string("%s %s" % (topic.SENSOR_TOPIC, self.getString()))
                    self.send_timer=t
                #print(time.time()-t)
            except:
                print("sensors error")

            time.sleep(delays.SENSOR_REFRESH_DELAY)

    def getString(self):
        return self.joinDelimiter([self.pitch, self.roll, self.yaw, self.heading, self.temp, self.humidity, self.pressure, self.ax, self.ay,
                                   self.az, self.altitude])

    # Update values if instance not doint reading with run()
    def setValues(self,string):
        self.pitch, self.roll, self.yaw, self.heading, self.temp, self.humidity, \
        self.pressure, self.ax, self.ay, self.az, self.altitude = [float(x) for x in string.split(',')]
        if (self.roll > 180):
            self.roll=round(self.roll - 360,1)
开发者ID:jeryfast,项目名称:piflyer,代码行数:99,代码来源:zmq_sensors.py


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