예제 #1
0
class PhidgetMovement:			
	def __init__(self,serial):
		self.servo = Servo()
		self.servo.openPhidget(serial)	
		print "connecting to servo: " + str(serial)
		self.servo.waitForAttach(10000)
		
	def setValue(self,value):
		self.servo.setPosition(0,value)
예제 #2
0
__author__ = 'Adam Stelmack'
__version__ = '2.1.8'
__date__ = 'May 17 2010'

#Basic imports
from ctypes import *
import sys
from time import sleep
#Phidget specific imports
from Phidgets.PhidgetException import PhidgetException
from Phidgets.Devices.Servo import Servo, ServoTypes

#Create an servo object
try:
    servo = Servo()
except RuntimeError as e:
    print("Runtime Exception: %s" % e.details)
    print("Exiting....")
    exit(1)

#Information Display Function
def DisplayDeviceInfo():
    print("|------------|----------------------------------|--------------|------------|")
    print("|- Attached -|-              Type              -|- Serial No. -|-  Version -|")
    print("|------------|----------------------------------|--------------|------------|")
    print("|- %8s -|- %30s -|- %10d -|- %8d -|" % (servo.isAttached(), servo.getDeviceName(), servo.getSerialNum(), servo.getDeviceVersion()))
    print("|------------|----------------------------------|--------------|------------|")
    print("Number of motors: %i" % (servo.getMotorCount()))

#Event Handler Callback Functions
예제 #3
0
__version__ = '2.1.8'
__date__ = 'May 17 2010'

#Basic imports
from ctypes import *
import sys
from time import sleep
#Phidget specific imports
from Phidgets.PhidgetException import PhidgetException
from Phidgets.Devices.Servo import Servo, ServoTypes
from Phidgets.Phidget import PhidgetLogLevel


#Create an servo object
try:
    servo = Servo()
except RuntimeError as e:
    print("Runtime Exception: %s" % e.details)
    print("Exiting....")
    exit(1)

#Information Display Function
def DisplayDeviceInfo():
    print("|------------|----------------------------------|--------------|------------|")
    print("|- Attached -|-              Type              -|- Serial No. -|-  Version -|")
    print("|------------|----------------------------------|--------------|------------|")
    print("|- %8s -|- %30s -|- %10d -|- %8d -|" % (servo.isAttached(), servo.getDeviceName(), servo.getSerialNum(), servo.getDeviceVersion()))
    print("|------------|----------------------------------|--------------|------------|")
    print("Number of motors: %i" % (servo.getMotorCount()))

#Event Handler Callback Functions
예제 #4
0
__author__ = 'Adam Stelmack'
__version__ = '2.1.4'
__date__ = 'May 02 2008'

#Basic imports
from ctypes import *
import sys
from time import sleep
#Phidget specific imports
from Phidgets.PhidgetException import *
from Phidgets.Events.Events import *
from Phidgets.Devices.Servo import Servo

#Create an servo object
servo = Servo()

#Information Display Function
def DisplayDeviceInfo():
    print "|------------|----------------------------------|--------------|------------|"
    print "|- Attached -|-              Type              -|- Serial No. -|-  Version -|"
    print "|------------|----------------------------------|--------------|------------|"
    print "|- %8s -|- %30s -|- %10d -|- %8d -|" % (servo.isAttached(), servo.getDeviceType(), servo.getSerialNum(), servo.getDeviceVersion())
    print "|------------|----------------------------------|--------------|------------|"
    print "Number of motors: %i" % (servo.getMotorCount())
    return 0

#Event Handler Callback Functions
def ServoAttached(e):
    attached = e.device
    print "Servo %i Attached!" % (attached.getSerialNum())
예제 #5
0
def AttachServo(databasepath, serialNumber):
    def onAttachHandler(event):
        logString = "Servo Attached " + str(event.device.getSerialNum())
        #print(logString)
        DisplayAttachedDeviceInfo(event.device)

    def onDetachHandler(event):
        logString = "Servo Detached " + str(event.device.getSerialNum())
        #print(logString)
        DisplayDetachedDeviceInfo(event.device)

        event.device.closePhidget()

    def onErrorHandler(event):
        logString = "Servo Error " + str(
            event.device.getSerialNum()) + ", Error: " + event.description
        print(logString)

        DisplayErrorDeviceInfo(event)

    def onServerConnectHandler(event):
        logString = "Servo Server Connect " + str(event.device.getSerialNum())
        #print(logString)

    def onServerDisconnectHandler(event):
        logString = "Servo Server Disconnect " + str(
            event.device.getSerialNum())
        #print(logString)

    def positionChangeHandler(event):
        logString = "Servo Changed " + str(event.device.getSerialNum())
        #print(logString)

        try:
            conn = sqlite3.connect(databasepath)

            conn.execute(
                "INSERT INTO SERVO_POSITIONCHANGE VALUES(NULL, DateTime('now'), ?, ?, ?)",
                (event.device.getSerialNum(), event.index, event.position))

            conn.commit()
            conn.close()
        except sqlite3.Error as e:
            print "An error occurred:", e.args[0]

    try:
        p = Servo()

        p.setOnAttachHandler(onAttachHandler)
        p.setOnDetachHandler(onDetachHandler)
        p.setOnErrorhandler(onErrorHandler)
        p.setOnServerConnectHandler(onServerConnectHandler)
        p.setOnServerDisconnectHandler(onServerDisconnectHandler)

        p.setOnPositionChangeHandler(positionChangeHandler)

        p.openPhidget(serialNumber)

    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        print("Exiting...")
        exit(1)
