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


Python SenseHat.get_orientation_radians方法代码示例

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


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

示例1: pi3d_model

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

    from sense_hat import SenseHat
    import math
    import pi3d

    sense = SenseHat()

    display = pi3d.Display.create()
    cam = pi3d.Camera.instance()

    shader = pi3d.Shader("mat_light")

    model = pi3d.Model(
        file_string="cow2.obj",
        name="model", x=0, y=-1, z=40, sx=2.5, sy=2.5, sz=2.5)

    model.set_shader(shader)

    cam.position((0, 20, 0))
    cam.point_at((0, -1, 40))
    keyb = pi3d.Keyboard()

    compass = gyro = accel = True
    sense.set_imu_config(compass, gyro, accel)

    yaw_offset = 0

    while display.loop_running():
        orientation = sense.get_orientation_radians()
        if orientation is None:
            pass

        pitch = orientation["pitch"]
        roll = orientation["roll"]
        yaw = orientation["yaw"]

        yaw_total = yaw + math.radians(yaw_offset)

        sin_y = math.sin(yaw_total)
        cos_y = math.cos(yaw_total)

        sin_p = math.sin(pitch)
        cos_p = math.cos(pitch)

        sin_r = math.sin(roll)
        cos_r = math.cos(roll)

        abs_roll = math.degrees(math.asin(sin_p * cos_y + cos_p * sin_r * sin_y))
        abs_pitch = math.degrees(math.asin(sin_p * sin_y - cos_p * sin_r * cos_y))

        model.rotateToZ(abs_roll)
        model.rotateToX(abs_pitch)
        model.rotateToY(math.degrees(yaw_total))
        model.draw()

        keypress = keyb.read()

        if keypress == 27:
            keyb.close()
            display.destroy()
            break
        elif keypress == ord('m'):
            compass = not compass
            sense.set_imu_config(compass, gyro, accel)
        elif keypress == ord('g'):
            gyro = not gyro
            sense.set_imu_config(compass, gyro, accel)
        elif keypress == ord('a'):
            accel = not accel
            sense.set_imu_config(compass, gyro, accel)
        elif keypress == ord('='):
            yaw_offset += 1
        elif keypress == ord('-'):
            yaw_offset -= 1
开发者ID:muku42,项目名称:initial-foray-into-raspberry-pi,代码行数:77,代码来源:cow_3d.py

示例2:

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_orientation_radians [as 别名]
cam.position((0, 20, 0))
cam.point_at((0, -1, 40))
keyb = pi3d.Keyboard()

compass = gyro = accel = True

#sense.set_imu_config(compass, gyro, accel)
sense.set_imu_config(False, True, False )
pitch=math.pi/4
roll=0
yaw=0
yaw_offset = 0

while display.loop_running():
    o = sense.get_orientation_radians()
    if o is None:
        pass

    pitch = o["pitch"]
    roll = o["roll"]
    yaw = o["yaw"]
    #roll +=math.pi/180
    yaw_total = yaw + math.radians(yaw_offset)

    sin_y = math.sin(yaw_total)
    cos_y = math.cos(yaw_total)

    sin_p = math.sin(pitch)
    cos_p = math.cos(pitch)
开发者ID:emailechiu,项目名称:emailechiu.github.io,代码行数:31,代码来源:soyuz.py

示例3: PiSenseHat

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

示例4: trunc

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_orientation_radians [as 别名]
	xi = trunc(x)
	xf = x- xi
	yi = trunc(y)
	yf = y - yi
	r = 1.0 - sqrt (xf*xf+yf*yf) / sqrt(2)
	sh.set_pixel (xi, yi, int(red[0] * r), int(red[1] * r), int(red[2] * r))
	r = 1.0 - sqrt (xf*xf+(1.0-yf)*(1.0-yf)) / sqrt(2)
	sh.set_pixel (xi, yi+1, int(red[0] * r), int(red[1] * r), int(red[2] * r))
	r = 1.0 - sqrt ((1.0-xf)*(1.0-xf)+yf*yf) / sqrt(2)
	sh.set_pixel (xi+1, yi, int(red[0] * r), int(red[1] * r), int(red[2] * r))
	r = 1.0 - sqrt ((1.0-xf)*(1.0-xf)+(1.0-yf)*(1.0-yf)) / sqrt(2)
	sh.set_pixel (xi+1, yi+1, int(red[0] * r), int(red[1] * r), int(red[2] * r))

	
while 1:
	orad = sh.get_orientation_radians()
#	print("p: {pitch}, r: {roll}, y: {yaw}".format(**orad))
	p = orad['pitch']
	r = orad['roll']
	y = orad['yaw']
	drawDot(-p*5.0 + 3.5, r*5.0 + 3.5)
#	print (r)
#	sleep(1)

#for a in range (0, 20):
#	sh.set_pixel (a, a, red)
#	sleep(1)
#	sh.clear()
#	drawDot (float(a+0.5),float(a+0.5))
#	drawDot (a*0.1 + 3, a*0.15 + 3)
#	sleep(1)
开发者ID:glouis14,项目名称:sensor-bike,代码行数:33,代码来源:SenseHat_tiltToMoveDot.py

示例5: pi3d_model

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

    from sense_hat import SenseHat
    import math
    import pi3d

    sense = SenseHat()

    display = pi3d.Display.create()
    cam = pi3d.Camera.instance()

    shader = pi3d.Shader("mat_light")

    # .obj file is read in and x,y,z size(s) are determined
    model = pi3d.Model(
        file_string="apollo-soyuz.obj",
        name="model", x=0, y=-1, z=40, sx=1.5, sy=1.5, sz=1.5)

    model.set_shader(shader)

    cam.position((0, 20, 0))
    cam.point_at((0, -1, 40))
    keyb = pi3d.Keyboard()

    compass = gyro = accel = True
    sense.set_imu_config(compass, gyro, accel)

    yaw_offset = 133 # This offset aligns the model with the Pi

    while display.loop_running():
        orientation = sense.get_orientation_radians()
        if orientation is None:
            pass

        pitch = orientation["pitch"]
        roll = orientation["roll"]
        yaw = orientation["yaw"]

        yaw_total = yaw + math.radians(yaw_offset)

        # Maths!
        sin_y = math.sin(yaw_total)
        cos_y = math.cos(yaw_total)

        sin_p = math.sin(pitch)
        cos_p = math.cos(pitch)

        sin_r = math.sin(roll)
        cos_r = math.cos(roll)

        abs_roll = math.degrees(math.asin(sin_p * cos_y + cos_p * sin_r * sin_y))
        abs_pitch = math.degrees(math.asin(sin_p * sin_y - cos_p * sin_r * cos_y))

        model.rotateToZ(abs_roll)
        model.rotateToX(abs_pitch)
        model.rotateToY(math.degrees(yaw_total))
        model.draw()

        keypress = keyb.read()

        if keypress == 27:
            keyb.close()
            display.destroy()
            break
        elif keypress == ord('m'): # Toggles Magnetometer
            compass = not compass
            sense.set_imu_config(compass, gyro, accel)
        elif keypress == ord('g'): # Toggles Gyroscope
            gyro = not gyro
            sense.set_imu_config(compass, gyro, accel)
        elif keypress == ord('a'): # Toggles Accelerometer
            accel = not accel
            sense.set_imu_config(compass, gyro, accel)
        elif keypress == ord('='): # Increases yaw offset
            yaw_offset += 1
        elif keypress == ord('-'): # Decreases yaw offset
            yaw_offset -= 1
开发者ID:muku42,项目名称:initial-foray-into-raspberry-pi,代码行数:79,代码来源:the_sense_hat_sampler.py


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