Пример #1
0
def planned_shuffle(d_motor:DispenseStep, p_motor:PushStep, b_motor:BinStep, dispenser:Dispenser, camera:Camera, deck):
    # Initialize vars
    dispenser.enable_motor()
    dispenser.baseline_motor_cur()
    t_last_dispense = time.time()
    n_bins = len(cfg.bin_heights_load_mm)
    cards_in_trash = 0

    camera.start_camera()

    # Generate bin reqs for deck
    deck.break_into_bins(n_bins=n_bins)

    def empty_trash():
        p_motor.enable()
        b_motor.unload_bin_pos(n_bins-1)
        time.sleep(0.1)
        p_motor.run()
        p_motor.disable()

    junk_cards_dispensed = 0
    last_card = camera.read_card()
    while junk_cards_dispensed < cfg.planned_shuffle_timeout:
        card = camera.read_card()

        # Determine where to put card. If it is the same as last, it probs failed to dispense
        if card.rank is None and card.suit is None:
            bin_index = None
        elif last_card.rank is card.rank and last_card.suit is card.suit:
            print('Previous card failed to dispense. Re-dispensing')
            pass
        else:
            bin_index = deck.get_bin(card)
            last_card = card
            print(card.rank, card.suit, ":", bin_index)

            # Handle vars if trash card
            if bin_index is None:
                bin_index = n_bins - 1
                cards_in_trash += 1
                junk_cards_dispensed += 1

            # Move to bin location
            b_motor.load_bin_pos(bin_index)

        # Dispense card
        while time.time() < t_last_dispense + cfg.min_time_between_dispenses_s:
            pass
        if not dispenser.dispense_card():
            raise Exception("Card Jam")
        t_last_dispense = time.time()

        # Check for full trash
        if cards_in_trash >= cfg.max_cards_per_bin:
            empty_trash()
            cards_in_trash = 0

        # Check for shuffle completion
        if deck.is_shuffle_complete:
            return_all_cards(p_motor, b_motor)
            break

    else:
        print("Planned Shuffle Timeout")

    camera.stop_camera()
Пример #2
0
def main():
    c = Camera()
    c.start_camera()
    card = c.read_card()
    print(card.rank, card.suit)
    c.stop_camera()