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


Python SenseHat.get_compass方法代码示例

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


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

示例1: root

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_compass [as 别名]
def root():
    sense = SenseHat()
    temp1 = sense.get_temperature()   
    temp2 = sense.get_temperature_from_pressure() 
    pressure = sense.get_pressure()
    north = sense.get_compass()
    accel_only = sense.get_accelerometer()
    acc_raw = sense.get_accelerometer_raw()
    temp = "Temp {:10.4f}".format(temp1) + " {:10.4f}".format(temp2) 
    other = "Pres {:10.4f}".format(pressure) + " Compas {:10.4f}".format(north)
    acc1 = "p: {pitch}, r: {roll}, y: {yaw}".format(**accel_only)
    acc2 = "x: {x}, y: {x}, z: {z}".format(**acc_raw)
    print temp + "\n" + other + "\n" + acc1 + "\n" + acc2 + "\n"
开发者ID:rtibell,项目名称:sens1,代码行数:15,代码来源:app1.py

示例2: SenseHat

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_compass [as 别名]
# The calibration program will produce the file RTIMULib.ini
# Copy it into the same folder as your Python code

led_loop = [4, 5, 6, 7, 15, 23, 31, 39, 47, 55, 63, 62, 61, 60, 59, 58, 57, 56, 48, 40, 32, 24, 16, 8, 0, 1, 2, 3]

sense = SenseHat()
sense.set_rotation(0)
sense.clear()

prev_x = 0
prev_y = 0

led_degree_ratio = len(led_loop) / 360.0

while True:
    dir = sense.get_compass()
    dir_inverted = 360 - dir  # So LED appears to follow North
    led_index = int(led_degree_ratio * dir_inverted)
    offset = led_loop[led_index]

    y = offset // 8  # row
    x = offset % 8  # column

    if x != prev_x or y != prev_y:
        sense.set_pixel(prev_x, prev_y, 0, 0, 0)

    sense.set_pixel(x, y, 0, 0, 255)

    prev_x = x
prev_y = y
开发者ID:ramesh-cit,项目名称:pi-python,代码行数:32,代码来源:compass.py

示例3: print

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_compass [as 别名]
# Creation des threads
#thread_telemeter = tw.Telemeter(TRIG,ECHO)
myranger = rt.ranger_thread(pi, TRIG, ECHO, 0.3)
#thread_logger = l.Logger(sense, myranger)
# Lancement des threads
myranger.start()
#thread_logger.start()

try:
	print("waiting initialization sensors")
	time.sleep(2)
	
	if ordre=="forward":
		Duration=parameter
		#front
		cap=round(sense.get_compass(),0)
		startcap=cap	
		t=time.time()
		while time.time() < t+Duration:
			ct.setcolor(sense,"forward")	
			mt.forwardto(sense,mymotors,LinearTolerance,cap,myranger)
		mymotors.stop()
		ct.setcolor(sense,"none")
		time.sleep(1)
	
	if ordre=="rotateby":
		deg=parameter
		#rotate 180
		ct.setcolor(sense,"turningby")
		mt.turnby(sense,mymotors,Tolerance,deg)
		mymotors.stop()
开发者ID:yaberry,项目名称:robotics,代码行数:33,代码来源:main.py

示例4: while

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


while (1 == 1) :
    print("%s Temperature" % sense.temp)
    print("%s Temp - humidity sensor" % sense.get_temperature_from_humidity())
    print("%s Temp - pressure sensor" % sense.get_temperature_from_pressure())
    print("%s Pressure: in Millibars" % sense.get_pressure())
    print("%s Humidity" % sense.get_humidity())

    north = sense.get_compass()
    print("%s Degrees to north" % north)

    raw = sense.get_accelerometer_raw()
    print("Acc intensity in Gs x: {x}, y: {y}, z: {z}".format(**raw))

    m = '%.1f' % sense.temp
    sense.show_message(m, text_colour=[255, 0, 0])
    print("*********")
    sense.set_pixels(question_mark)
    time.sleep(1)
    
开发者ID:Statoil,项目名称:happyeye,代码行数:31,代码来源:dumphatsensors.py

示例5:

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_compass [as 别名]
    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)
    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
开发者ID:Student-Space-Technology-Association,项目名称:ssta-hab3,代码行数:33,代码来源:hab3_sensors.py

示例6: sensors

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

示例7: SenseHat

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

sense = SenseHat()

while True:
    bearing = sense.get_compass()
    print('Bearing: {:.0f} to North'.format(bearing))
开发者ID:BASIC-TwoDot0,项目名称:raspberrypi_cookbook_ed2,代码行数:9,代码来源:sense_hat_compass.py

示例8: PiSenseHat

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_compass [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
开发者ID:santhoshmeda,项目名称:iot-310,代码行数:74,代码来源:sense.py

示例9: sensors

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

示例10: SenseHat

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

from sense_hat import SenseHat
from time import sleep

sh = SenseHat()

try:
    while True:
        north = sh.get_compass()
        north = round( north, 1 )

        print( "North = %s°" %(north) )

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


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