Advertisement
Guest User

#1ate2rGc

a guest
Aug 18th, 2023
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. from Phidget22.Phideget import *
  2. from Phidget22.Devices.DCMotor import *
  3. from Phidget22.Devices.Encoder import *
  4. from Phidget22.Devices.VoltageInput import *
  5. import time
  6. import sys
  7.  
  8.  
  9.  
  10. def onPositionChange(self, positionChange, timeChange, indexTriggered):
  11.     print("-"*10)
  12.     print("PositionChange: %d" % positionChange)
  13.     print("TimeChange: %f" % timeChange)
  14.     print("IndexTriggered %d" % indexTriggered)
  15.     print("getPosition: %d" % self.getPosition())
  16.     print("-"*10)
  17.  
  18.  
  19.  
  20.  
  21. def onVelocityUpdate(self, velocity):
  22.     print("Veolcity: %f" % velocity)
  23.  
  24. def main():
  25.     dcMotor0 = DCMotor()
  26.     encoder0 = Encoder()
  27.  
  28.     encoder0.setOnPositionChangeHandler(onPositionChange)
  29.     dcMotor0.setOnVeolocityUpdateHandler(onVelocityUpdate)
  30.  
  31.     encoder0.openWaitForAttachment(1000)
  32.     dcMotor0.openWaitForAttachment(1000)
  33.  
  34.     encoder0.setPositionChangeTrigger(0)
  35.     dcMotor0.setTargetVelocity(0.5)
  36.  
  37.     try:
  38.         while True:
  39.             time.sleep(1.0)
  40.     except KeyboardInterrupt as e:
  41.         print(e)
  42.     finally:
  43.         dcMotor0.close()
  44.         encoder0.close()
  45.  
  46. if __name__ == "__main__":
  47.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement