Beispiel #1
0
class MotorThread(threading.Thread):
    def __init__(self):
        self.base = DriveBase(left=('outC', 'inversed'),
                              right=('outB', 'inversed'),
                              wheel_diameter=4.3,
                              wheel_span=12,
                              counter_clockwise_is_positive=False)
        self.ballsensor = BallSensor('in4')
        self.picker = Picker('outA')
        threading.Thread.__init__(self)

    def run(self):
        global gripper
        print("Engines running!")
        while running:
            # Autopicker
            if self.ballsensor.ball_detected() and not self.picker.is_running:
                # print(self.picker.is_running)
                self.picker.go_to_target(self.picker.STORE)

            # Close after storing
            if self.picker.is_at_store:
                # print("at store")
                self.picker.go_to_target(self.picker.OPEN)

            # if cross_btn:
            #     self.picker.go_to_target(picker.STORE)
            # if square_btn:
            #     break
            self.base.drive_and_turn(fwd_speed, turn_rate)
            #
            # # Autopicker
            # if picker.target == picker.OPEN and picker.is_at_target:
            #     if self.ballsensor.check_ball():
            #         gripper.target = picker.CLOSED
            # elif picker.target == picker.STORE and picker.is_at_target:
            #     picker.target = picker.OPEN
            #
            # picker.run()
            # self.base.drive_and_turn(fwd_speed, -turn_rate)

            # Give the Ev3 some time to handle other threads.
            time.sleep(0.04)
        self.base.stop()
        picker.stop()
                 wheel_span=12,
                 counter_clockwise_is_positive=False)

picker = Picker('outA')
battery = PowerSupply()
print(battery.voltage)

# Dictionary of action tuples associated with remote button
actions = {
    'NONE': (0, 0, None),
    'LEFT_UP': (0, 40, None),
    'RIGHT_UP': (0, -40, None),
    'BOTH_UP': (6, 0, None),
    'BOTH_DOWN': (-6, 0, None),
    'LEFT_DOWN': (None, None, Picker.STORE),
    'RIGHT_DOWN': (None, None, Picker.OPEN),
    'BEACON': (None, None, Picker.PURGE)
}

# Main Loop: Drive around and control picker based on remote
while True:
    try:
        speed_now, steering_now, target_now = actions[remote.button]
    except:
        speed_now, steering_now, target_now = actions['NONE']

    if target_now is not None:
        picker.go_to_target(target_now, blocking=True)
    if speed_now is not None and steering_now is not None:
        base.drive_and_turn(speed_now, steering_now)
    time.sleep(0.1)
Beispiel #3
0
        'scale': (-60, 60)
    }
}
gamepad = PS3GamePad(gamepad_settings)
base = DriveBase(left=('outC', 'inversed'),
                 right=('outB', 'inversed'),
                 wheel_diameter=4.3,
                 wheel_span=12,
                 counter_clockwise_is_positive=False)
ballsensor = BallSensor('in4')

print("Engines running!")
while True:
    # Autopicker
    if ballsensor.ball_detected() and not picker.is_running:
        picker.go_to_target(picker.STORE)

    # Close after storing
    if picker.is_at_store:
        picker.go_to_target(picker.OPEN)

    # Gamepad
    fwd_speed = gamepad.left_stick_y
    turn_rate = gamepad.left_stick_x
    if gamepad.cross_btn:
        picker.go_to_target(picker.STORE)
    if gamepad.square_btn:
        break
    base.drive_and_turn(fwd_speed, turn_rate)

    # Give the Ev3 some time to handle other threads.