Exemplo n.º 1
0
class Wheels(MoveSteering):

    def __init__(self, left_motor_port, right_motor_port, desc=None, motor_class=LargeMotor):
        super().__init__(left_motor_port, right_motor_port, desc, motor_class)
        self.diff = MoveDifferential(left_motor_port, right_motor_port, EV3EducationSetTire, 110, desc, motor_class)

    def get_rotations(self):
        return (self.diff.left_motor.rotations + self.diff.right_motor.rotations) / 2.0

    def distance_remaining(self, total_distance, initial_rotations):
        return total_distance - ((self.get_rotations() - initial_rotations) * self.diff.circumference_mm)

    @staticmethod
    def __speed(speed):
        return speed if isinstance(speed, SpeedValue) else SpeedPercent(speed)

    def on_for_rotations(self, steering, speed, rotations, brake=True, block=True):
        super().on_for_rotations(steering, self.__speed(speed), rotations, brake, block)

    def on_for_degrees(self, steering, speed, degrees, brake=True, block=True):
        super().on_for_degrees(steering, self.__speed(speed), degrees, brake, block)

    def on_for_seconds(self, steering, speed, seconds, brake=True, block=True):
        super().on_for_seconds(steering, self.__speed(speed), seconds, brake, block)

    def on(self, steering, speed):
        super().on(steering, self.__speed(speed))

    def get_speed_steering(self, steering, speed):
        return super().get_speed_steering(steering, self.__speed(speed))

    def on_for_distance(self, speed, distance_mm, brake=True, block=True):
        self.diff.on_for_distance(self.__speed(speed), distance_mm, brake, block)

    def on_arc_right(self, speed, radius_mm, distance_mm, brake=True, block=True):
        self.diff.on_arc_right(self.__speed(speed), radius_mm, distance_mm, brake, block)

    def on_arc_left(self, speed, radius_mm, distance_mm, brake=True, block=True):
        self.diff.on_arc_left(self.__speed(speed), radius_mm, distance_mm, brake, block)

    def turn_right(self, speed, degrees, brake=True, block=True):
        self.diff.turn_right(self.__speed(speed), degrees, brake, block)

    def turn_left(self, speed, degrees, brake=True, block=True):
        self.diff.turn_left(self.__speed(speed), degrees, brake, block)

    def turn(self, speed, degrees, brake=True, block=True):
        (self.turn_left if degrees < 0 else self.turn_right)(speed, degrees, brake, block)
Exemplo n.º 2
0
# done = False

gs = GyroSensor(INPUT_4)
# reset the angle and rate values for the Gyro by changing the mode
gs.mode = GyroSensor.MODE_GYRO_CAL
sleep(1)
gs.mode = GyroSensor.MODE_GYRO_RATE
gs.mode = GyroSensor.MODE_GYRO_ANG
gs.mode = GyroSensor.MODE_GYRO_G_A
sleep(1)

motors = MoveDifferential(OUTPUT_C, OUTPUT_A, EV3EducationSetTire, 103)


def check_gyro(val: Value, logger, gyro: GyroSensor):
    # write to a file for testing
    while val.value == 0:
        logger.info('(Angle, Rate) = {}\n'.format(gyro.angle_and_rate))
        sleep(0.5)


value = Value('i', 0)
t = Process(target=check_gyro, args=(value, get_logger('arc.gyro'), gs))
t.start()

motors.on_arc_left(SpeedPercent(50), 200, 1256.64)

# done = True
value.value = 1
t.join()
Exemplo n.º 3
0
STUD_MM = 8
INCH_MM = 25.4

ONE_FOOT_CICLE_RADIUS_MM = (12 * INCH_MM) / 2
ONE_FOOT_CICLE_CIRCUMFERENCE_MM = 2 * pi * ONE_FOOT_CICLE_RADIUS_MM

# Testing with RileyRover
# http://www.damienkee.com/home/2013/8/2/rileyrover-ev3-classroom-robot-design.html
#
# The centers of the wheels are 16 studs apart but this is not the
# "effective" wheel seperation.  Test drives of circles with
# a diameter of 1-foot shows that the effective wheel seperation is
# closer to 16.3 studs. ndward has a writeup that goes into effective
# wheel seperation.
# https://sites.google.com/site/ev3basic/ev3-basic-programming/going-further/writerbot-v1/drawing-arcs
mdiff = MoveDifferential(OUTPUT_A, OUTPUT_B, EV3Tire, 16.3 * STUD_MM)

# This goes crazy on brickpi3, does it do the same on ev3?
#mdiff.on_for_distance(SpeedRPM(-40), 720, brake=False)
#mdiff.on_for_distance(SpeedRPM(40), 720, brake=False)

# Test arc left/right turns
#mdiff.on_arc_right(SpeedRPM(80), ONE_FOOT_CICLE_RADIUS_MM, ONE_FOOT_CICLE_CIRCUMFERENCE_MM / 4)
mdiff.on_arc_left(SpeedRPM(80), ONE_FOOT_CICLE_RADIUS_MM,
                  ONE_FOOT_CICLE_CIRCUMFERENCE_MM)

