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


Python SenseHat.get_accelerometer_raw方法代码示例

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


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

示例1: VibrateSensor

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_accelerometer_raw [as 别名]
class VibrateSensor(object):
    """Vibration Sensor"""

    def __init__(self):
        from sense_hat import SenseHat
        self.movement_threshold = 0.05
        self.sensor = SenseHat()
        self.current_reading = self.sensor.get_accelerometer_raw()
        self.last_reading = self.current_reading

    def read_sensor(self):
        """Set last_reading to prevous sensor reading, and read again"""
        self.last_reading = self.current_reading
        self.current_reading = self.sensor.get_accelerometer_raw()

    def motion_detected(self):
        """Returns True if there has been movement since the last read"""
        self.read_sensor()
        x_movement = abs(self.last_reading['x'] - self.current_reading['x'])
        y_movement = abs(self.last_reading['y'] - self.current_reading['y'])
        z_movement = abs(self.last_reading['z'] - self.current_reading['z'])
        if (x_movement > self.movement_threshold) \
                or (y_movement > self.movement_threshold) \
                or (z_movement > self.movement_threshold):
            return True
        else:
            return False
开发者ID:gdfuego,项目名称:pybrate,代码行数:29,代码来源:pybrate.py

示例2: sense_data

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_accelerometer_raw [as 别名]
def sense_data():
    sense = SenseHat()
    comx, comy, comz = sense.get_compass_raw().values()
    accx, accy, accz = sense.get_accelerometer_raw().values()
    gyrox, gyroy, gyroz = sense.get_accelerometer_raw().values()
    temperature = sense.get_temperature_from_humidity()
    humidity = sense.get_humidity()
    pressure = sense.get_pressure()

    timestamp = datetime.now().isoformat()

    if accy > 0.1 :
        drop_flg = 1
    else:
        drop_flg = 0
            

    message = { "deviceid": deviceid, \
                "timestamp" : timestamp, \
                "temperature" : temperature, \
                "humidity" : humidity, \
                "pressure" : pressure, \
                "comx" : comx, \
                "comy" : comy, \
                "comz" : comz, \
                "gyrox" : gyrox, \
                "gyroy" : gyroy, \
                "gyroz" : gyroz, \
                "accx" : accx, \
                "accy" : accy, \
                "accz" : accz, \
                "drop" : drop_flg
                 }
    print accx, accy, accz, drop_flg
    return message
开发者ID:aquaviter,项目名称:sko2015-hackathon,代码行数:37,代码来源:sensor.py

示例3: menu

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_accelerometer_raw [as 别名]
        def menu():
            global sense, time1, time2, r, t, m, w, k, a, b, elapsed
            sense = SenseHat()
            
            sense.set_rotation(180)
            sense.clear()
            sense.set_pixels(imagemenu)
            
            sense.stick.get_events()
            while True:
                print (" new game1",a," ",b)
                y1 = sense.get_accelerometer_raw()['y']
                y1 = round(y1, 0)

                if y1 == -1:
                    sense.show_message("Highscore '%s'"% (h))
                    sense.set_pixels(imagemenu)
                for event in sense.stick.get_events():
                    if event.action == "pressed" and event.direction == "middle":
                        elapsed = timedelta(seconds=0)
                        sense.set_rotation(180)
                        sense.stick.direction_up = move_up
                        sense.stick.direction_down = move_down
                        sense.stick.direction_right = move_right
                        sense.stick.direction_left = move_left
                        x=0
                        y=0
                        time1 = datetime.now()
                        print(elapsed, " elapsed and e ", e)
                        while elapsed < e:
                            sense.clear()
                            draw_player()
                            test = draw_enemy(x, y)
                            print("menu nivel1 ",test)
                            if test == 1:
                                new_game()
                                break
                            sleep(0.25)
                            y = y+1
                            if y > 7:
                                r = randint(0,7)
                                t = randint(0,7)
                                m = randint(0,7)
                                y = 0
                            x = x+1
                            if x > 7:
                                w = randint(0,7)
                                k = randint(0,7)
                                x = 0
                        if elapsed > e:
                                sense.show_message("Next level", scroll_speed=0.05)
                                sense.set_pixels(imagesmile)
                                sleep(1)
                                level_2(x,y)
                                new_game()
                                break
                    if event.action == "pressed" and (event.direction == "up" or event.direction == "down" or event.direction == "left" or event.direction == "right"):
                        return
开发者ID:Coding4Kids,项目名称:cidadeinteligente,代码行数:60,代码来源:FugaAosQuadrados.py

示例4: __init__

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

示例5: root

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

