def __init__(self, numSamples=50): # Get measurements of the orientation change to account for bias self.mpu = mpu9250() # Make sure to use the minimum sampling rate self.sampleTime = 1 / 200 self.biasCalculated = False xDps = np.zeros((numSamples, 1)) yDps = np.zeros((numSamples, 1)) zDps = np.zeros((numSamples, 1)) takenCnt = 0 for i in range(0, numSamples): gReading = self.getGyro() xDps[i] = gReading[0] yDps[i] = gReading[1] zDps[i] = gReading[2] self.xBias = np.average(xDps) self.yBias = np.average(yDps) self.zBias = np.average(zDps) self.biasCalculated = True
def main(): global start_value global data_max # Initialize sensor with external library class. sensor = mpu9250() # Key taken from account. API_KEY = "fb2dc4530995b2fe3d3f823a0fa35a5e8d635716" # Name of channel. CHANNEL_NAME = "JuicySeniorDesign" # Create pushetta object. p = Pushetta(API_KEY) print('entering main loop...') sys.stdout.flush() while True: # Get sensor data. data = sensor.accel[2] # Look at new max value. if data > data_max: print('New Maximum... {}'.format(data_max)) data_max = data # Thresholding for alarm detection. Adjust magnitude for each axis. if (data_max >= (start_value + Z_THRESHOLD)): print('Sending out alert... {} {} {}'.format( data_max, start_value, Z_THRESHOLD)) sys.stdout.flush() alert(p, CHANNEL_NAME, sensor) print('Done... {} {} {}'.format(data_max, start_value, Z_THRESHOLD)) sys.stdout.flush()
Z_RESET = 1.8 # Push message until button press. while (sensor.accel[2] < Z_RESET): p.pushMessage(CHANNEL_NAME, "CHECK POOL!!!!") time.sleep(2) # Turn off alarm and reset threshold starting value. time.sleep(15) start_value = sensor.accel[2] if __name__ == "__main__": # Initialize sensor with external library class. sensor = mpu9250() # Key taken from account. API_KEY = "fb2dc4530995b2fe3d3f823a0fa35a5e8d635716" # Name of channel. CHANNEL_NAME = "JuicySeniorDesign" # Create pushetta object. p = Pushetta(API_KEY) data_max = 0 while True: # Get sensor data.