コード例 #1
0
ファイル: main.py プロジェクト: nataliesigurdson/Kundts-Tube
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 wiggle(self):
        s1.home(1)
        s1.relative_move(-3)

        s0.relative_move(-1)
        s0.relative_move(1)
        s0.relative_move(-2)
        s0.relative_move(2)
        s0.relative_move(-3)
        s0.relative_move(3)

    # if s0.get_position_in_units > 3.0 & s0.get_position_in_units < 112.0:
    def test_sticking(self):
        s0.get_position_in_units()
        pos_s0 = s0.get_position_in_units()
        pos_s1 = s1.get_position_in_units()
        if pos_s0 > 4.0:
            if pos_s0 < 109.0:
                self.wiggle()
                print("not home")

        s1.home(1)
        s1.relative_move(-3)
        s0.home(1)
        print("went home")
        s0.go_to_position(-28)
        self.wiggle()
        s0.go_to_position(-56)
        self.wiggle()
        s0.go_to_position(-84)
        self.wiggle()
        s0.go_to_position(-112)
        sleep(0.5)
        s0.go_to_position(-84)
        self.wiggle()
        s0.go_to_position(-56)
        self.wiggle()
        s0.go_to_position(-28)
        self.wiggle()
        s0.home(1)

    def reset(self):
        x = s0.get_position_in_units()
        s1.home(1)
        s1.start_relative_move(-3)
        if x > 3.0:
            if x < 112.0:
                self.wiggle()
        s0.home(1)
        s1.home(1)
コード例 #2
0
ファイル: main.py プロジェクト: ElianaBohn/RoboticArmWidget
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):
        print("Process arm movement here")
        self.setArmPosition()

    def toggleMagnet(self):
        print("Process magnet here")

    def auto(self):
        print("Run the arm automatically here")

    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 homeArm(self):
        arm.home(self.homeDirection)

    def isBallOnTallTower(self):
        print("Determine if ball is on the top tower")

    def isBallOnShortTower(self):
        print("Determine if ball is on the bottom tower")

    def initialize(self):
        print("Home arm and turn off magnet")

    def resetColors(self):
        self.ids.armControl.color = YELLOW
        self.ids.magnetControl.color = YELLOW
        self.ids.auto.color = BLUE

    def quit(self):
        MyApp().stop()
コード例 #3
0
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()
コード例 #4
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()
コード例 #5
0
ファイル: main.py プロジェクト: cbohley/Robotic-Arm-Widget
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()
コード例 #6
0
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()
コード例 #7
0
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()
コード例 #8
0
ファイル: main.py プロジェクト: beebopenguin/PerpetualMotion
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()
コード例 #9
0
class MainScreen(Screen):
    version = cyprus.read_firmware_version()
    rampSpeed = INIT_RAMP_SPEED
    staircaseSpeed = INIT_SC_SPEED

    def __init__(self, **kwargs):
        super(MainScreen, self).__init__(**kwargs)
        self.initialize()

    def toggleGate(self):
        toggle_gate()
        if OPEN:
            self.ids.gate.text = "Close Gate"
        else:
            self.ids.gate.text = "Open Gate"

    def toggleStaircase(self):
        toggle_staircase(self.staircaseSpeed)
        if ON:
            self.ids.staircase.text = "Staircase Off"
        else:
            self.ids.staircase.text = "Staircase On"

    def toggleRamp(self):
        move_ramp()
        if TOP:
            self.ids.ramp.text = "Ramp to Home"
        else:
            self.ids.ramp.text = "Ramp to Top"

    def auto(self):
        global ON
        global OPEN
        global TOP
        ON = True
        OPEN = True
        TOP = True
        sc_temp = self.staircaseSpeed
        ramp_temp = self.rampSpeed
        self.staircaseSpeed = INIT_SC_SPEED
        self.rampSpeed = INIT_RAMP_SPEED
        set_staircase_speed(self.staircaseSpeed)
        set_ramp_speed(self.rampSpeed)
        self.initialize()
        while not debounce(False):
            print("Please place ball at home.")
            sleep(1)
        move_ramp()
        while ramp.is_busy():
            sleep(0.1)
        toggle_staircase(self.staircaseSpeed)
        move_ramp()
        toggle_staircase(self.staircaseSpeed)
        toggle_gate()

        self.staircaseSpeed = sc_temp
        self.rampSpeed = ramp_temp
        set_staircase_speed(self.staircaseSpeed)
        set_ramp_speed(self.rampSpeed)

    def setRampSpeed(self, speed):
        self.rampSpeed = speed
        set_ramp_speed(self.rampSpeed)
        self.ids.rampSpeedLabel.text = 'Ramp Speed: ' + str(self.rampSpeed)

    def setStaircaseSpeed(self, speed):
        self.staircaseSpeed = speed
        set_staircase_speed(self.staircaseSpeed)
        self.ids.staircaseSpeedLabel.text = 'Staircase Speed: ' + str(
            self.staircaseSpeed)

    def initialize(self):
        move_ramp()
        toggle_gate()
        toggle_staircase(self.staircaseSpeed)

    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")
        ramp.free_all()
        GPIO.cleanup()
        GPIO.cleanup()
        cyprus.close()
        MyApp().stop()
コード例 #10
0
class MainScreen(Screen):
    version = cyprus.read_firmware_version()
    staircaseSpeedText = '0'
    global rspeed
    global sspeed
    sspeed = 0.5
    rspeed = 2

    def __init__(self, **kwargs):
        super(MainScreen, self).__init__(**kwargs)
        self.initialize()

    def check_text(self, mod):
        if mod == 'gate':
            if self.gate.text == "Open Gate":
                return 'Off'
            elif self.gate.text == "Close Gate":
                return 'On'
        elif mod == 'staircase':
            if self.staircase.text == "Start Staircase":
                return 'Off'
            elif self.staircase.text == "Stop Staircase":
                return 'On'
        elif mod == 'ramp':
            if self.ramp.text == "Ramp Up":
                return 'Off'
            elif self.ramp.text == "Ramp Down":
                return 'On'

    # checks states

    def toggle_gate(self):
        if self.check_text('gate') == 'Off':
            self.gate.text = "Close Gate"
            cyprus.set_servo_position(2, 0.5)
        elif self.check_text('gate') == 'On':
            self.gate.text = "Open Gate"
            cyprus.set_servo_position(2, 0)

    # changes gate state

    def toggle_staircase(self):
        global sspeed
        if self.check_text('staircase') == 'Off':
            self.staircase.text = "Stop Staircase"
            cyprus.set_motor_speed(1, sspeed)
        elif self.check_text('staircase') == 'On':
            self.staircase.text = "Start Staircase"
            cyprus.set_motor_speed(1, 0)

    # changes staircase state

    def set_staircase_speed(self, speedy):
        global sspeed
        cyprus.set_motor_speed(1, 0)
        if self.check_text('staircase') == 'Off':
            pass
        elif self.check_text('staircase') == 'On':
            cyprus.set_motor_speed(1, speedy)
            sspeed = speedy

    # updates speed value based on slider

    def toggle_ramp(self):
        if self.check_text('ramp') == 'Off':
            self.ramp.text = "Ramp Down"
            self.move_ramp()
        elif self.check_text('ramp') == 'On':
            self.ramp.text = "Ramp Up"
            self.move_ramp()

    @staticmethod
    def move_ramp():
        ramp.free()

        if ramp.read_switch() == 1:
            ramp.go_to_position(29)
            ramp.free()
        elif ramp.get_position_in_units() == 29:
            axis1.goTo(0)

        else:
            while axis1.isBusy():
                continue
            axis1.goUntilPress(0, 0, 5000)

            while axis1.isBusy():
                continue
            axis1.setAsHome()

    def set_ramp_speed(self, speedz):
        global rspeed
        cyprus.set_motor_speed(1, 0)
        if self.check_text('ramp') == 'Off':
            pass
        elif self.check_text('ramp') == 'On':
            cyprus.set_motor_speed(1, speedz)
            rspeed = speedz

    def auto(self):
        ramp.set_speed(3.5)
        cyprus.set_servo_position(2, 0)
        cyprus.set_motor_speed(1, 0)
        Clock.schedule_once(lambda dt: self.move_ramp(), 0.01)
        Clock.schedule_once(lambda dt: self.part2(), 9)
        Clock.schedule_once(lambda dt: self.part3(), 18)

    @staticmethod
    def part2():
        ramp.set_speed(3.5)
        ramp.goHome()
        cyprus.set_motor_speed(1, 1)

    @staticmethod
    def part3():
        cyprus.set_motor_speed(1, 0)
        cyprus.set_servo_position(2, 0.5)

    @staticmethod
    def initialize():
        ramp.free()
        ramp.set_speed(3.5)
        cyprus.initialize()
        cyprus.setup_servo(2)
        cyprus.set_motor_speed(1, 0)
        cyprus.set_servo_position(2, 0)

    def resetColors(self):
        self.ids.gate.color = YELLOW
        self.ids.staircase.color = YELLOW
        self.ids.ramp.color = YELLOW
        self.ids.auto.color = BLUE

    @staticmethod
    def quit():
        print("Exit")
        ramp.free()
        cyprus.close()
        MyApp().stop()
コード例 #11
0
class MainScreen(Screen):
    global rampSpeed
    global staircaseSpeed
    version = cyprus.read_firmware_version()
    staircaseSpeedText = '0'
    rampSpeed = INIT_RAMP_SPEED
    staircaseSpeed = 40

    def __init__(self, **kwargs):
        super(MainScreen, self).__init__(**kwargs)
        self.initialize()

    gate = ObjectProperty(None)
    staircase = ObjectProperty(None)
    staircaseSpeedLabel = ObjectProperty(None)
    rampSpeedLabel = ObjectProperty(None)

    def toggleGate(self):
        global gate_count
        if gate_count % 2 == 0:
            self.gate.text = "Close Gate"
            cyprus.set_servo_position(2, 0.5)
            sleep(0.1)
        else:
            self.gate.text = "Open Gate"
            cyprus.set_servo_position(2, 0.25)
            sleep(0.1)
        gate_count += 1

    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 toggleRamp(self):
        global s0, rampSpeed
        s0.set_speed_in_steps(rampSpeed * 6)
        s0.relative_move(28.5)
        sleep(0.5)
        s0.goHome()
        while s0.isBusy() == True:
            yurrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr = 2

    def auto_program(self):
        global bottom
        while True:
            self.toggleRamp()
            sleep(1)
            self.toggleStaircase()
            sleep(5)
            self.toggleGate()
            bottom = True
            self.checkBottom()

    def auto(self):
        Thread(target=self.auto_program).start()
        Thread.daemon = True

    def setRampSpeed(self, speed):
        global rampSpeed
        rampSpeed = speed
        self.rampSpeedLabel.text = "Ramp Speed: " + str(speed)

    def setStaircaseSpeed(self, speed):
        global staircaseSpeed
        staircaseSpeed = speed * 10000
        self.staircaseSpeedLabel.text = "Staircase Speed: " + str(speed)

    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 checkBottom(self):
        global bottom
        while bottom:
            if (cyprus.read_gpio() & 0b0010) == 0:
                self.toggleGate()
                self.toggleStaircase()
                bottom = False
            sleep(0.1)

    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()