예제 #6
0
__author__ = 'Adam Stelmack'
__version__ = '2.1.4'
__date__ = 'May 02 2008'

#Basic imports
from ctypes import *
import sys
from time import sleep
#Phidget specific imports
from Phidgets.PhidgetException import *
from Phidgets.Events.Events import *
from Phidgets.Devices.Servo import Servo

#Create an servo object
servo = Servo()


#Information Display Function
def DisplayDeviceInfo():
    print "|------------|----------------------------------|--------------|------------|"
    print "|- Attached -|-              Type              -|- Serial No. -|-  Version -|"
    print "|------------|----------------------------------|--------------|------------|"
    print "|- %8s -|- %30s -|- %10d -|- %8d -|" % (
        servo.isAttached(), servo.getDeviceType(), servo.getSerialNum(),
        servo.getDeviceVersion())
    print "|------------|----------------------------------|--------------|------------|"
    print "Number of motors: %i" % (servo.getMotorCount())
    return 0

예제 #7
0
def AttachServo(databasepath, serialNumber):
	def onAttachHandler(event):
		logString = "Servo Attached " + str(event.device.getSerialNum())
		#print(logString)
		DisplayAttachedDeviceInfo(event.device)

	def onDetachHandler(event):
		logString = "Servo Detached " + str(event.device.getSerialNum())
		#print(logString)
		DisplayDetachedDeviceInfo(event.device)

		event.device.closePhidget()

	def onErrorHandler(event):
		logString = "Servo Error " + str(event.device.getSerialNum()) + ", Error: " + event.description
		print(logString)

		DisplayErrorDeviceInfo(event)
		
	def onServerConnectHandler(event):
		logString = "Servo Server Connect " + str(event.device.getSerialNum())
		#print(logString)

	def onServerDisconnectHandler(event):
		logString = "Servo Server Disconnect " + str(event.device.getSerialNum())
		#print(logString)

	def positionChangeHandler(event):
		logString = "Servo Changed " + str(event.device.getSerialNum())
		#print(logString)

		try:
			conn = sqlite3.connect(databasepath)

			conn.execute("INSERT INTO SERVO_POSITIONCHANGE VALUES(NULL, DateTime('now'), ?, ?, ?)", 
					(event.device.getSerialNum(), event.index, event.position))

			conn.commit()
			conn.close()
		except sqlite3.Error as e:
			print "An error occurred:", e.args[0]

	try:
		p = Servo()

		p.setOnAttachHandler(onAttachHandler)
		p.setOnDetachHandler(onDetachHandler)
		p.setOnErrorhandler(onErrorHandler)
		p.setOnServerConnectHandler(onServerConnectHandler)
		p.setOnServerDisconnectHandler(onServerDisconnectHandler)

		p.setOnPositionChangeHandler(positionChangeHandler)

		p.openPhidget(serialNumber)

	except PhidgetException as e:
		print("Phidget Exception %i: %s" % (e.code, e.details))
		print("Exiting...")
		exit(1)
예제 #8
0
#Phidget specific imports
from Phidgets.PhidgetException import PhidgetErrorCodes, PhidgetException
from Phidgets.Events.Events import AttachEventArgs, DetachEventArgs, ErrorEventArgs, PositionChangeEventArgs
from Phidgets.Devices.Servo import Servo, ServoTypes

#measured high stopped pulse width = 1522
#measured low stopped pulse width = 1499
#median stopped pulse width = 1511

stopPW = 1511
goPW = 130


#Create an servo object
try:
    servo = Servo()
except RuntimeError as e:
    print("Runtime Exception: %s" % e.details)
    print("Exiting....")
    exit(1)

#Information Display Function
def DisplayDeviceInfo():
    print("|------------|----------------------------------|--------------|------------|")
    print("|- Attached -|-              Type              -|- Serial No. -|-  Version -|")
    print("|------------|----------------------------------|--------------|------------|")
    print("|- %8s -|- %30s -|- %10d -|- %8d -|" % (servo.isAttached(), servo.getDeviceType(), servo.getSerialNum(), servo.getDeviceVersion()))
    print("|------------|----------------------------------|--------------|------------|")
    print("Number of motors: %i" % (servo.getMotorCount()))

#Event Handler Callback Functions
예제 #9
0
	def __init__(self,serial):
		self.servo = Servo()
		self.servo.openPhidget(serial)	
		print "connecting to servo: " + str(serial)
		self.servo.waitForAttach(10000)