PRE2017 3 11 Python Code

From Control Systems Technology Group
Revision as of 15:38, 16 March 2018 by S164358 (talk | contribs) (Created page with '<source lang="python" line='line'> import RPi.GPIO as GPIO # GPIO pin control import time # Posibility to delay GPIO.setmode(GPIO.BOARD) # Board numbering …')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

<source lang="python" line='line'> import RPi.GPIO as GPIO # GPIO pin control import time # Posibility to delay GPIO.setmode(GPIO.BOARD) # Board numbering sceme pin_cServo1 = 29 # Continuous servo 1 pin_cServo2 = 33 # Continuous servo 2 pin_cServo3 = 37 # Continuous servo 3 pin_mServo1 = 13 # Mini servo 1

  1. Sets pin as output.

GPIO.setup(cServo1,GPIO.OUT) GPIO.setup(cServo2,GPIO.OUT) GPIO.setup(cServo3,GPIO.OUT) GPIO.setup(mServo1,GPIO.OUT)

freq = 100 # Servo frequency [Hz]

  1. Assigns frequency to pins

cServo1 = GPIO.PWM(pin_cServo1, freq) cServo2 = GPIO.PWM(pin_cServo2, freq) cServo3 = GPIO.PWM(pin_cServo3, freq) mServo1 = GPIO.PWM(pin_mServo1, freq)

cleft = 5 # 100% velocity to left ccenter = 7.5 # no movement cright = 10 # 100% velocity to right

mleft = 5 # 90 degrees left mcenter = 7.5 # center mright = 10 # 90 degrees right

cyldelay = 2 # Time it takes for cylinder to rotate dropdelay = 15 # Time it takes to drop package platformdelay = 2 # Time it takes for platform to move down lockdelay = 20 # Time lock stays opened

  1. Sets all servos still at centered position

cServo1.start(ccenter) cServo2.start(ccenter) cServo3.start(ccenter) mServo1.start(mcenter)

if i=true:

   cServo1.ChangeDutyCycle(cleft)      # Inner cylinder opens 
   cServo2.ChangeDutyCycle(cright)     # Outer cylinder moves away
   time.delay(cyldelay)                # Duration of cylinder movement
   cServo1.ChangeDutyCycle(ccenter)    # Inner Cylinder stops moving
   cServo2.ChangeDutyCycle(ccenter)    # Outer Cylinder stops moving
   time.delay(dropdelay)               # Duration of package dropping
   cServo1.ChangeDutyCycle(cright)     # Inner cylinder closes
   cServo2.ChangeDutyCycle(cleft)      # Outer cylinder moves back
   time.delay(cyldelay)                # Duration of cylinder movement
   cServo1.ChangeDutyCycle(ccenter)
   cServo2.ChangeDutyCycle(ccenter)   
   
   cServo3.ChangeDutyCycle(cleft)      # Platform moves down
   time.delay(platformdelay)           # Duration of platform moving down
   cServo3.ChangeDutyCycle(ccenter)    # Platform stops moving

if j=true:

   mServo1.ChangeDutyCycle(mleft)      # Lock opens
   time.delay(lockdelay)
   mServo1.ChangeDutyCycle(mcenter)    # Lock closes

</source>