Ejemplo n.º 1
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()
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
 def ramp_up(self):
     cyprus.initialize()
     cyprus.setup_servo(1)
     for i in range(2, 4, 6, 8, 10):
         cyprus.set_servo_speed(1, i/10.0)
         sleep(4)
     cyprus.set_servo_position(1, 0.5)
     cyprus.close()
Ejemplo n.º 4
0
 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()
Ejemplo n.º 5
0
 def cyprus_setup(self):
     global servo_state
     servo_state = 0
     cyprus.initialize()
     cyprus.setup_servo(1)
     cyprus.set_servo_position(1, 0)
     sleep(0.2)
     self.start_cyprus_thread()
Ejemplo n.º 6
0
 def start_talon(self):
     cyprus.initialize()
     cyprus.set_servo_position(1, 1)
     sleep(5)
     cyprus.set_servo_position(1, 0)
     sleep(5)
     cyprus.set_servo_position(1, 0.5)
     cyprus.close()
Ejemplo n.º 7
0
 def talon_switch(self):
     cyprus.initialize()
     cyprus.setup_servo(1)
     def isGPIO_P6_HIGH(self):
         return (cyprus.read_gpio() & 0b0001) == 1
     if isGPIO_P6_HIGH(self):
         cyprus.set_servo_speed(1, 0)
     else:
         cyprus.set_servo_speed(1, 1)
Ejemplo n.º 8
0
 def limit_switch(self):
     cyprus.initialize()
     cyprus.setup_servo(1)
     def isGPIO_P6_HIGH(self):
         return (cyprus.read_gpio() & 0b0001) == 1
     if isGPIO_P6_HIGH(self):
         cyprus.set_servo_position(1, 0)
     else:
         cyprus.set_servo_position(1, 1)
Ejemplo n.º 9
0
 def talon_spup(self):
     cyprus.initialize()
     cyprus.set_servo_position(1, 0.5)
     for i in range(6, 11, 1):
         print(i)
         cyprus.set_servo_position(1, i / 10.0)
         sleep(4)
     cyprus.set_servo_position(1, 0.5)
     cyprus.close()
Ejemplo n.º 10
0
 def exit_ui(self):
     s1.free()
     cyprus.initialize()
     #cyprus.set_servo_position(1, 0.5)
     cyprus.set_pwm_values(2,
                           period_value=100000,
                           compare_value=0,
                           compare_mode=cyprus.LESS_THAN_OR_EQUAL)
     #cyprus.close()
     exit()
Ejemplo n.º 11
0
 def cytron_dc(self):
     cyprus.initialize()
     cyprus.set_pwm_values(2, period_value=100000, compare_value=100000, compare_mode=cyprus.LESS_THAN_OR_EQUAL)
     sleep(.5)
     cyprus.set_pwm_values(2, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL)
     sleep(5)
     cyprus.set_pwm_values(2, period_value=100000, compare_value=-100000, compare_mode=cyprus.LESS_THAN_OR_EQUAL)
     sleep(.5)
     cyprus.set_pwm_values(2, period_value=100000, compare_value=0, compare_mode=cyprus.LESS_THAN_OR_EQUAL)
     cyprus.close()
Ejemplo n.º 12
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)
Ejemplo n.º 13
0
    def talonDCMotor(self):
        cyprus.initialize()
        cyprus.setup_servo(1)

        cyprus.set_servo_position(1, 1)
        sleep(5)
        cyprus.set_servo_position(1, 0.5)
        sleep(5)
        cyprus.set_servo_position(1, 0)
        sleep(5)
        cyprus.set_servo_position(1, 0.5)
Ejemplo n.º 14
0
 def talon_dc(self):
     cyprus.initialize()
     cyprus.setup_servo(1)
     cyprus.set_servo_speed(1, 1)
     sleep(1)
     cyprus.set_servo_speed(1, 0)
     sleep(5)
     cyprus.set_servo_speed(1, -1)
     sleep(1)
     cyprus.set_servo_speed(1, 0)
     cyprus.close()
Ejemplo n.º 15
0
 def servoPressed(self):
     global pos
     cyprus.initialize(
     )  # initialize the RPiMIB and establish communication
     cyprus.setup_servo(
         2)  # sets up P4 on the RPiMIB as a RC servo style output
     if pos:
         cyprus.set_servo_position(1, 0)
         pos = False
     else:
         cyprus.set_servo_position(1, 1)
         pos = True
