Exemple #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")
 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)
Exemple #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
 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"
Exemple #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")
 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)
Exemple #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
Exemple #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()
Exemple #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
Exemple #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)
Exemple #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
Exemple #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
 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 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
Exemple #17
0
 def checkBottom(self):
     global bottom
     while bottom:
         if (cyprus.read_gpio() & 0b0010) == 0:
             self.toggleGate()
             self.toggleStaircase()
             bottom = False
         sleep(0.1)
Exemple #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)
Exemple #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)
Exemple #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()
 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 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")
Exemple #23
0
 def isGPIO_P6_HIGH(self):
     return (cyprus.read_gpio() & 0b0001) == 1
Exemple #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()
Exemple #25
0
 def get_trigger_button_state():
     if cyprus.read_gpio() & 0b0001:
         return 'up'
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
# 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
def is_ball_on_upper():
    return (cyprus.read_gpio() & 0b0001) == 0
def is_ball_off_lower():
    return (cyprus.read_gpio() & 0b0010) != 0
Exemple #30
0
def is_ball_at_top():
    return (cyprus.read_gpio() & 0b0001) == 0