Exemplo n.º 1
0
 def __init__(self):
     #self.a_motor = ev3.LargeMotor(ev3.OUTPUT_A)
     self.b_motor = ev3.LargeMotor(ev3.OUTPUT_B)
     self.c_motor = ev3.LargeMotor(ev3.OUTPUT_C)
     #self.d_motor = ev3.MediumMotor(ev3.OUTPUT_D)
     time.sleep(1)
     threading.Thread.__init__(self)
Exemplo n.º 2
0
 def __init__(self, channel, freq=PwmFreq.H50, extended=False):
     PwmBase.__init__(self, channel, freq, extended)
     #        print("Channel=%d" % self._channel)
     if self._channel == 12:
         self.motor = ev3.LargeMotor(ev3.OUTPUT_B)
     elif self._channel == 13:
         self.motor = ev3.LargeMotor(ev3.OUTPUT_A)
     else:
         pass
Exemplo n.º 3
0
 def __init__(self):
     # Add more sensors and motors here if you need them
     self.left_motor = ev3.LargeMotor(ev3.OUTPUT_A)
     self.right_motor = ev3.LargeMotor(ev3.OUTPUT_B)
     self.hand_motor = ev3.MediumMotor(ev3.OUTPUT_C)
     self.drop_motor = ev3.MediumMotor(ev3.OUTPUT_D)
     threading.Thread.__init__(self)
     self.hand = 1
     self.handpos = self.hand_motor.position
Exemplo n.º 4
0
    def __init__(self, side, out):
        self.side = side
        self.speed = 0

        self.motor = ev3.LargeMotor(ev3.OUTPUT_A)
        if out.upper() == "B":
            self.motor = ev3.LargeMotor(ev3.OUTPUT_B)
        elif out.upper() == "C":
            self.motor = ev3.LargeMotor(ev3.OUTPUT_C)
        elif out.upper() == "D":
            self.motor = ev3.LargeMotor(ev3.OUTPUT_D)
Exemplo n.º 5
0
 def __init__(self):
     # Add more sensors and motors here if you need them
     #self.left_motor = ev3.LargeMotor(ev3.OUTPUT_C)
     #self.right_motor = ev3.LargeMotor(ev3.OUTPUT_B)
     self.tank = MoveTank(OUTPUT_C, OUTPUT_B)
     self.left_motor = ev3.LargeMotor(ev3.OUTPUT_C)
     self.right_motor = ev3.LargeMotor(ev3.OUTPUT_B)
     self.hand_motor = ev3.MediumMotor(ev3.OUTPUT_A)
     #self.drop_motor = ev3.MediumMotor(ev3.OUTPUT_D)
     self.replay = replay  # Are we recording or not?
     self.handpos = self.hand_motor.position
     self.handmin = 0
     self.handmax = 0
     threading.Thread.__init__(self)
Exemplo n.º 6
0
 def __init__(self):
     self.left_motor = ev3.LargeMotor(ev3.OUTPUT_B)
     self.right_motor = ev3.LargeMotor(ev3.OUTPUT_C)
     self.steer_motor = ev3.MediumMotor(ev3.OUTPUT_A)
     self.steer_motor.position = 0
     self.gyro = ev3.GyroSensor(ev3.INPUT_4)
     self.gyro.mode = ev3.GyroSensor.MODE_GYRO_RATE
     self.offset = 0
     for i in range(60):
         self.offset += self.gyro.rate
         time.sleep(0.015)
     self.offset /= 100
     threading.Thread.__init__(self)
     self.rates = deque([0] * 4, maxlen=4)
Exemplo n.º 7
0
 def __init__(self):
     self.left_motor = ev3.LargeMotor(ev3.OUTPUT_B)
     self.right_motor = ev3.LargeMotor(ev3.OUTPUT_C)
     self.tail_motor = ev3.MediumMotor(ev3.OUTPUT_A)
     self.tail_motor.run_direct(duty_cycle_sp=-40)
     self.tail_motor.wait_until("stalled")
     self.tail_motor.stop()
     self.tail_motor.position = 0
     self.gyro = ev3.GyroSensor(ev3.INPUT_1)
     self.gyro.mode = ev3.GyroSensor.MODE_GYRO_RATE
     self.gyro.auto_mode = False
     self.offset = 0
     for i in range(60):
         self.offset += self.gyro.rate
         time.sleep(0.015)
     self.offset /= 100
     threading.Thread.__init__(self)
     self.rates = deque([0] * 4, maxlen=4)
Exemplo n.º 8
0
    def __init__(self):
        self.steer_motor = ev3.LargeMotor(ev3.OUTPUT_B)
        self.drive_motor = ev3.MediumMotor(ev3.OUTPUT_A)
        threading.Thread.__init__(self)

        # Calibrate
        touch_sensor = ev3.TouchSensor(ev3.INPUT_1)
        while not touch_sensor.pressed:
            self.steer_motor.run_forever(speed_sp=-100)
        self.steer_motor.position = -30
        self.steer_motor.stop()
