Exemple #1
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
    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()
Exemple #3
0
 def makeMediumMotor(port, regulated, direction, side=None):
     try:
         m = ev3dev.MediumMotor(port)
         if direction == 'backward':
             m.polarity = 'inversed'
         else:
             m.polarity = 'normal'
     except (AttributeError, OSError):
         logger.info('no medium motor connected to port [%s]', port)
         logger.exception("HW Config error")
         m = None
     return m
Exemple #4
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)
Exemple #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)
 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)
Exemple #7
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
Exemple #8
0
 def __init__(self):
     self.right_motor = ev3.LargeMotor(ev3.OUTPUT_C)
     self.left_motor = ev3.LargeMotor(ev3.OUTPUT_B)
     self.claw_motor = ev3.MediumMotor(ev3.OUTPUT_A)
     threading.Thread.__init__(self)
Exemple #9
0
#!/usr/bin/env python3

import evdev
import ev3dev.auto as ev3
import threading
import time

garra = ev3.MediumMotor(ev3.OUTPUT_B)
memoria = True

def clamp(n, minn, maxn):
    return max(min(maxn, n), minn)

def scale(val, src, dst):
    return (float(val - src[0]) / (src[1] - src[0])) * (dst[1] - dst[0]) + dst[0]

def scale_stick(value):
    return scale(value,(0,255),(-1000,1000))

def dc_clamp(value):
    return clamp(value,-1000,1000)

print("Finding ps4 controller...")
devices = [evdev.InputDevice(fn) for fn in evdev.list_devices()]
ps4dev = devices[0].fn

gamepad = evdev.InputDevice(ps4dev)

forward_speed = 0
side_speed = 0
running = True
 def __init__(self):
     self.motor = ev3.MediumMotor(ev3.OUTPUT_D)
     threading.Thread.__init__(self)
 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)
Exemple #12
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)
 def __init__(self):
     self.medium_motor = ev3.MediumMotor(ev3.OUTPUT_A)
     self.touch_sensor = ev3.TouchSensor(ev3.INPUT_1)
     threading.Thread.__init__(self)