Ejemplo n.º 16
0
 def servo_binary(self):
     global bcount
     cyprus.initialize()
     if bcount % 2 == 0:
         self.servooo.text = "0 Deg"
         cyprus.set_servo_position(1, 0)
         sleep(0.1)
     else:
         self.servooo.text = "180 Deg"
         cyprus.set_servo_position(1, 1)
         sleep(0.1)
     bcount += 1
     cyprus.close()
Ejemplo n.º 17
0
    def tickArrows(self, way):
        cyprus.initialize()
        cyprus.setup_servo(2)
        num = self.ids.PWM_slider.value
        if way == "up":
            if self.ids.cytron_label.text == "Neutral":
                num = 55
            elif num == 45:
                num = 50
            elif num == 100:
                num = 100
            else:
                num += 1
        elif way == "down":
            if self.ids.cytron_label.text == "Neutral":
                num = 45
            elif num == 55:
                num = 50
            elif num == 0:
                num = 0
            else:
                num -= 1
        if (num > 45) and (num < 55):
            self.ids.cytron_label.text = "Neutral"
            self.ids.cytron_label.color = (1, .65, 0, .8)
            self.ids.PWM_slider.value = 50
            val = 0
        elif num > 54:
            s = "Forward " + str(num - 50)
            self.ids.cytron_label.text = s
            self.ids.cytron_label.color = (0, 1, 0, .8)
            self.ids.PWM_slider.value = num
            val = (self.ids.PWM_slider.value - 50) * 200
            direction = 1
        else:
            s = "Backward " + str(num - 50)
            self.ids.cytron_label.text = s
            self.ids.cytron_label.color = (1, 0, 0, .8)
            self.ids.PWM_slider.value = num
            val = (50 - self.ids.PWM_slider.value) * 200
            direction = 0

        cyprus.set_pwm_values(2, period_value=10000, compare_value=val,
                              compare_mode=cyprus.LESS_THAN_OR_EQUAL)
Ejemplo n.º 18
0
 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()
Ejemplo n.º 19
0
    def tickArrows(self, way):
        cyprus.initialize()
        cyprus.setup_servo(2)
        num = self.ids.PWM_slider.value
        if way == "up":
            if self.ids.talon_label.text == "Neutral":
                num = 55
            elif num == 45:
                num = 50
            elif num == 100:
                num = 100
            else:
                num += 1
        elif way == "down":
            if self.ids.talon_label.text == "Neutral":
                num = 45
            elif num == 55:
                num = 50
            elif num == 0:
                num = 0
            else:
                num -= 1
        spd = num / 100
        if (num > 45) and (num < 55):
            self.ids.talon_label.text = "Neutral"
            self.ids.talon_label.color = (1, .65, 0, .8)
            self.ids.PWM_slider.value = 50
            spd = .5
        elif num > 54:
            s = "Forward " + str(num - 50)
            self.ids.talon_label.text = s
            self.ids.talon_label.color = (0, 1, 0, .8)
            self.ids.PWM_slider.value = num
            spd = spd - .03
        else:
            s = "Backward " + str(num - 50)
            self.ids.talon_label.text = s
            self.ids.talon_label.color = (1, 0, 0, .8)
            self.ids.PWM_slider.value = num
            spd = spd + .03

        cyprus.set_servo_position(2, spd)
Ejemplo n.º 20
0
    def updateLabel(self):
        cyprus.initialize()
        cyprus.setup_servo(2)
        spd = self.ids.PWM_slider.value / 100
        if (self.ids.PWM_slider.value > 45) and (self.ids.PWM_slider.value < 55):
            self.ids.talon_label.text = "Neutral"
            self.ids.talon_label.color = (1, .65, 0, .8)
            spd = .5
        elif self.ids.PWM_slider.value > 54:
            s = "Forward " + str(self.ids.PWM_slider.value - 50)
            self.ids.talon_label.text = s
            self.ids.talon_label.color = (0, 1, 0, .8)
            spd = spd - .03
        else:
            s = "Backward " + str(self.ids.PWM_slider.value - 50)
            self.ids.talon_label.text = s
            self.ids.talon_label.color = (1, 0, 0, .8)
            spd = spd + .03

        cyprus.set_servo_position(2, spd)
