Ejemplo n.º 1
0
 def __init__(self, id, type, port, interval):
     self.id = id
     self.type = type
     self.port = port
     self.interval = interval
     self.lastCapture = time.time()
     if self.type == 'accelerometer':
         grove6axis.init6Axis()
Ejemplo n.º 2
0
import grovepi
import time
import grove6axis

inputPortDistance = 4
inputPortTouch = 3
grovepi.pinMode(inputPortTouch,'INPUT')
inputPortLoudness = 2
inputPortLoudness2 = 2
grove6axis.init6Axis()

# nearDistanceThreshold = 60
typeTime = '%f'
typeLoudness = '%d'
typeDistance = '%d'
typeTouch = '%d'
typeOrientation = '%f'
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)
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
import grovepi
import grove6axis
import time
import math

# The accelerometer should be plugged into an I2C port
# It should be a version 2.0 - the more complicated looking one
grove6axis.init6Axis()  # Initialise the accelerometer

t = 0  # Initialise time
aDiffLo = 0  # Initialise the low-passed value for the difference in light levels
leanLo = math.pi / 2  # Initialise the low-passed value for the lean

problemTime = 20  # The number of seconds before there's a problem
problemAngle = math.pi / 8  # The angle at which there is a problem

calibrationPassesInit = 100  # Number of calibration passes
calibrationPasses = calibrationPassesInit  # Calibration pass counter

a0Cal = 0  # Accumulator for the values recorded by a0
a1Cal = 0  # Accumulator for the values recorded by a1


def loPass(curr, val):
    const = 0.05
    return val * (1.0 - const) + curr * const


while True:
    # Read from an analog sensor on input 0 (this should be the top one)
    a0 = grovepi.analogRead(0)