Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from Phidget22.Phideget import *
- from Phidget22.Devices.DCMotor import *
- from Phidget22.Devices.Encoder import *
- from Phidget22.Devices.VoltageInput import *
- import time
- import sys
- def onPositionChange(self, positionChange, timeChange, indexTriggered):
- print("-"*10)
- print("PositionChange: %d" % positionChange)
- print("TimeChange: %f" % timeChange)
- print("IndexTriggered %d" % indexTriggered)
- print("getPosition: %d" % self.getPosition())
- print("-"*10)
- def onVelocityUpdate(self, velocity):
- print("Veolcity: %f" % velocity)
- def main():
- dcMotor0 = DCMotor()
- encoder0 = Encoder()
- encoder0.setOnPositionChangeHandler(onPositionChange)
- dcMotor0.setOnVeolocityUpdateHandler(onVelocityUpdate)
- encoder0.openWaitForAttachment(1000)
- dcMotor0.openWaitForAttachment(1000)
- encoder0.setPositionChangeTrigger(0)
- dcMotor0.setTargetVelocity(0.5)
- try:
- while True:
- time.sleep(1.0)
- except KeyboardInterrupt as e:
- print(e)
- finally:
- dcMotor0.close()
- encoder0.close()
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement