예제 #1
0
    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")
예제 #2
0
 def servoThread(self):
     global servo
     while servo:
         if (cyprus.read_gpio() & 0b0001):
             sleep(.1)
             if (cyprus.read_gpio() & 0b0001):
                 cyprus.set_servo_position(1, 0)
         else:
             cyprus.set_servo_position(1, 1)
예제 #3
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
예제 #4
0
 def flip(self):
     if cyprus.read_gpio() & 0B0001:
         time.sleep(.05)
         if cyprus.read_gpio() & 0B0001:
             cyprus.set_servo_position(1, 1)
             self.ids.flip.text = "180 Degrees"
         else:
             cyprus.set_servo_position(1, 0)
             self.ids.flip.text = "0 Degrees"
예제 #5
0
    def talonDCMotorFullSpeedWhenPressed(self):  # talon motor is in 1 (port 4)
        cyprus.setup_servo(1)
        cyprus.set_servo_position(1, 0.5)

        while True:
            if cyprus.read_gpio() & 0b0001:
                sleep(0.05)
                if cyprus.read_gpio() & 0b0001:
                    cyprus.set_servo_position(1, 0.5)
            else:
                cyprus.set_servo_position(1, 1)
 def bs(self):
     global x
     while x:
         if(cyprus.read_gpio() & 0b0001):
             sleep(.1)
             if (cyprus.read_gpio() & 0b0001):
                 cyprus.set_servo_position(1, 0)
                 print("a")
         else:
             cyprus.set_servo_position(1, 1)
             print("f")
 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")
예제 #8
0
 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)
예제 #9
0
    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
예제 #10
0
 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()
예제 #11
0
    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
예제 #12
0
 def is_it_on():
     if cyprus.read_gpio() & 0b0001:
         cyprus.set_servo_speed(1, 0)
         sleep(0.05)
     else:
         cyprus.set_servo_position(1, 0)
         sleep(0.05)
예제 #13
0
    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
예제 #14
0
 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
예제 #15
0
 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
예제 #16
0
 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
예제 #17
0
 def checkBottom(self):
     global bottom
     while bottom:
         if (cyprus.read_gpio() & 0b0010) == 0:
             self.toggleGate()
             self.toggleStaircase()
             bottom = False
         sleep(0.1)
예제 #18
0
 def switchThread(self):
     global switchPort
     global checking
     while checking:
         if switchPort == 6:
             val = 0b0001
         elif switchPort == 7:
             val = 0b0010
         elif switchPort == 8:
             val = 0b0100
         if (cyprus.read_gpio() & val):
             sleep(.1)
             if (cyprus.read_gpio() & val):
                 self.ids.toggle_sensing_label.text = "Not Sensing"
                 self.ids.toggle_sensing_label.color = (1, 0, 0, .8)
         else:
             self.ids.toggle_sensing_label.text = "Sensing"
             self.ids.toggle_sensing_label.color = (0, 1, 0, .8)
예제 #19
0
    def servoMotorBinaryState(self):
        cyprus.initialize()
        cyprus.setup_servo(2)

        while True:
            if cyprus.read_gpio() & 0b0001:
                cyprus.set_servo_position(2, 0)  # close gate
                sleep(1)
            else:
                cyprus.set_servo_position(2, .7)  # open gate
                sleep(1)
예제 #20
0
 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()
예제 #21
0
 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")
예제 #22
0
 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")
예제 #23
0
 def isGPIO_P6_HIGH(self):
     return (cyprus.read_gpio() & 0b0001) == 1
예제 #24
0
 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()
예제 #25
0
 def get_trigger_button_state():
     if cyprus.read_gpio() & 0b0001:
         return 'up'
예제 #26
0
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

cyprus.initialize()
if (cyprus.read_gpio()
        & 0b0001):  # binary bitwise AND of the value returned from read.gpio()
    print("GPIO on port P6 is HIGH")
elif (cyprus.read_gpio() & 0b0010):
    print("GPIO on port P7 is HIGH")
elif (cyprus.read_gpio() & 0b0100):
    print("GPIO on port P8 is HIGH")
elif (cyprus.read_gpio() & 0b1000):
    print("GPIO on port P9 is HIGH")
cyprus.close()

# To get the status of a GPIO pin one could create a method like this:
#     def isGPIO_P6_HIGH(self):
#         return (cyprus.read_gpio() & 0b0001) == 1
#
# Checks to see if gpio read and bitwise AND are equal to 1. If so returns TRUE otherwise returns FALSE
예제 #27
0
# 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

cyprus.initialize()
if (cyprus.read_gpio() & 0b0001):    # binary bitwise AND of the value returned from read.gpio()
    print("GPIO on port P6 is HIGH")
elif (cyprus.read_gpio() & 0b0010):
    print("GPIO on port P7 is HIGH")
elif (cyprus.read_gpio() & 0b0100):
    print("GPIO on port P8 is HIGH")
else (cyprus.read_gpio() & 0b1000):
    print("GPIO on port P9 is HIGH")
cyprus.close()

# To get the status of a GPIO pin one could create a method like this:
#     def isGPIO_P6_HIGH(self):
#         return (cyprus.read_gpio() & 0b0001) == 1
#
# Checks to see if gpio read and bitwise AND are equal to 1. If so returns TRUE otherwise returns FALSE
예제 #28
0
def is_ball_on_upper():
    return (cyprus.read_gpio() & 0b0001) == 0
예제 #29
0
def is_ball_off_lower():
    return (cyprus.read_gpio() & 0b0010) != 0
예제 #30
0
def is_ball_at_top():
    return (cyprus.read_gpio() & 0b0001) == 0