Exemplo n.º 9
0
 def makeLargeMotor(port, regulated, direction, side=None):
     try:
         m = ev3dev.LargeMotor(port)
         if direction == 'backward':
             m.polarity = 'inversed'
         else:
             m.polarity = 'normal'
     except (AttributeError, OSError):
         logger.info('no large motor connected to port [%s]', port)
         logger.exception("HW Config error")
         m = None
     return m
Exemplo n.º 10
0
class Motors:
    """
    This class connects the robots wheel motors to more usable variables and it has two static methods.

    """
    right_mtr = ev3.LargeMotor(ev3.OUTPUT_D)
    assert right_mtr.connected
    left_mtr = ev3.LargeMotor(ev3.OUTPUT_C)
    assert left_mtr.connected
    grip_mtr = ev3.MediumMotor(ev3.OUTPUT_A)
    assert grip_mtr.connected

    @staticmethod
    def motor_running(motor):
        """
        Sets the state of the motor to "running" and returns that value.

        Keyword arguments:
        motor -- The motor to run the command on
        """
        return motor.state == ["running"]

    @staticmethod
    def wait_motor(motor):
        """
        Makes the motor wait for a certain amount of time.

        Keyword arguments:
        motor -- The motor to run the command on.
        """
        ctr = 0
        while ctr < 2:
            if not Motors.motor_running(motor):
                ctr += 1
            else:
                ctr = 0
Exemplo n.º 11
0
 def __init__(self):
     self.front_motor = ev3.LargeMotor(ev3.OUTPUT_A)
     self.right_motor = ev3.LargeMotor(ev3.OUTPUT_B)
     self.back_motor = ev3.LargeMotor(ev3.OUTPUT_C)
     self.left_motor = ev3.LargeMotor(ev3.OUTPUT_D)
     threading.Thread.__init__(self)
Exemplo n.º 12
0
 def __init__(self):
     # Add more sensors and motors here if you need them
     self.left_motor = ev3.LargeMotor(ev3.OUTPUT_B)
     self.right_motor = ev3.LargeMotor(ev3.OUTPUT_C)
     self.middle_motor = ev3.MediumMotor(ev3.OUTPUT_A)
     threading.Thread.__init__(self)
Exemplo n.º 13
0
 def __init__(self):
     self.motor = ev3.LargeMotor(ev3.OUTPUT_B)
     threading.Thread.__init__(self)
Exemplo n.º 14
0
GO_TO_CENTER = 0
CENTER = np.array([1920 / 2, 1080 / 2])
MODE = CIRCLE  # GO_TO_CENTER or CIRCLE

# Server communication
robot_broadcast_data = {'states': {}, 'balls': {}, 'settings': {}}
running = True
logging.basicConfig(  # filename='position_server.log',     # To a file. Or not.
    filemode='w',  # Start each run with a fresh log
    format='%(asctime)s, %(levelname)s, %(message)s',
    datefmt='%H:%M:%S',
    level=logging.INFO,
)  # Log info, and warning

# Robot setup
left_motor = ev3.LargeMotor(ev3.OUTPUT_B)
right_motor = ev3.LargeMotor(ev3.OUTPUT_C)


### Helpers ###
def vec2d_length(vector):
    """
    Calculates the length of a 2D vector
    :param vector: 1 x 2 numpy array
    :return: length (float)
    """
    return np.dot(vector, vector)**0.5


def vec2d_angle(vector):
    """
Exemplo n.º 15
0
 def __init__(self):
     self.left_motor = ev3.LargeMotor(ev3.OUTPUT_B)
     self.right_motor = ev3.LargeMotor(ev3.OUTPUT_C)
     self.tail_motor = ev3.MediumMotor(ev3.OUTPUT_A)
     self.tail_motor.position = 0
     threading.Thread.__init__(self)
Exemplo n.º 16
0
import ev3dev.auto as ev3
us = ev3.UltrasonicSensor('pistorm:BAS1')
ts = ev3.TouchSensor('pistorm:BBS1')
ls = ev3.LightSensor('pistorm:BAS2')
rs = ev3.LightSensor('pistorm:BBS2')
cm = ev3.LargeMotor('pistorm:BBM1')
lm = ev3.LargeMotor('pistorm:BAM2')
rm = ev3.LargeMotor('pistorm:BBM2')
Exemplo n.º 17
0
 def __init__(self):
     self.right_motor = ev3.LargeMotor(ev3.OUTPUT_C)
     self.left_motor = ev3.LargeMotor(ev3.OUTPUT_B)
     threading.Thread.__init__(self)
Exemplo n.º 18
0
 def __init__(self, channel, freq=PwmFreq.H50, extended=False):
     PwmBase.__init__(self, channel, freq, extended)
     if self._channel == 9:
         self.servo1_180 = ev3.LargeMotor(ev3.OUTPUT_C)