# Test turning in place
#mdiff.turn_right(SpeedRPM(40), 180)
#mdiff.turn_left(SpeedRPM(40), 180)
Exemplo n.º 4
0
from ev3dev2.wheel import EV3Tire 
from time import sleep 
from ev3dev2.motor import MediumMotor, OUTPUT_A
medium_motorA = MediumMotor(OUTPUT_A)
large_motorB = LargeMotor(OUTPUT_B)
large_motorC = LargeMotor(OUTPUT_C)
STUD_MM = 8
mdiff = MoveDifferential(OUTPUT_B, OUTPUT_C, EV3Tire, 16 * STUD_MM)
mdiff.on_for_distance(speed = 50, distance_mm = 690)
sleep(5)
mdiff.turn_left(speed = 50, degrees = 80)
mdiff.on_arc_right(SpeedRPM(60), 150, 65)
mdiff.on_for_distance(speed = 50, distance_mm = -145)
sleep(5)
medium_motorA.on_for_degrees(speed = 10, degrees = -110)
mdiff.on_arc_left(SpeedRPM(60), 150,67)
sleep(10)
mdiff.on_for_distance(10,50)
#sleep while picking up the first green piece
#medium_motorA.on_for_degrees(speed = 10, degrees = -110)
sleep(5)
#mdiff.turn_left(speed = 35, degrees = 10)
sleep(2)
medium_motorA.on_for_degrees(speed = 10, degrees = 110)
sleep(2)
mdiff.on_arc_right(SpeedRPM(60), 5200, 400)
sleep(5)
medium_motorA.on_for_degrees(speed = 10, degrees = -110)
sleep(5)
medium_motorA.on_for_degrees(speed = 10, degrees = 110)
#sleep while picking up the second green piece
Exemplo n.º 5
0
    on(speed=-65)
    while not touch.is_pressed:
        pass
    wheels.off(brake=False)


# go forward until nearest object is within 25 cm
on()
wait_until_distance(35)
on(speed=15)
wait_until_distance(20)

# hard turn to get off wall
wheels.turn_left(SpeedPercent(15), 45)
# arc to the left to orient towards push object
wheels.on_arc_left(SpeedPercent(30), 300, 230, brake=False)
# move forward 430 mm
forward_distance()

# reverse at an arc
wheels.on_arc_right(SpeedPercent(-50), 200, 225, brake=False)
# reverse for 145 mm
wheels.on_for_distance(SpeedPercent(-30), 155)
# reverse at an arc, orient touch sensor towards wall
wheels.on_arc_left(SpeedPercent(-50), 175, 115, brake=False)

# move back at 50% speed until touch sensor is pressed
on(speed=-50)
while not touch.is_pressed:
    pass
Exemplo n.º 6
0
#move straight
mdiff.on_for_distance(speed=50, distance_mm=690)
mdiff.turn_left(speed=50, degrees=60)
mdiff.on_arc_right(SpeedRPM(60), 150, 65)
mdiff.on_for_distance(speed=50, distance_mm=-145)
#medium_motorA.on_for_degrees(speed = 10, degrees = -95)
#sleep(5)
# turn left for 60 degrees
#mdiff.turn_left(speed = 50, degrees = 60)
#arc with radius 150 and distance 65
#mdiff.on_arc_right(SpeedRPM(50), 150, 65)
#mdiff.on_for_distance(speed = 50, distance_mm = -145)
#sleep(5)
# moving the arm down
medium_motorA.on_for_degrees(speed=8, degrees=-110)
mdiff.on_arc_left(SpeedRPM(50), 120, 65)
#sleep(5)
mdiff.on_for_distance(10, 50)
#sleep(5)
#moving the arm up
medium_motorA.on_for_degrees(speed=8, degrees=110)


#sample1()
#sleep(2)
def sample2():

    medium_motorA.on_for_degrees(speed=10, degrees=-110)
    #sleep(5)
    #go to sample 2 position
    mdiff.on_arc_left(SpeedRPM(50), 750, 400)
Exemplo n.º 7
0
from ev3dev2.wheel import EV3Tire
from time import sleep
from ev3dev2.motor import MediumMotor, OUTPUT_A
medium_motorA = MediumMotor(OUTPUT_A)
large_motorB = LargeMotor(OUTPUT_B)
large_motorC = LargeMotor(OUTPUT_C)
STUD_MM = 8
mdiff = MoveDifferential(OUTPUT_B, OUTPUT_C, EV3Tire, 16 * STUD_MM)
mdiff.on_for_distance(speed=50, distance_mm=690)
sleep(5)
mdiff.turn_left(speed=50, degrees=70)
mdiff.on_arc_right(SpeedRPM(60), 150, 65)
mdiff.on_for_distance(speed=50, distance_mm=-145)
sleep(5)
medium_motorA.on_for_degrees(speed=10, degrees=-110)
mdiff.on_arc_left(SpeedRPM(60), 135, 67)
sleep(10)
mdiff.on_for_distance(10, 50)
#sleep while picking up the first green piece
#medium_motorA.on_for_degrees(speed = 10, degrees = -110)
sleep(5)
#mdiff.turn_left(speed = 35, degrees = 10)
sleep(2)
medium_motorA.on_for_degrees(speed=10, degrees=110)
sleep(2)
medium_motorA.on_for_degrees(speed=10, degrees=-110)
sleep(5)
mdiff.on_arc_left(SpeedRPM(50), 1200, 400)
sleep(5)
medium_motorA.on_for_degrees(speed=10, degrees=110)
sleep(2)
touch = TouchSensor(INPUT_3)


def on(speed=50):
    wheels.on(SpeedPercent(speed), SpeedPercent(speed))


def wait_until_distance(distance=25):
    while claw._us_sensor.distance_centimeters > distance:
        pass


on()
wait_until_distance()

wheels.on_arc_left(SpeedPercent(50), 220, 215, brake=False)


def forward_distance(distance=415):
    wheels.on_for_distance(SpeedPercent(35), distance)


distance = 415
forward_distance()
while not button.down:
    if button.up:
        distance += 5
        print(distance)
        forward_distance(5)

wheels.on_arc_right(SpeedPercent(-50), 200, 225, brake=False)