Ejemplo n.º 21
0
 def updateLabel(self):
     cyprus.initialize()
     if (self.ids.PWM_slider.value < 55) and (self.ids.PWM_slider.value > 45):
         self.ids.cytron_label.text = "Neutral"
         self.ids.cytron_label.color = (1, .65, 0, .8)
         val = 0
     elif self.ids.PWM_slider.value > 54:
         s = "Forward " + str(abs(self.ids.PWM_slider.value) - 50)
         self.ids.cytron_label.text = s
         self.ids.cytron_label.color = (0, 1, 0, .8)
         val = (self.ids.PWM_slider.value - 50) * 200
         direction = 1
     else:
         s = "Backward " + str(abs(self.ids.PWM_slider.value) - 50)
         self.ids.cytron_label.text = s
         self.ids.cytron_label.color = (1, 0, 0, .8)
         val = (50 - self.ids.PWM_slider.value) * 200
         direction = 0
     cyprus.set_pwm_values(2, period_value=10000, compare_value=val,
                           compare_mode=cyprus.LESS_THAN_OR_EQUAL)
Ejemplo n.º 22
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()
Ejemplo n.º 23
0
 def setup():
     cyprus.initialize()
     cyprus.setup_servo(1)
     cyprus.set_servo_speed(1, 0)
     sleep(0.05)
Ejemplo n.º 24
0
#    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
Ejemplo n.º 25
0

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
Port 5: Talon
Port 6: Tall Tower Sensor
Port 7: Short Tower Sensor
Port 8: N/A

38.9 is the tall tower
30.25 is the short tower
"""
# ////////////////////////////////////////////////////////////////
# //                       MAIN FUNCTIONS                       //
Ejemplo n.º 26
0
 def free_mtrs(self):
     s1.free()
     cyprus.initialize()
     cyprus.set_servo_position(1, 0.5)
     cyprus.close()
Ejemplo n.º 27
0
 def binary_state(self):
     cyprus.initialize()
     cyprus.setup_servo(1)
     cyprus.set_servo_position(1, 0)
     sleep(1)
     cyprus.set_servo_position(1, 1)
Ejemplo n.º 28
0
 def back(self):
     SCREEN_MANAGER.transition.direction = 'right'
     SCREEN_MANAGER.current = "motors"
     cyprus.set_servo_position(1, .5)
     cyprus.initialize()
Ejemplo n.º 29
0
class MainScreen(Screen):
    """
    Class to handle the main screen and its associated touch events
    """
    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)
    cyprus.initialize()
    cyprus.setup_servo(1)

    go = False
    direction_pin = 1

    def thread_flip(self):
        y = threading.Thread(target=self.flip, daemon=True)
        y.start()

    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"

    def pressed(self):

        self.go = not self.go

        if self.go:
            self.s0.run(self.direction_pin, int(self.ids.slider.value))
            self.ids.motor.text = "Motor On"
        else:
            self.s0.softStop()
            self.ids.motor.text = "Motor Off"

    def direction(self):
        if self.go:
            if self.direction_pin == 1:
                self.direction_pin = 0
                self.ids.direction.text = "Clockwise"
                self.s0.run(self.direction_pin, int(self.ids.slider.value))
            else:
                self.direction_pin = 1
                self.ids.direction.text = "Counter-Clockwise"
                self.s0.run(self.direction_pin, int(self.ids.slider.value))

    def motor_thread(self):
        y = threading.Thread(target=self.motor, daemon=True)
        y.start()

    def motor(self):
        self.s0.set_as_home()
        print(self.s0.get_position_in_units())
        self.ids.updates.text = str(self.s0.get_position_in_units())
        self.s0.set_speed(1)
        self.s0.go_to_position(15)
        print(self.s0.get_position_in_units())
        self.ids.updates.text = str(self.s0.get_position_in_units())
        time.sleep(10)

        self.s0.set_speed(5)
        self.s0.relative_move(10)
        self.ids.updates.text = str(self.s0.get_position_in_units())
        time.sleep(8)

        self.s0.relative_move(-25)
        self.ids.updates.text = str(self.s0.get_position_in_units())
        time.sleep(30)

        self.s0.set_speed(8)
        self.s0.relative_move(-100)
        self.ids.updates.text = str(self.s0.get_position_in_units())
        time.sleep(10)

        self.s0.relative_move(100)
        self.ids.updates.text = "Finished: " + str(
            self.s0.get_position_in_units())

    def admin_action(self):
        """
        Hidden admin button touch event. Transitions to passCodeScreen.
        This method is called from pidev/kivy/PassCodeScreen.kv
        :return: None
        """
        SCREEN_MANAGER.current = 'passCode'