class MainScreen(Screen): version = cyprus.read_firmware_version() staircaseSpeedText = '0' rampSpeed = INIT_RAMP_SPEED staircaseSpeed = 40 def __init__(self, **kwargs): super(MainScreen, self).__init__(**kwargs) self.initialize() global pos pos = 0 def toggleGate(self): global pos if pos == 0: pos = 0.5 cyprus.set_servo_position(2, pos) else: pos = 0 cyprus.set_servo_position(2, pos) print("Open and Close gate here") def toggleRamp(self): s0.set_speed(self.rampSpeed.value) if s0.read_switch() == 1: print("hi") s0.go_to_position(56.5) elif s0.get_position_in_units() == 56.5: axis1.goTo(0) print("bye") else: while (axis1.isBusy()): continue axis1.goUntilPress( 0, 0, 5000 ) #spins until hits a NO limit at speed 1000 and direction 1 while (axis1.isBusy()): continue axis1.setAsHome() #set the position for 0 for all go to commands print("Move ramp up and down here") def auto(self): print("Run through one cycle of the perpetual motion machine") if axis1.isBusy(): s0.softStop() if s0.get_position_in_units() == 56.5: s0.goHome() elif s0.get_position_in_units() != 0.0: axis1.goUntilPress(0, 0, 5000) elif s0.get_position_in_units() == 0.0: cyprus.set_servo_position(2, 0.5) sleep(2) cyprus.set_servo_position(2, 0) self.toggleRamp() while 1: if cyprus.read_gpio() == 6: print("metal detector signal read") cyprus.set_motor_speed(1, self.staircaseSpeed.value) self.toggleRamp() while 1: if s0.read_switch() == True: sleep(5 / self.staircaseSpeed.value) cyprus.set_motor_speed(1, 0) s0.free_all() return return def setRampSpeed(self, speed): s0.set_speed(speed) print("Set the ramp speed and update slider text") def setStaircaseSpeed(self, speed): if self.staircase.text == "Staircase Off": cyprus.set_motor_speed(1, speed) else: pass print("Set the staircase speed and update slider text") def toggleStaircase(self): if self.staircase.text == "Staircase Off": cyprus.set_motor_speed(1, 0) self.staircase.text = "Staircase On" else: self.staircase.text = "Staircase Off" self.setStaircaseSpeed(self.staircaseSpeed.value) def initialize(self): print("Close gate, stop staircase and home ramp here") cyprus.set_servo_position(2, 0) cyprus.set_motor_speed(1, 0) if (axis1.isBusy()): s0.softStop() print("s0 motor stopped") if s0.get_position_in_units != 0.0: axis1.goUntilPress( 0, 0, 5000) #spins until hits a NO limit at speed 1000 and direction axis1.setAsHome() else: pass print("initialized.") def resetColors(self): self.ids.gate.color = YELLOW self.ids.staircase.color = YELLOW self.ids.ramp.color = YELLOW self.ids.auto.color = BLUE def quit(self): print("Exit") MyApp().stop()
# resides in RaspberryPiCommon Github repo which is something you should always keep up to date. # # As mentioned, the Software library is in RaspberryPiCommon/pidev/Cyprus_Commands/Cyprus_Commands.py # The code is readable - and there is a very well written README.md with example usage in the same folder as the library. # # The PWM Ports on the RPiMIB are P4 and P5. The software library can be used to control both servo motors and motor # controllers like the Talon that use a servo motor input and convert that to a high current drive that can control # large motors. # # In addition to creating PWM that is used to control servo motors and servo motor style motor controllers the software # library has been designed to also create non servo specific PWM for controlling industry standard motor controllers. # Basically the Servo PWM is a special case of industry standard PWM, hopefully we will get to more on this later. # # To get a RC servo motor signal out of P4 of the RPiMIB do the following: cyprus.initialize() # initialize the RPiMIB and establish communication cyprus.setup_servo(1) # sets up P4 on the RPiMIB as a RC servo style output cyprus.set_servo_position( 1, 0 ) # 1 specifies port P4, 0 is a float from 0-1 that specifies servo position ~(0-180deg) sleep( 1 ) # wait one second for the servo to get there... minimum here should be about sleep(0.05) cyprus.set_servo_position( 1, .5 ) # 1 specifies port P4, 0.5 specifies servo position ~(0-180deg) range of (0-1) # when done disconnect the RPiMIB communication cyprus.close() # To get a RC servo motor CONTROLLER signal out of P5 of the RPiMIB do the following: cyprus.initialize() # initialize the RPiMIB and establish communication
def button_down(self): self.goSwitch.color = 0, 0.588, 0.637, 1 sleep(0.05) if cyprus.read_gpio() & 0b0001: self.goSwitch.color = 0.0, 0.84, 0.91, 1 self.servo_change()
def initialize(self): cyprus.setup_servo(2) cyprus.setup_servo(1) print("Close gate, stop staircase and home ramp here")
sleep(.5) home_pos_1 = 11.34 motor_1.go_to_position(home_pos_1) #MOTOR 2 SETUP motor_2 = stepper(port=0, speed=10, micro_steps=128) motor_2.home(0) print("homed motor 2") sleep(.5) home_pos_2 = 24.123 motor_2.go_to_position(home_pos_2) increment = .035 current_pos_x = home_pos_2 current_pos_y = home_pos_1 ccrpi.open_spi() print("opened spi") ##ccrpi.write_gpio(0) #### ccrpi.setup_servo() ccrpi.write_pwm(6, 1, .5) clamp = lambda n, min_n, max_n: max(min(max_n, n), min_n) try: while True: pygame.event.pump() joy_val_x = joystick.get_axis(HORIZONTAL_AXIS) joy_val_y = joystick.get_axis(VERTICAL_AXIS) current_pos_y = current_pos_y + joy_val_y * increment current_pos_x = current_pos_x + joy_val_x * increment
def is_ball_off_lower(): return (cyprus.read_gpio() & 0b0010) != 0
class MainScreen(Screen): version = cyprus.read_firmware_version() armPosition = 0 lastClick = time.clock() def __init__(self, **kwargs): super(MainScreen, self).__init__(**kwargs) self.initialize() def debounce(self): processInput = False currentTime = time.clock() if (currentTime - self.lastClick) > DEBOUNCE: processInput = True self.lastClick = currentTime return processInput def toggleArm(self): toggle_arm() if UP: self.ids.armControl.text = "Lower Arm" else: self.ids.armControl.text = "Raise Arm" def toggleMagnet(self): toggle_magnet() if ON: self.ids.magnetControl.text = "Drop Ball" else: self.ids.magnetControl.text = "Hold Ball" def auto(self): global ON global UP temp_on = ON temp_up = UP ON = True toggle_magnet() UP = False toggle_arm() for i in range(0, 50): if is_ball_on_upper(): break print("Please place ball on higher tower.") sleep(1) else: return try_lift(is_ball_on_upper, upperTowerPositions, False) try_lift(is_ball_off_lower, lowerTowerPositions, True) ON = not temp_on toggle_magnet() UP = not temp_up toggle_arm() move_arm_final(self.armPosition) def setArmPosition(self, position): self.armPosition = position move_arm(self.armPosition) self.ids.armControlLabel.text = 'Arm Position: ' + str( int(self.armPosition)) def initialize(self): toggle_arm() toggle_magnet() home_arm() def resetColors(self): self.ids.armControl.color = YELLOW self.ids.magnetControl.color = YELLOW self.ids.auto.color = BLUE def quit(self): print("Exit") arm.free_all() GPIO.cleanup() GPIO.cleanup() cyprus.close() MyApp().stop()
# //////////////////////////////////////////////////////////////// # // DECLARE APP CLASS AND SCREENMANAGER // # // LOAD KIVY FILE // # //////////////////////////////////////////////////////////////// class MyApp(App): def build(self): self.title = "Perpetual Motion" return sm Builder.load_file('main.kv') Window.clearcolor = (.1, .1, .1, 1) # (WHITE) cyprus.open_spi() # //////////////////////////////////////////////////////////////// # // SLUSH/HARDWARE SETUP // # //////////////////////////////////////////////////////////////// sm = ScreenManager() ramp = stepper(port=0, speed=INIT_RAMP_SPEED) onGate = False cyprus.initialize() cyprus.setup_servo(2) cyprus.set_servo_position(2, 0) # //////////////////////////////////////////////////////////////// # // MAIN FUNCTIONS // # // SHOULD INTERACT DIRECTLY WITH HARDWARE // # ////////////////////////////////////////////////////////////////
MAIN_SCREEN_NAME = 'main' s1 = stepper(port=0, micro_steps=32, hold_current=20, run_current=20, accel_current=20, deaccel_current=20, steps_per_unit=200, speed=8) dire = 0 mcount = 1 dcount = 0 bcount = 1 switch_boolean = False cyprus.initialize() cyprus.setup_servo(1) cyprus.set_servo_position(1, 0.5) cyprus.close() class ProjectNameGUI(App): """ Class to handle running the GUI Application """ def build(self): """ Build the application :return: Kivy Screen Manager instance """ return SCREEN_MANAGER
def initialize(self): print("Home arm and turn off magnet") cyprus.set_servo_position(2, 0.5) self.homeArm()
class MainScreen(Screen): version = cyprus.read_firmware_version() #Slider.value = 0 lastClick = time.clock() #Slider.value = ObjectProperty(None) def __init__(self, **kwargs): super(MainScreen, self).__init__(**kwargs) self.initialize() def debounce(self): processInput = False currentTime = time.clock() if ((currentTime - self.lastClick) > DEBOUNCE): processInput = True self.lastClick = currentTime return processInput def toggleArmV(self): print("Process vertical arm movement here") self.setArmPositionV() 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 toggleArmH(self): print("Process horizontal arm movement here") self.setArmPositionH() def setArmPositionH(self): print("Move arm horizontally here") global HOME global position position = self.ids.moveArm.value * -1 while True: if HOME: #arm.set_as_home() print("arm moving") arm.go_to_position(position) #print(self.Slider.value) print("moved") #arm.softStop() break else: arm.goHome() print(" now at home") HOME = True break x = self.ids.moveArm.value #self.isBallOnTallTower() #if tall_OFF == False: #arm.start_relative_move(14) #else: # if short_OFF == False: # arm.start_relative_move(5) def toggleMagnet(self): print("Process magnet here") #talon motor self.setMagnet() def setMagnet(self): global OFF if OFF: cyprus.set_servo_position(2, 1) print("magnet has grabbed") self.ids.magnetControl.text = "Magnet Off" OFF = False else: cyprus.set_servo_position(2, 0.5) print("magnet has released") self.ids.magnetControl.text = "Magnet On" OFF = True def auto(self): print("Run the arm automatically here") self.isBallOnTallTower() if tall_OFF == False: print("ball in on top tower") arm.go_to_position(-12) cyprus.set_pwm_values(1, period_value=100000, compare_value=100000, compare_mode=cyprus.LESS_THAN_OR_EQUAL) print("lowered") sleep(0.5) cyprus.set_servo_position(2, 1) print("grabbed") sleep(0.5) cyprus.set_pwm_values(1, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL) print("raised") sleep(0.5) arm.go_to_position(-20) print("at final location") cyprus.set_pwm_values(1, period_value=100000, compare_value=100000, compare_mode=cyprus.LESS_THAN_OR_EQUAL) print("lowered") sleep(1) cyprus.set_servo_position(2, 0.5) print("released") sleep(0.5) cyprus.set_pwm_values(1, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL) print("raised") sleep(0.5) arm.go_to_position(0) else: self.isBallOnShortTower() if short_OFF == False: print("ball is at short tower") arm.go_to_position(-20) cyprus.set_pwm_values(1, period_value=100000, compare_value=100000, compare_mode=cyprus.LESS_THAN_OR_EQUAL) print("lowered") sleep(0.5) cyprus.set_servo_position(2, 1) print("grabbed") sleep(0.5) cyprus.set_pwm_values(1, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL) print("raised") sleep(0.5) arm.go_to_position(-12) print("at final location") cyprus.set_pwm_values(1, period_value=100000, compare_value=100000, compare_mode=cyprus.LESS_THAN_OR_EQUAL) print("lowered") sleep(1) cyprus.set_servo_position(2, 0.5) print("released") sleep(0.5) cyprus.set_pwm_values(1, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL) print("raised") sleep(0.5) arm.go_to_position(0) def homeArm(self): global homeDirection arm.home(1) def isBallOnTallTower(self): print("Determine if ball is on the top tower") global tall_OFF if ((cyprus.read_gpio() & 0b0001) == 0): print("GPIO on port P6 is LOW") tall_OFF = False else: tall_OFF = True def isBallOnShortTower(self): print("Determine if ball is on the bottom tower") global short_OFF if ((cyprus.read_gpio() & 0b0010) == 0): print("GPIO on port P7 is LOW") short_OFF = False else: short_OFF = True def initialize(self): print("Home arm and turn off magnet") cyprus.set_servo_position(2, 0.5) self.homeArm() def resetColors(self): self.ids.armControl.color = YELLOW self.ids.magnetControl.color = YELLOW self.ids.auto.color = BLUE def quit(self): MyApp().stop()
def auto(self): print("Run the arm automatically here") self.isBallOnTallTower() if tall_OFF == False: print("ball in on top tower") arm.go_to_position(-12) cyprus.set_pwm_values(1, period_value=100000, compare_value=100000, compare_mode=cyprus.LESS_THAN_OR_EQUAL) print("lowered") sleep(0.5) cyprus.set_servo_position(2, 1) print("grabbed") sleep(0.5) cyprus.set_pwm_values(1, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL) print("raised") sleep(0.5) arm.go_to_position(-20) print("at final location") cyprus.set_pwm_values(1, period_value=100000, compare_value=100000, compare_mode=cyprus.LESS_THAN_OR_EQUAL) print("lowered") sleep(1) cyprus.set_servo_position(2, 0.5) print("released") sleep(0.5) cyprus.set_pwm_values(1, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL) print("raised") sleep(0.5) arm.go_to_position(0) else: self.isBallOnShortTower() if short_OFF == False: print("ball is at short tower") arm.go_to_position(-20) cyprus.set_pwm_values(1, period_value=100000, compare_value=100000, compare_mode=cyprus.LESS_THAN_OR_EQUAL) print("lowered") sleep(0.5) cyprus.set_servo_position(2, 1) print("grabbed") sleep(0.5) cyprus.set_pwm_values(1, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL) print("raised") sleep(0.5) arm.go_to_position(-12) print("at final location") cyprus.set_pwm_values(1, period_value=100000, compare_value=100000, compare_mode=cyprus.LESS_THAN_OR_EQUAL) print("lowered") sleep(1) cyprus.set_servo_position(2, 0.5) print("released") sleep(0.5) cyprus.set_pwm_values(1, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL) print("raised") sleep(0.5) arm.go_to_position(0)
# //////////////////////////////////////////////////////////////// # // DECLARE APP CLASS AND SCREENMANAGER // # // LOAD KIVY FILE // # //////////////////////////////////////////////////////////////// class MyApp(App): def build(self): self.title = "Robotic Arm" return sm Builder.load_file('main.kv') Window.clearcolor = (.1, .1, .1, 1) # (WHITE) cyprus.open_spi() # //////////////////////////////////////////////////////////////// # // SLUSH/HARDWARE SETUP // # //////////////////////////////////////////////////////////////// sm = ScreenManager() arm = stepper(port=0, speed=10) cyprus.initialize() cyprus.setup_servo(2) # //////////////////////////////////////////////////////////////// # // MAIN FUNCTIONS // # // SHOULD INTERACT DIRECTLY WITH HARDWARE // # ////////////////////////////////////////////////////////////////
def setStaircaseSpeed(self, speed): if self.staircase.text == "Staircase Off": cyprus.set_motor_speed(1, speed) else: pass print("Set the staircase speed and update slider text")
class MainScreen(Screen): version = cyprus.read_firmware_version() armPosition = 0 lastClick = time.clock() armHeight = False magnet = False def __init__(self, **kwargs): super(MainScreen, self).__init__(**kwargs) self.initialize() def debounce(self): processInput = False currentTime = time.clock() if ((currentTime - self.lastClick) > DEBOUNCE): processInput = True self.lastClick = currentTime return processInput 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 toggleMagnet(self): print("Process magnet here") self.magnet = not self.magnet if self.magnet: cyprus.set_servo_position(2, 1) else: cyprus.set_servo_position(2, .5) def auto(self): print("Run the arm automatically here") shortTower = 30.25 tallTower = 38.9 if self.isBallOnTallTower(): shortTower = 38.9 tallTower = 30.25 arm.home(1) arm.go_to_position(shortTower) self.toggleMagnet() time.sleep(.5) self.toggleArm() time.sleep(1) self.toggleArm() time.sleep(.5) arm.go_to_position(tallTower) time.sleep(.5) self.toggleArm() time.sleep(.7) self.toggleMagnet() time.sleep(.5) self.toggleArm() time.sleep(.5) arm.home(1) def setArmPosition(self, position): if arm.get_position_in_units() == 0: self.ids.moveArm.value = 0 self.ids.armControlLabel.text = str(position) arm.go_to_position(position) print(arm.get_position_in_units()) print("Move arm here") def homeArm(self): arm.home(0) def isBallOnTallTower(self): print("Determine if ball is on the top tower") if cyprus.read_gpio() & 0b0001: sleep(.05) if cyprus.read_gpio() & 0b0001: print("proximity sensor off") return False return True def isBallOnShortTower(self): print("Determine if ball is on the bottom tower") if cyprus.read_gpio() & 0B0010: print("Nope!") return False print("Here") return True 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 resetColors(self): self.ids.armControl.color = YELLOW self.ids.magnetControl.color = YELLOW self.ids.auto.color = BLUE def quit(self): MyApp().stop()
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()
# //////////////////////////////////////////////////////////////// # // DECLARE APP CLASS AND SCREENMANAGER // # // LOAD KIVY FILE // # //////////////////////////////////////////////////////////////// class MyApp(App): def build(self): self.title = "Robotic Arm" return sm Builder.load_file('main.kv') Window.clearcolor = (.1, .1, .1, 1) # (WHITE) cyprus.open_spi() # //////////////////////////////////////////////////////////////// # // SLUSH/HARDWARE SETUP // # //////////////////////////////////////////////////////////////// sm = ScreenManager() arm = stepper(port=0, micro_steps=32, hold_current=20, run_current=20, accel_current=20, deaccel_current=20, steps_per_unit=25, speed=5)
def free_mtrs(self): s1.free() cyprus.initialize() cyprus.set_servo_position(1, 0.5) cyprus.close()
def is_ball_on_upper(): return (cyprus.read_gpio() & 0b0001) == 0
# //////////////////////////////////////////////////////////////// # // DECLARE APP CLASS AND SCREENMANAGER // # // LOAD KIVY FILE // # //////////////////////////////////////////////////////////////// class MyApp(App): def build(self): self.title = "Perpetual Motion" return sm Builder.load_file('main.kv') Window.clearcolor = (.1, .1, .1, 1) # (WHITE) cyprus.open_spi() # //////////////////////////////////////////////////////////////// # // SLUSH/HARDWARE SETUP // # //////////////////////////////////////////////////////////////// sm = ScreenManager() ramp = stepper(port=0, micro_steps=32, hold_current=20, run_current=20, accel_current=20, deaccel_current=20, steps_per_unit=25, speed=INIT_RAMP_SPEED) ramp.go_until_press(0, 20000) ramp.set_as_home()
# //////////////////////////////////////////////////////////////// # // DECLARE APP CLASS AND SCREENMANAGER // # // LOAD KIVY FILE // # //////////////////////////////////////////////////////////////// class MyApp(App): def build(self): self.title = "Perpetual Motion" return sm Builder.load_file('main.kv') Window.clearcolor = (.1, .1, .1, 1) # (WHITE) cyprus.open_spi() # //////////////////////////////////////////////////////////////// # // SLUSH/HARDWARE SETUP // # //////////////////////////////////////////////////////////////// sm = ScreenManager() ramp = stepper(port=0, speed=INIT_RAMP_SPEED) # //////////////////////////////////////////////////////////////// # // MAIN FUNCTIONS // # // SHOULD INTERACT DIRECTLY WITH HARDWARE // # //////////////////////////////////////////////////////////////// # //////////////////////////////////////////////////////////////// # // DEFINE MAINSCREEN CLASS THAT KIVY RECOGNIZES //
class MainScreen(Screen): version = cyprus.read_firmware_version() staircaseSpeedText = '0' rampSpeed = INIT_RAMP_SPEED staircaseSpeed = 40 staircase = ObjectProperty(None) rampSpeed = ObjectProperty(None) staircaseSpeed = ObjectProperty(None) def __init__(self, **kwargs): super(MainScreen, self).__init__(**kwargs) self.initialize() def toggleGate(self): print("Open and Close gate here") self.openGate() def openGate(self): global CLOSE if CLOSE: cyprus.set_servo_position(2, 0.5) CLOSE = False else: cyprus.set_servo_position(2, 0) CLOSE = True def toggleStaircase(self): print("Turn on and off staircase here") self.turnOnStaircase() 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 toggleRamp(self): print("Move ramp up and down here") self.moveRamp() #def isBallAtBottomOfRamp(self): #this function is on the exercise thing but do we need it? # ramp.set_as_home() 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 moveRamp(self): #cyprus.set_pwm_values(1, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL) #cyprus.set_servo_position(2, 0) global HOME #global TOP #if ((cyprus.read_gpio() & 0b0010)==0): # print("GPIO on port P7 is LOW") # print(" ramp moving") # ramp.start_relative_move(-228) #print("at top") # self.isBallAtTopOfRamp() # ramp.set_speed(40) # ramp.relative_move(228) # print("at home") # ramp.stop() #ramp.get_position_in_units() global INIT_RAMP_SPEED #ramp.go_until_press(1, 1) #ramp.set_as_home() # global TOP while True: #ramp.goHome() #ramp.softStop() if HOME: #ramp.get_position_in_units() ramp.set_as_home() print(" ramp moving") ramp.start_relative_move(-226) print("at top") self.isBallAtTopOfRamp() ramp.set_speed(INIT_RAMP_SPEED) #ramp.goHome() ramp.start_relative_move(226) print("at home") #ramp.stop() #HOME = False break # TOP = True else: ramp.go_until_press(1, 1) # ramp.goHome() print(" now at home") HOME = True break 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 setRampSpeed(self, speed): print("Set the ramp speed and update slider text") ramp.set_speed(self.rampSpeed.value) def setStaircaseSpeed(self, speed): global STAIRCASE_SPEED print("Set the staircase speed and update slider text") STAIRCASE_SPEED = self.staircaseSpeed.value cyprus.set_motor_speed(4, self.staircaseSpeed.value) def initialize(self): print("Close gate, stop staircase and home ramp here") def resetColors(self): self.ids.gate.color = YELLOW self.ids.staircase.color = YELLOW self.ids.ramp.color = YELLOW self.ids.auto.color = BLUE def quit(self): print("Exit") MyApp().stop()
class MainScreen(Screen): version = cyprus.read_firmware_version() staircaseSpeedText = '0' rampSpeed = INIT_RAMP_SPEED staircaseSpeed = 40 gate = False staircase = False ramp = False 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_speed(3.75) staircase_speed = 100000 def __init__(self, **kwargs): super(MainScreen, self).__init__(**kwargs) self.initialize() def thread_flip(self): y = threading.Thread(target=self.auto, daemon=True) y.start() def toggleGate(self): self.gate = not self.gate if self.gate: cyprus.set_servo_position(2, .48) else: cyprus.set_servo_position(2, 0) print("Open and Close gate here") 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 toggleRamp(self): self.ramp = not self.ramp if self.ramp: self.s0.start_relative_move(29) else: self.s0.start_relative_move(-29) print("Move ramp up and down here") def auto(self): """"" while True: if cyprus.read_gpio() and 0B0010: pass else: self.s0.start_relative_move(29) if cyprus.read_gpio() and 0B001: pass else: """ "" self.toggleRamp() time.sleep(7.75) self.s0.set_speed(4) self.toggleRamp() time.sleep(1) self.toggleStaircase() time.sleep(5.25) self.toggleGate() time.sleep(1.75) self.toggleStaircase() time.sleep(.5) self.toggleGate() print("Run through one cycle of the perpetual motion machine") def setRampSpeed(self, speed): self.s0.set_speed(speed) self.ids.rampSpeedLabel.text = "Ramp Speed: " + "{:.1f}".format(speed) print("Set the ramp speed and update slider text") 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 initialize(self): cyprus.setup_servo(2) cyprus.setup_servo(1) print("Close gate, stop staircase and home ramp here") def resetColors(self): self.ids.gate.color = YELLOW self.ids.staircase.color = YELLOW self.ids.ramp.color = YELLOW self.ids.auto.color = BLUE def quit(self): print("Exit") MyApp().stop()
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
from pidev.Cyprus_Commands import Cyprus_Commands_RPi as ccrpi ccrpi.open_spi() from pidev import stepper ##led = stepper(port = 1, speed = 50) ##for i in range(1, 255): ## print("lup") ccrpi.write_pwm(1, ccrpi.COMPARE_MODE, ccrpi.LESS_THAN) ccrpi.write_pwm(1, ccrpi.PERIOD, .001) ccrpi.write_pwm(1, ccrpi.COMPARE, .001) ccrpi.write_pwm(2, ccrpi.COMPARE_MODE, ccrpi.LESS_THAN) ccrpi.write_pwm(2, ccrpi.PERIOD, .001) ccrpi.write_pwm(2, ccrpi.COMPARE, .001) ## ccrpi.set_servo_speed(1, -0.5)
def setStaircaseSpeed(self, speed): global STAIRCASE_SPEED print("Set the staircase speed and update slider text") STAIRCASE_SPEED = self.staircaseSpeed.value cyprus.set_motor_speed(4, self.staircaseSpeed.value)
def get_trigger_button_state(): if cyprus.read_gpio() & 0b0001: return 'up'
# //////////////////////////////////////////////////////////////// # // DECLARE APP CLASS AND SCREENMANAGER // # // LOAD KIVY FILE // # //////////////////////////////////////////////////////////////// class MyApp(App): def build(self): self.title = "Robotic Arm" return sm Builder.load_file('main.kv') Window.clearcolor = (.1, .1, .1, 1) # (WHITE) cyprus.open_spi() ballOnTallTower = False # //////////////////////////////////////////////////////////////// # // SLUSH/HARDWARE SETUP // # //////////////////////////////////////////////////////////////// sm = ScreenManager() arm = stepper(port=0, speed=10) cyprus.initialize() cyprus.setup_servo(1) # cytron cyprus.setup_servo(2) # talon """ Port 4: Cytron
def transition_back(): SCREEN_MANAGER.current = MAIN_SCREEN cyprus.close()
def cleanup(self): cyprus.set_servo_position(1, .5) cyprus.close() spi.close() GPIO.cleanup() quit()