def read(self): if self.type == 'accelerometer': data = {} data['orientation'] = grove6axis.getOrientation() data['acceleration'] = grove6axis.getAccel() data['magnitude'] = grove6axis.getMag() return data else: return None
import grovepi import grove6axis import time while True: #read from 6-Axis Accelerometer&Compass sensor on input I1 grove6axis.init6Axis() # start it up i1 = grove6axis.getOrientation() # returns orientation as yaw,pitch,roll i2 = grove6axis.getAccel() # get acceleration values i3 = grove6axis.getMag() # get magnetometer values print('Orientation', i1) print('Accel', i2) print('Mag', i3) #read from Tilt sensor on input D4 #d4= grovepi.digitalRead(4) #read from Ultrasonic sensor on input D3 d3 = grovepi.ultrasonicRead(3) #output the data print("Ultrasonic_Distance:", d3) # Read roughly 10 times a second # - n.b. analog read takes time to do also # set the time for 1s to display data time.sleep(2)
calibrationPasses -= 1 else: a0Fix = a0 - a0Cal a1Fix = a1 - a1Cal # Calculate the absolute difference between a0 and a1 aDiff = a1Fix / a0Fix # Apply a low-pass filter to this difference aDiffLo = loPass(aDiff, aDiffLo) # Read the first value of the 3-tuple returned by getOrientation() # This value will be in radians, with flat on its back being 0 # The 3-axis sensor should be positioned with the cable port on the bottom # Due to prototyping constraints the yaw value is used lean = grove6axis.getOrientation()[1] # Apply a low-pass filter to this leanLo = loPass(lean, leanLo) # Output the data if aDiffLo > 1.2: # If the difference is more than 200 t += 0.1 # Increase the time by 0.1 if t > problemTime: # If that time is more than 200 (should be ~20s) print( "You have been looking at the screen for too long, please look away now" ) else: # Else we have a look at how much the user's leaning if abs( leanLo ) < problemAngle: # If the LP'd lean value is within bounds...
typeAcceleration = '%f' sensorVariables = [typeTime, typeDistance, typeLoudness, typeLoudness, typeTouch, typeOrientation, typeOrientation, typeOrientation, typeAcceleration, typeAcceleration, typeAcceleration] header = 'time, distance, loudness, loudness2, touch, orientationX, orientationY, orientationZ, accelerationX, accelerationY, accelerationZ' rowFormatString = ','.join(sensorVariables) waitTime = 0.1 print(header) while(True): timestamp = time.time() distance = grovepi.ultrasonicRead(inputPortDistance) loudness = grovepi.analogRead(inputPortLoudness) loudness2 = grovepi.analogRead(inputPortLoudness2) touch = grovepi.digitalRead(inputPortTouch) orientation = grove6axis.getOrientation() orientationX = orientation[0] orientationY = orientation[1] orientationZ = orientation[2] acceleration = grove6axis.getAccel() accelerationX = acceleration[0] accelerationY = acceleration[1] accelerationZ = acceleration[2] print(rowFormatString % (timestamp, distance, loudness, loudness2, touch, orientationX, orientationY, orientationZ, accelerationX, accelerationY, accelerationZ)) # print(rowFormatString % (timestamp, distance, loudness, orientationX, orientationY, orientationZ, accelerationX, accelerationY, accelerationZ)) # if distance < nearDistanceThreshold: # print('%d: near!', distance) # else:
import grovepi import time import grove6axis import math # get a timestamp so we know when it happened timestamp = time.time() print ('time,ori,accel') while True: #read from 6-Axis Accelerometer&Compass sensor on input I1 grove6axis.init6Axis() # start it up print (grove6axis.getOrientation()) # returns orientation as yaw,pitch,roll print (grove6axis.getAccel()) # get acceleration values print (grove6axis.getMag()) # get magnetometer values grove6axis.getAccel()grove6axis.getAccel() # returns orientation as yaw,pitch,roll # ori_list = list(ori) yaw = ori_list[3] * 180.0 / math.pi # pitch = ori_list[2] * 180.0 / math.pi # roll = ori_list[3] * 180.0 / math.pi time.sleep(0.5)