def initialize_sensors(): print("\n--- Sensors initializing...") try: #For a raspberry pi, for example, to set up pins 4 and 5, you would add #GPIO.setmode(GPIO.BCM) #GPIO.setup(4, GPIO.IN) #GPIO.setup(5, GPIO.IN) print("--- Waiting 10 seconds for sensors to warm up...") time.sleep(10) # Activate the accelerometer global ch ch = Accelerometer() # Assign event handlers ch.setOnAttachHandler(AccelerometerAttached) ch.setOnDetachHandler(AccelerometerDetached) ch.setOnErrorHandler(ErrorEvent) # Wait for the sensor to be attached print( "--- Waiting for the Phidget Accelerometer Object to be attached..." ) ch.openWaitForAttachment(5000) print("--- Sensors initialized!") # Sync the time on this device to an internet time server try: print('\n--- Syncing time...') os.system('sudo service ntpd stop') time.sleep(1) os.system('sudo ntpd -gq') time.sleep(1) os.system('sudo service ntpd start') print('--- Success! Time is ' + str(datetime.datetime.now())) except: print('Error syncing time!') except Exception as ex: # Log any error, if it occurs print( str(datetime.datetime.now()) + " Error when initializing sensors: " + str(ex))
def initialize_sensors(): print("\n--- Sensors initializing...") try: #For a raspberry pi, for example, to set up pins 4 and 5, you would add #GPIO.setmode(GPIO.BCM) #GPIO.setup(4, GPIO.IN) #GPIO.setup(5, GPIO.IN) print("--- Waiting 10 seconds for sensors to warm up...") time.sleep(10) # Activate the accelerometer global ch ch = Accelerometer() # Assign event handlers ch.setOnAttachHandler(AccelerometerAttached) ch.setOnDetachHandler(AccelerometerDetached) ch.setOnErrorHandler(ErrorEvent) # Wait for the sensor to be attached print("--- Waiting for the Phidget Accelerometer Object to be attached...") ch.openWaitForAttachment(5000) print("--- Sensors initialized!") # Sync the time on this device to an internet time server try: print('\n--- Syncing time...') os.system('sudo service ntpd stop') time.sleep(1) os.system('sudo ntpd -gq') time.sleep(1) os.system('sudo service ntpd start') print('--- Success! Time is ' + str(datetime.datetime.now())) except: print('Error syncing time!') except Exception as ex: # Log any error, if it occurs print(str(datetime.datetime.now()) + " Error when initializing sensors: " + str(ex))
acceleration[2] * 9.80665)) print("Timestamp: %f\n" % timestamp) t.append(timestamp) ac0.append(acceleration[0]) ac1.append(acceleration[1]) ac2.append(acceleration[2]) ######################################################################### # Programa Principal ######################################################################### try: ch.setOnAttachHandler(AccelerometerAttached) ch.setOnDetachHandler(AccelerometerDetached) ch.setOnErrorHandler(ErrorEvent) ch.setOnAccelerationChangeHandler(AccelerationChangeHandler) print("Waiting for the Phidget Accelerometer Object to be attached...") ch.openWaitForAttachment(5000) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) print("Press Enter to Exit...\n") readin = sys.stdin.read(1) exit(1) # Definir el tiempo de muestro del acelerometro (En ms) T_muestreo = 50 # 20 mediciones por segundo ch.setDataInterval(T_muestreo)