Esempio n. 1
0
def main():
    try:
        #Create your Phidget channels
        accelerometer0 = Accelerometer()
        gyroscope0 = Gyroscope()
        magnetometer0 = Magnetometer()

        #Set addressing parameters to specify which channel to open (if any)

        #Assign any event handlers you need before calling open so that no events are missed.
        accelerometer0.setOnAccelerationChangeHandler(onAccelerationChange)
        gyroscope0.setOnAngularRateUpdateHandler(onAngularRateUpdate)
        magnetometer0.setOnMagneticFieldChangeHandler(onMagneticFieldChange)

        #Open your Phidgets and wait for attachment
        accelerometer0.openWaitForAttachment(5000)
        gyroscope0.openWaitForAttachment(5000)
        magnetometer0.openWaitForAttachment(5000)

        #Do stuff with your Phidgets here or in your event handlers.

        time.sleep(5)

        #Close your Phidgets once the program is done.
        accelerometer0.close()
        gyroscope0.close()
        magnetometer0.close()

    except PhidgetException as ex:
        #We will catch Phidget Exceptions here, and print the error informaiton.
        traceback.print_exc()
        print("")
        print("PhidgetException " + str(ex.code) + " (" + ex.description +
              "): " + ex.details)
def main():
    accelerometer0 = Accelerometer()

    accelerometer0.setOnAccelerationChangeHandler(onAccelerationChange)

    accelerometer0.openWaitForAttachment(5000)

    try:
        input("Press Enter to Stop\n")
    except (Exception, KeyboardInterrupt):
        pass

    accelerometer0.close()
    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)

# Esperar 5 segundos por las interrupciones del acelerometro