def isBallAtTopOfRamp(self): global OFF global STAIRCASE_SPEED if OFF: while True: if ((cyprus.read_gpio() & 0b0001) == 0): print("GPIO on port P6 is LOW") print(" ramp moving") cyprus.set_pwm_values( 1, period_value=100000, compare_value=STAIRCASE_SPEED, compare_mode=cyprus.LESS_THAN_OR_EQUAL) print("staircase moving") time.sleep(5) OFF = False break else: cyprus.set_pwm_values(1, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL) print("staircase stopped") # self.staircase.text = "Staircase Off" OFF = True
def prox_sensor(self): cyprus.initialize() if (cyprus.read_gpio() & 0b0010): cyprus.set_pwm_values(2, period_value=100000, compare_value=100000, compare_mode=cyprus.LESS_THAN_OR_EQUAL) else: cyprus.set_pwm_values(2, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL) cyprus.close()
def toggleArm(self): print("Process arm movement here") self.armHeight = not self.armHeight if self.armHeight: cyprus.set_pwm_values(1, period_value=100000, compare_value=50000, compare_mode=cyprus.LESS_THAN_OR_EQUAL) else: cyprus.set_pwm_values(1, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL)
def proximitySensorCytronController(self): cyprus.setup_servo(1) # cyprus.set_servo_position(1, 0.5) print("function is working") while True: if cyprus.read_gpio( ) & 0b0010: # HIGH (True) means not detecting metal sleep(1) if cyprus.read_gpio() & 0b0010: print("Metal not detected") cyprus.set_pwm_values( 1, period_value=100000, compare_value=50000, compare_mode=cyprus.LESS_THAN_OR_EQUAL) if not (cyprus.read_gpio() & 0b0010): sleep(1) if not (cyprus.read_gpio() & 0b0010): cyprus.set_pwm_values( 1, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL) print("Metal detected")
def initialize(self): print("Home arm and turn off magnet") cyprus.initialize() cyprus.setup_servo(1) cyprus.setup_servo(2) cyprus.set_servo_position(2, .5) cyprus.set_pwm_values(1, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL) self.homeArm()
def setStaircaseSpeed(self, speed): self.staircase_speed = speed * 1000 self.ids.staircaseSpeedLabel.text = "StairCase Speed: " + str( speed) + "%" if self.staircase: cyprus.set_pwm_values(1, period_value=100000, compare_value=(speed * 1000), compare_mode=cyprus.LESS_THAN_OR_EQUAL) print("Set the staircase speed and update slider text")
def exit_ui(self): s1.free() cyprus.initialize() #cyprus.set_servo_position(1, 0.5) cyprus.set_pwm_values(2, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL) #cyprus.close() exit()
def set_staircase_speed(speed): if ON: cyprus.set_pwm_values(1, period_value=100000, compare_value=speed * 1000, compare_mode=cyprus.LESS_THAN_OR_EQUAL) else: cyprus.set_pwm_values(1, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL)
def toggle_staircase(speed): global ON if ON: cyprus.set_pwm_values(1, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL) else: cyprus.set_pwm_values(1, period_value=100000, compare_value=speed * 1000, compare_mode=cyprus.LESS_THAN_OR_EQUAL) ON = not ON
def bs2(self): global x2 while x2: if (cyprus.read_gpio() & 0b0001): sleep(.1) if (cyprus.read_gpio() & 0b0001): cyprus.set_pwm_values(1, period_value=100000, compare_value=50000, compare_mode=cyprus.LESS_THAN_OR_EQUAL) cyprus.set_servo_position(1, 1) print("r") else: cyprus.set_servo_position(1, .5) print("b")
def gamerrise(self): global b b = 1 global speder speder = 0 cyprus.set_servo_position(1,.5) while(b<=200): speder = .5 + .5 * b/200 print("%s" % speder) cyprus.set_pwm_values(1, period_value=100000, compare_value=50000, compare_mode=cyprus.LESS_THAN_OR_EQUAL) cyprus.set_servo_position(1, speder) sleep(.1) b = b + 1
def toggle_arm(): global UP if UP: cyprus.set_pwm_values(1, period_value=100000, compare_value=100000, compare_mode=cyprus.LESS_THAN_OR_EQUAL) else: cyprus.set_pwm_values(1, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL) UP = not UP
def cytronControllerFN(self): cyprus.setup_servo(1) # cyprus.set_servo_position(1, 0.5) cyprus.set_pwm_values(1, period_value=100000, compare_value=50000, compare_mode=cyprus.LESS_THAN_OR_EQUAL) sleep(5) cyprus.set_pwm_values(1, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL) sleep(5)
def talonThread(self): global talon while talon: if (cyprus.read_gpio() & 0b0001): sleep(.1) if (cyprus.read_gpio() & 0b0001): cyprus.set_pwm_values( 1, period_value=100000, compare_value=50000, compare_mode=cyprus.LESS_THAN_OR_EQUAL) cyprus.set_servo_position(1, 1) else: cyprus.set_servo_position(1, .5)
def toggleStaircase(self): self.staircase = not self.staircase if self.staircase: print(self.staircase) cyprus.set_pwm_values(1, period_value=100000, compare_value=self.staircase_speed, compare_mode=cyprus.LESS_THAN_OR_EQUAL) else: print(self.staircase) cyprus.set_pwm_values(1, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL) print("Turn on and off staircase here")
def flip(self): while True: if cyprus.read_gpio() & 0b0010: cyprus.set_pwm_values(1, period_value=10000, compare_value=5000, compare_mode=cyprus.LESS_THAN_OR_EQUAL) self.ids.flip.text = "180 Degrees" print("I hear this") else: cyprus.set_pwm_values(1, period_value=10000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL) self.ids.flip.text = "0 Degrees" print("I am so bad")
def setArmPosition(self): print("Move arm here") global DOWN if DOWN: cyprus.set_pwm_values(1, period_value=100000, compare_value=100000, compare_mode=cyprus.LESS_THAN_OR_EQUAL) print("robotic arm up") DOWN = False else: cyprus.set_pwm_values(1, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL) print("robotic arm down") DOWN = True
def pressedF(self): """ Function called on button touch event for button with id: testButton :return: None """ cyprus.set_pwm_values(1, period_value=100000, compare_value=50000, compare_mode=cyprus.LESS_THAN_OR_EQUAL) cyprus.set_servo_position(1, 0) sleep(5) print("a") cyprus.set_servo_position(1, .5) sleep(5) print("b") cyprus.set_pwm_values(1, period_value=100000, compare_value=50000, compare_mode=cyprus.LESS_THAN_OR_EQUAL) cyprus.set_servo_position(1, 1) sleep(5) cyprus.set_servo_position(1, .5) print("c")
def toggleStaircase(self): global stair_count, staircaseSpeed if stair_count % 2 == 0: self.staircase.text = "Turn Off Staircase" cyprus.set_pwm_values(1, period_value=100000, compare_value=staircaseSpeed, compare_mode=cyprus.LESS_THAN_OR_EQUAL) sleep(0.1) else: self.staircase.text = "Turn On Staircase" cyprus.set_pwm_values(1, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL) sleep(0.1) stair_count += 1
def cytronThread(self): global cytron while cytron: if (cyprus.read_gpio() & 0b0010): cyprus.set_pwm_values(1, period_value=100000, compare_value=50000, compare_mode=cyprus.LESS_THAN_OR_EQUAL) sleep(.1) print("yeepie") else: cyprus.set_pwm_values(1, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL) sleep(.1) print("yeepie 1")
def cytron_dc(self): cyprus.initialize() cyprus.set_pwm_values(2, period_value=100000, compare_value=100000, compare_mode=cyprus.LESS_THAN_OR_EQUAL) sleep(.5) cyprus.set_pwm_values(2, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL) sleep(5) cyprus.set_pwm_values(2, period_value=100000, compare_value=-100000, compare_mode=cyprus.LESS_THAN_OR_EQUAL) sleep(.5) cyprus.set_pwm_values(2, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL) cyprus.close()
def tickArrows(self, way): cyprus.initialize() cyprus.setup_servo(2) num = self.ids.PWM_slider.value if way == "up": if self.ids.cytron_label.text == "Neutral": num = 55 elif num == 45: num = 50 elif num == 100: num = 100 else: num += 1 elif way == "down": if self.ids.cytron_label.text == "Neutral": num = 45 elif num == 55: num = 50 elif num == 0: num = 0 else: num -= 1 if (num > 45) and (num < 55): self.ids.cytron_label.text = "Neutral" self.ids.cytron_label.color = (1, .65, 0, .8) self.ids.PWM_slider.value = 50 val = 0 elif num > 54: s = "Forward " + str(num - 50) self.ids.cytron_label.text = s self.ids.cytron_label.color = (0, 1, 0, .8) self.ids.PWM_slider.value = num val = (self.ids.PWM_slider.value - 50) * 200 direction = 1 else: s = "Backward " + str(num - 50) self.ids.cytron_label.text = s self.ids.cytron_label.color = (1, 0, 0, .8) self.ids.PWM_slider.value = num val = (50 - self.ids.PWM_slider.value) * 200 direction = 0 cyprus.set_pwm_values(2, period_value=10000, compare_value=val, compare_mode=cyprus.LESS_THAN_OR_EQUAL)
def initialize(self): global s0 cyprus.initialize() cyprus.setup_servo(1) cyprus.setup_servo(2) cyprus.set_pwm_values(1, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL) cyprus.set_servo_position(2, 0.25) s0 = stepper(port=0, micro_steps=32, hold_current=20, run_current=20, accel_current=20, deaccel_current=20, steps_per_unit=200, speed=8) s0.set_as_home()
def turnOnStaircase(self): global OFF global STAIRCASE_SPEED if OFF: cyprus.set_pwm_values(1, period_value=100000, compare_value=STAIRCASE_SPEED, compare_mode=cyprus.LESS_THAN_OR_EQUAL) print("staircase moving") OFF = False else: cyprus.set_pwm_values(1, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL) print("staircase stopped") # self.staircase.text = "Staircase Off" OFF = True
def setArmPositionV(self): print("Move arm vertically here") global DOWN if DOWN: cyprus.set_pwm_values(1, period_value=100000, compare_value=100000, compare_mode=cyprus.LESS_THAN_OR_EQUAL) print("robotic arm up") self.ids.armControl.text = "Raise Arm" DOWN = False else: cyprus.set_pwm_values(1, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL) print("robotic arm down") self.ids.armControl.text = "Lower Arm" DOWN = True
def updateLabel(self): cyprus.initialize() if (self.ids.PWM_slider.value < 55) and (self.ids.PWM_slider.value > 45): self.ids.cytron_label.text = "Neutral" self.ids.cytron_label.color = (1, .65, 0, .8) val = 0 elif self.ids.PWM_slider.value > 54: s = "Forward " + str(abs(self.ids.PWM_slider.value) - 50) self.ids.cytron_label.text = s self.ids.cytron_label.color = (0, 1, 0, .8) val = (self.ids.PWM_slider.value - 50) * 200 direction = 1 else: s = "Backward " + str(abs(self.ids.PWM_slider.value) - 50) self.ids.cytron_label.text = s self.ids.cytron_label.color = (1, 0, 0, .8) val = (50 - self.ids.PWM_slider.value) * 200 direction = 0 cyprus.set_pwm_values(2, period_value=10000, compare_value=val, compare_mode=cyprus.LESS_THAN_OR_EQUAL)
def switch_button(self): global switch_boolean cyprus.initialize() while switch_boolean: if cyprus.read_gpio() & 0b0001: sleep(0.1) if (cyprus.read_gpio() & 0b0001) == 1: cyprus.set_pwm_values( 2, period_value=100000, compare_value=100000, compare_mode=cyprus.LESS_THAN_OR_EQUAL) else: sleep(0.1) if (cyprus.read_gpio() & 0b0001) == 0: cyprus.set_pwm_values( 2, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL) cyprus.close()
def auto(self): print("Run through one cycle of the perpetual motion machine") global HOME # global TOP ramp.goHome() sleep(5) cyprus.set_servo_position(2, 0.5) sleep(0.5) cyprus.set_servo_position(2, 0) while True: if ((cyprus.read_gpio() & 0b0010) == 0): cyprus.set_pwm_values(1, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL) ramp.set_speed(40) print("GPIO on port P7 is LOW") ramp.start_relative_move(-226) print(" ramp moving") while True: if ((cyprus.read_gpio() & 0b0001) == 0): ramp.stop() print("GPIO on port P6 is LOW") cyprus.set_pwm_values( 1, period_value=100000, compare_value=50000, compare_mode=cyprus.LESS_THAN_OR_EQUAL) print("staircase moving") break #ramp.start_relative_move(226) ramp.goHome() print("going home") time.sleep(8) print("turning ramp off") cyprus.set_pwm_values(1, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL) cyprus.set_servo_position(2, 0.5) sleep(0.5) cyprus.set_servo_position(2, 0) break
def buttonControl(self, cmd): if cmd == "forward": self.ids.cytron_label.text = "Forward 50.0" self.ids.PWM_slider.value = 100 self.ids.cytron_label.color = (0, 1, 0, .8) cyprus.set_pwm_values(2, period_value=10000, compare_value=10000, compare_mode=cyprus.LESS_THAN_OR_EQUAL) elif cmd == "back": self.ids.cytron_label.text = "Backward 50.0" self.ids.PWM_slider.value = 0 self.ids.cytron_label.color = (1, 0, 0, .8) cyprus.set_pwm_values(2, period_value=10000, compare_value=10000, compare_mode=cyprus.LESS_THAN_OR_EQUAL) else: self.ids.cytron_label.text = "Neutral" self.ids.PWM_slider.value = 50 self.ids.cytron_label.color = (1, .65, 0, .8) cyprus.set_pwm_values(2, period_value=10000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL)
cyprus.initialize() # initialize the RPiMIB and establish communication cyprus.setup_servo( 2) # sets up P5 on the RPiMIB as a RC servo motor controller style output # for loop will set speed all the way from 0-full reverse to 0.5-halt to 1-full forward then halt with half second delays for i in range(5, 10, 1): cyprus.set_servo_position( 2, i / 10.0) # 2 specifies port P5, i is a float that specifies speed sleep(0.5) cyprus.set_servo_position(1, 0.5) # halt the motor cyprus.close() # when done disconnect the RPiMIB communication # To get a Industrial PWM output on P5 to control something like a Cytron Motor Controller do the following: cyprus.initialize() # initialize the RPiMIB and establish communication # the following command will set up port 2 (P5) to put out a 100000HZ (100KHz) signal with a 50% high time or duty cycle cyprus.set_pwm_values(2, period_value=100000, compare_value=50000, compare_mode=cyprus.LESS_THAN_OR_EQUAL) # Motor controller Ex. Cytron MD10C connected to P5, the connected motor would be running ~50% max rpm cyprus.set_pwm_values(2, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL) # Motor OFF cyprus.close() # To get sensors and other I/O to work with RPiMIB # The RPiMIB has four multipurpose I/O ports. Ports P6, P7, P8 and P9 # # The command to read is cyprus.read_gpio() which will return 4 bits which represents ALL GPIO pins (P6-P9) # To get the actual value of a particular port one needs to do a bitwise AND as per example below from pidev.Cyprus_Commands import Cyprus_Commands_RPi as cyprus