示例6: Start

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_accelerometer_raw [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()
开发者ID:keshavchintamani,项目名称:triniBot,代码行数:24,代码来源:sensehat_publisher.py

示例7: main

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_accelerometer_raw [as 别名]
def main():
    sense = SenseHat()
    color = (255, 0, 0)
    prev_x = -1
    prev_y = -1
    while True:
        acc = sense.get_accelerometer_raw()
        x = round(limit(-10 * acc['x'] + 3))
        y = round(limit(-10 * acc['y'] + 3))
        if x != prev_x or y != prev_y:
            sense.clear()
        sense.set_pixel(x, y, *color)
        prev_x = x
        prev_y = y
        time.sleep(0.08)
开发者ID:RaspberryPi-Samples,项目名称:SenseHat-samples,代码行数:17,代码来源:main.py

示例8: while

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

示例9: radians

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

    # Round measurements
    a_x = round(a_x,5)
    a_y = round(a_y,5)
    a_z = round(a_z,5)
    
    # Compute user acceleration
    A_x = a_x-a_gx
    A_y = a_y-a_gy
    A_z = a_z-a_gz

    # Round measurements
    A_x = round(A_x,0)
    A_y = round(A_y,0)
    A_z = round(A_z,0)
开发者ID:jaimeferragut,项目名称:UnderwaterPi,代码行数:33,代码来源:decompose_acceleration.py

示例10: SenseHat

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

from sense_hat import SenseHat

sense = SenseHat()

sense.show_letter("J")

while True:
    x = sense.get_accelerometer_raw()['x']
    y = sense.get_accelerometer_raw()['y']
    z = sense.get_accelerometer_raw()['z']

    x = round(x, 0)
    y = round(y, 0)

    if x == -1:
        sense.set_rotation(180)
    elif y == 1:
        sense.set_rotation(90)
    elif y == -1:
        sense.set_rotation(270)
    else:
        sense.set_rotation(0)

开发者ID:ericosur,项目名称:ericosur-snippet,代码行数:26,代码来源:rot_letter.py

示例11: while

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_accelerometer_raw [as 别名]
start = time.time()
current = time.time()
i = 0
video = 0

#SET MAX LOG DURATION IN SECONDS
while (current-start) < 5:
	
	current = time.time()

	t = sense.get_temperature()
	p = sense.get_pressure()
	h = sense.get_humidity()
	pitch, roll, yaw = sense.get_orientation().values()
	xc, yc, zc = sense.get_compass_raw().values()
	xg, yg, zg = sense.get_gyroscope_raw().values()
	xa, ya, za = sense.get_accelerometer_raw().values()

	f = open('./hat-log/hat.csv', 'a', os.O_NONBLOCK)
	line = "%d, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f\n" % (1000*time.time(),t,p,h,pitch,roll,yaw,xc,yc,zc,xg,yg,zg,xa,ya,za)
	f.write(line)
	f.flush
	f.close()

	#set za threshold to the number of g you would expect at launch
	if video == 0 and (za > 1.1 or za < -1.1):
		video = 1
		call(["./video", ""])

	#print i
	i = i+1
开发者ID:JacopoPan,项目名称:oronos-payload,代码行数:33,代码来源:hat.py

示例12: print

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_accelerometer_raw [as 别名]
arrow = [
e,e,e,w,w,e,e,e,
e,e,w,w,w,w,e,e,
e,w,e,w,w,e,w,e,
w,e,e,w,w,e,e,w,
e,e,e,w,w,e,e,e,
e,e,e,w,w,e,e,e,
e,e,e,w,w,e,e,e,
e,e,e,w,w,e,e,e
]

# Print it once
sh.set_pixels(arrow)

while True:
    x_full, y_full, z_full = sh.get_accelerometer_raw().values()

    x=round(x_full, 0)
    y=round(y_full, 0)
    z=round(z_full, 0)

    print ("x=%s, y=%s, z=%s" % (x_full,y_full,z_full))

    if x == -1:  # works
        sh.set_pixels(arrow)
        sh.set_rotation(180)
    elif x == 1: # works
        sh.set_pixels(arrow)
        sh.set_rotation(0)
        
    elif y == 1: 
开发者ID:jrgifford,项目名称:sense-hat,代码行数:33,代码来源:rotating_letter.py

示例13:

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_accelerometer_raw [as 别名]
    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
    #sense.set_imu_config(False,False,True)
    time.sleep(0.01) # sleep for 10 ms after changing IMU configuration
    #SH_accel = sense.get_accelerometer()        # orientation of pitch, roll, yaw axes in degrees
    SH_accel_raw = sense.get_accelerometer_raw()    # acceleration intensity of pitch, roll, yaw axes in 'G's
    SH_accel_raw_x = SH_accel_raw.get('x')
    SH_accel_raw_y = SH_accel_raw.get('y')
    SH_accel_raw_z = SH_accel_raw.get('z')

    ## Readings from the BMP180 installed in the sealed box
    BMP_pressure = BMP_sensor.read_pressure()   # value in Pascals
    BMP_temp = BMP_sensor.read_temperature()    # value in degrees C

    # Altitude readings
    BMP_prev_alt = BMP_alt # keep the previous altitude reading for comparison later
    BMP_alt = BMP_sensor.read_altitude()        # value in meters


    ## Readings from the ADC to monitor battery and bus voltages
    bus_bat = (adc.readADCSingleEnded(3, gain, sps) / 1000) * (3)
开发者ID:Student-Space-Technology-Association,项目名称:ssta-hab3,代码行数:33,代码来源:hab3_sensors.py

示例14: sensors

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

示例15: recorded

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_accelerometer_raw [as 别名]
running = False # No data being recorded (yet)
try:
    print('Press the Joystick button to start recording.')
    print('Press it again to stop.')
    while True:
        # capture all the relevant events from joystick
        r,w,x=select([js.fd],[],[],0.01)
        for fd in r:
            for event in js.read():
                # If the event is a key press...
                if event.type==ecodes.EV_KEY and event.value==1:
                    # If we're not logging data, start now
                    if event.code==ecodes.KEY_ENTER and not running:
                        running = True # Start recording data
                        sh.clear(0,255,0) # Light up LEDs green 
                    # If we were already logging data, stop now
                    elif event.code==ecodes.KEY_ENTER and running:
                        running = False
                        gentle_close()
        # If we're logging data...
        if running:
             # Read from acceleromter
            acc_x,acc_y,acc_z = [sh.get_accelerometer_raw()[key] for key in ['x'
,'y','z']]
            # Format the results and log to file
            logging.info('{:12.10f}, {:12.10f}, {:12.10f}'.format(acc_x,acc_y,ac
c_z))
            print(acc_x,acc_y,acc_z) # Also write to screen
except: # If something goes wrong, quit
    gentle_close()
开发者ID:topshed,项目名称:SenseHatSci-Gravity,代码行数:32,代码来源:gravity.py


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