Beispiel #1
0
 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)
Beispiel #2
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()
#!/usr/bin/env python3
from hardware.motors import DriveBase, Picker
from hardware.sensors import RemoteControl
from hardware.simple_device import PowerSupply
from collections import defaultdict
import time

# # Configure the devices
remote = RemoteControl('in4')
base = DriveBase(left=('outC', DriveBase.POLARITY_INVERSED),
                 right=('outB', DriveBase.POLARITY_INVERSED),
                 wheel_diameter=4.3,
                 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)
}
Beispiel #4
0
devices = [evdev.InputDevice(fn) for fn in evdev.list_devices()]
for device in devices:
    if device.name == 'PLAYSTATION(R)3 Controller':
        ps3dev = device.fn

try:
    gamepad = evdev.InputDevice(ps3dev)
except:
    gamepad = GamePadStub()

turn_rate = 0
turn_speed = 0
fwd_speed = 0
triangle_pressed_time = 0
running = True
picker = Picker('outA')


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
Beispiel #5
0
#!/usr/bin/env python3

__author__ = 'anton'

from hardware.gamepad import PS3GamePad
from hardware.motors import DriveBase, Picker
from hardware.sensors import BallSensor
import time

turn_rate = 0
turn_speed = 0
fwd_speed = 0
triangle_pressed_time = 0
picker = Picker('outA')
gamepad_settings = {
    'left_stick_x': {
        'min_value': 3,
        'scale': (40, -40)
    },
    'left_stick_y': {
        'min_value': 4,
        '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')
Beispiel #6
0
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
port = 50000 + MY_ID
s.bind(('', 50000 + MY_ID))
s.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1500)
s.settimeout(0.1)
logging.debug("Listening on port {0}".format(port))

# Configure the devices
ballsensor = BallSensorReader()
ballsensor.start()
base = DriveBase(left=('outC', DriveBase.POLARITY_INVERSED),
                 right=('outB', DriveBase.POLARITY_INVERSED),
                 wheel_diameter=4.3,
                 wheel_span=12,
                 counter_clockwise_is_positive=False)
picker = Picker('outA')
battery = PowerSupply()
buttons = Buttons()

# States
FLOCKING = 'flocking'  # For now, just behavior that makes robots avoid one another
SEEK_BALL = 'seek ball'
STORE = 'store'
TO_DEPOT = 'to depot'
PURGE = 'purge'
LOW_VOLTAGE = 'low'
EXIT = 'exit'
BOUNCE = 'bounce'
DRIVE = 'drive'
PAUSE = 'pause'
TO_CENTER = 'to_center'