Example #1
0
import time
import numpy

import liblo
try:
  target = liblo.Address(1234)
except liblo.AddressError, err:
  print str(err)
  sys.exit()

steer = 0
velocity = 0

try:
   interfaceKit = InterfaceKit()
   encoder = Encoder()

except RuntimeError as e:
  print("Runtime Error: %s" % e.message)

def interfaceKitSensorChanged(e):
  global steer
  DEAD_ZONE = 0
  if e.index == 0:
    steer = numpy.clip((e.value-263)/110.0, -1, 1)
    if abs(steer) < DEAD_ZONE:
      steer = 0
    print "steer", steer
  return 0

def interfaceKitInputChanged(e):
Example #2
0
"""

__author__ = 'Adam Stelmack'
__version__ = '2.1.4'
__date__ = 'May 02 2008'

#Basic imports
from ctypes import *
import sys
#Phidget specific imports
from Phidgets.PhidgetException import *
from Phidgets.Events.Events import *
from Phidgets.Devices.Encoder import *

#Create an accelerometer object
encoder = Encoder()

#Information Display Function
def displayDeviceInfo():
    print "|------------|----------------------------------|--------------|------------|"
    print "|- Attached -|-              Type              -|- Serial No. -|-  Version -|"
    print "|------------|----------------------------------|--------------|------------|"
    print "|- %8s -|- %30s -|- %10d -|- %8d -|" % (encoder.isAttached(), encoder.getDeviceType(), encoder.getSerialNum(), encoder.getDeviceVersion())
    print "|------------|----------------------------------|--------------|------------|"
    return 0

#Event Handler Callback Functions
def encoderAttached(e):
    attached = e.device
    print "Encoder %i Attached!" % (attached.getSerialNum())
    return 0
Example #3
0
    def __init__(self):
        try:
            encoder = Encoder()
            encoder.setOnAttachHandler(self.encoderAttached)
            encoder.setOnDetachHandler(self.encoderDetached)
            encoder.setOnErrorhandler(self.encoderError)
            encoder.setOnPositionChangeHandler(self.encoderPositionChange)
            encoder.openPhidget()

            self.encoder = encoder

            self.attachDetachObservers = []
            self.changeObservers = []

        except PhidgetException as e:
            print("Phidget Error %i: %s" % (e.code, e.details))
            exit(1)
        except RuntimeError as e:
            print("Runtime Exception: %s" % e.details)
            print("Exiting....")
            exit(1)