本文整理汇总了Python中sense_hat.SenseHat.set_imu_config方法的典型用法代码示例。如果您正苦于以下问题:Python SenseHat.set_imu_config方法的具体用法?Python SenseHat.set_imu_config怎么用?Python SenseHat.set_imu_config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sense_hat.SenseHat
的用法示例。
在下文中一共展示了SenseHat.set_imu_config方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_imu_config [as 别名]
class _SenseHat:
def __init__(self, board_object, colour=""):
self.board = board_object
self.colour = colour
self.sense = SenseHat()
def magnetometer_on(self):
self.sense.set_imu_config(True, False, False) # gyroscope only
@property
def temp_c(self):
return (self.sense.get_temperature_from_humidity() +
self.sense.get_temperature_from_pressure())/2
@property
def pressure(self):
return self.sense.pressure
@property
def humidity(self):
return self.sense.humidity
def led_all(self, colour):
lcd = []
for i in range(0, 64):
lcd.append(colour)
self.sense.set_pixels(lcd)
def led_1(self, colour):
self.sense.set_pixel(0, 0, colour)
self.sense.set_pixel(0, 1, colour)
self.sense.set_pixel(1, 0, colour)
self.sense.set_pixel(1, 1, colour)
def led_2(self, colour):
self.sense.set_pixel(2, 2, colour)
self.sense.set_pixel(2, 3, colour)
self.sense.set_pixel(3, 2, colour)
self.sense.set_pixel(3, 3, colour)
def led_3(self, colour):
self.sense.set_pixel(4, 4, colour)
self.sense.set_pixel(4, 5, colour)
self.sense.set_pixel(5, 4, colour)
self.sense.set_pixel(5, 5, colour)
def led_4(self, colour):
self.sense.set_pixel(6, 6, colour)
self.sense.set_pixel(6, 7, colour)
self.sense.set_pixel(7, 6, colour)
self.sense.set_pixel(7, 7, colour)
def clear(self):
self.sense.clear()
示例2: init
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_imu_config [as 别名]
def init():
global dsp_mtx
dsp_mtx = [
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0],
[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0]
]
sense = SenseHat()
sense.set_imu_config(False, False, True)
global sense
tt = threading.Thread(target=doit)
tt.daemon = True
tt.start()
print "start sleeping..."
time.sleep(64)
示例3: main
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_imu_config [as 别名]
def main():
cli = mosquitto.Mosquitto()
cli.on_message = on_message
cli.on_publish = on_publish
#cli.tls_set('root.ca',
#certfile='c1.crt',
#keyfile='c1.key')
#cli.username_pw_set("guigui", password="abloc")
cli.connect(config['host'], config['port'], config['keepalive'])
sense = SenseHat()
sense.set_imu_config(True, True, True)
d_sensors = all_sensors(sense)
while cli.loop() == 0:
#now = now_timestamp()
now = datetime.datetime.now(pytz.utc)
sensors = d_sensors.keys() # all sensors
#print(sensors)
for sensor in sensors:
get_value = d_sensors[sensor] # get a "callable"
#print(sensor, get_value)
data = {
'ts': now.isoformat(),
'd': {
sensor: get_value()
}
}
#print(data)
payload = json.dumps(data) # serialization
cli.publish(topic='/sensors/SenseHat01/%s' % sensor, payload=payload, qos=0, retain=False)
示例4: pi3d_model
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_imu_config [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
示例5:
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_imu_config [as 别名]
shader = pi3d.Shader("mat_light")
model = pi3d.Model(
file_string="apollo-soyuz.obj",
name="model", x=0, y=-1, z=40, sx=1, sy=1, sz=1)
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)
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)
示例6: SenseHat
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_imu_config [as 别名]
import ConfigParser
# New instance with 'bar' and 'baz' defaulting to 'Life' and 'hard' each
config = ConfigParser.ConfigParser()
config.read('/home/pi/ybot/ybot.cfg')
print config.get('Motors', 'MLA') # -> "Python is fun!"
print config.get('Ranger', 'TRIG') # -> "Life is hard!"
Tolerance = 5
LinearTolerance=2
sense = SenseHat()
#sense.set_imu_config(True, False, False) # magnet only
sense.set_imu_config(True, True, True)
#motors pins
MLA=5 #GRIS pin 29 M2 IN1
MLB=6 #BLANC pin 31 M2 IN2
MRA=16 #JAUNE pin 36 M1 IN1
MRB=26 #ORANGE pin 37 M1 IN2
#telemeter pins
TRIG = 17 #17 en pin
ECHO = 27 #27 en pin
#derive compensation
COMPENSATION_LEFT=1
COMPENSATION_RIGHT=1
示例7:
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_imu_config [as 别名]
original_pos_x = 0
original_pos_y = -1
original_pos_z = 40
model = pi3d.Model(
file_string="apollo-soyuz.obj",
name="model", x=original_pos_x, y=original_pos_y, z=original_pos_y, sx=1, sy=1, sz=1)
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 = 72
while display.loop_running():
o = sense.get_orientation_radians()
accraw = sense.get_accelerometer_raw()
acc_x = accraw["x"]* 2.0
acc_y = accraw["y"]* 2.0
acc_z = accraw["z"]* 2.0
if o is None:
pass
pitch = o["pitch"]
roll = o["roll"]
示例8:
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_imu_config [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
示例9: Accelerometer
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_imu_config [as 别名]
class Accelerometer(Thread):
def __init__(self, quantum, bin_logger):
Thread.__init__(self)
self.daemon = True
self.Sense = SenseHat()
self.Sense.set_imu_config(False, False, True)
self.cnt = 0
self.quantum = quantum
self.period = 0.01
self.iters = int(self.quantum / self.period)
self.que = Queue(1024)
self.dorun = True
self.acc_offset = 0
self.bin_logger = bin_logger
def run(self):
print("Calibrating...")
self.adjust()
print("Calibration done!")
while (self.dorun):
i = self.iters
max = -1000000000.0
min = 1000000000.0
sum = 0.0
acc_first = self.read_acc()
while (i > 0):
rd = self.read_acc()
av = self.get_adj_len()
sum = sum + av
if (max < av):
max = av
acc_max = rd
acc_max_i = (self.iters - i)
if (min > av):
min = av
acc_min = rd
acc_min_i = (self.iters - i)
i = i - 1
time.sleep
acc_last = self.read_acc()
ruck_avg = sqrt(pow(acc_first['x']-acc_last['x'], 2)+pow(acc_first['y']-acc_last['y'], 2)+pow(acc_first['z']-acc_last['z'], 2))/self.quantum
ruck_max = sqrt(pow(acc_max['x']-acc_min['x'], 2)+pow(acc_max['y']-acc_min['y'], 2)+pow(acc_max['z']-acc_min['z'], 2))/(abs(acc_min_i-acc_max_i)*self.period)
acc_dic = {'avg': (sum/float(self.iters)), 'min': min, 'max': max}
ruck_dic = {'avg': ruck_avg, 'max': ruck_max}
self.que.put([dt.datetime.now().strftime('%Y%m%d %H:%M.%S.%f'),
acc_dic, ruck_dic, acc_first, acc_last])
time.sleep(self.period)
def writeBinLog(self, entry):
if (self.bin_logger == None):
return
else:
self.bin_logger.putNext([dt.datetime.now().strftime('%Y%m%d %H:%M.%S.%f'), entry])
def adjust(self):
ac = 0.0
for i in range(0,100):
rd = self.read_acc()
av = self.get_len()
ac += av
self.acc_offset = ac/100.0
self.acc_offset *= 1.02
def read_acc(self):
a1 = self.Sense.get_accelerometer_raw()
self.writeBinLog(a1)
self.acc = a1
return a1
def get(self):
return [self.get_x(), self.get_y(), self.get_z()]
def get_x(self):
return self.acc['x']
def get_y(self):
return self.acc['y']
def get_z(self):
return self.acc['z']
def get_len(self):
self.Length = sqrt(pow(self.get_x(),2) + pow(self.get_y(),2) + pow(self.get_z(),2))
return self.Length
def get_adj_len(self):
return self.get_len()-self.acc_offset
def report(self):
print(self.get_x())
print(self.get_y())
print(self.get_z())
print(self.get())
print(self.get_len())
def stopit(self):
self.dorun = False
def getNext(self):
try:
#.........这里部分代码省略.........
示例10: SenseHat
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_imu_config [as 别名]
#! /usr/bin/env python
from sense_hat import SenseHat
from time import sleep
from math import *
sh = SenseHat()
sh.set_imu_config (True, True, True) # gyroscope only
#red = [255.0, 0.0, 0.0]
red = (255, 0, 0)
def drawDot (x, y):
sh.clear()
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))
示例11: PiSenseHat
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_imu_config [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
示例12: sensors
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_imu_config [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)
示例13: pi3d_model
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_imu_config [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
示例14:
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_imu_config [as 别名]
cam.position((10, 10, -10))
cam.point_at((0, 0, 0))
cam2d = pi3d.Camera(is_3d=False)
texture1=pi3d.Texture("worldmap.jpg")
texture2=pi3d.Texture("worldmap2.png")
texture3=pi3d.Texture("worldmap1.png")
shader = pi3d.Shader("uv_flat")
model = pi3d.Model( file_string="apollo-soyuz.obj",name="model", x=0, y=0, z=0, sx=0.5, sy=0.5, sz=0.5)
#model = pi3d.Model(file_string="models/teapot.obj",camera=cam,sx=2,sy=2,sz=2)
#model.set_draw_details(shader,[texture2,texture1])
model.set_shader(shader)
keyb = pi3d.Keyboard()
#model=pi3d.Sphere(z=0,sx=4,sy=4,sz=4)
#model=pi3d.Cuboid(4,5,6)
compass = gyro = accel = True
if sense!=0: sense.set_imu_config(compass, gyro, accel)
#yaw_offset = 72
#model.rotateToZ(-22.5)
while display.loop_running():
try:
o = sense.get_orientation_radians()
if o is None:
pass
pitch = o["pitch"]
roll = o["roll"]
yaw = o["yaw"]
except:
yaw =math.radians(-45) #around y axis
pitch =math.radians(0) #around x axis
示例15: SenseHat
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_imu_config [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):