Example #1
0
        Drive clockwise in a circle of a given radius for a given distance
        """
        radius_mm = self.inches_to_mm(radius_inches)
        distance_mm = self.inches_to_mm(distance_inches)
        self.on_arc_right(speed=speed, radius_mm=radius_mm, distance_mm=distance_mm, brake=stop)

    def inches_to_mm(self, inches):
        """
        Convert inches to mm
        """
        return inches*25.4

# For the arm motor, we want positive values to be up and negative to be down.
# The way that we're configured, we have to reverse the polarity to achieve this.
arm_motor = MediumMotor(address=ARM_MOTOR_PORT)
arm_motor.polarity = MediumMotor.POLARITY_INVERSED

# Let's initialize our arm motor by putting it all the way down until it
# stalls.  With our build, it will stall when it hits the supporting arms
# for the color sensor and touch sensor (so it doesn't hit the ground - it's
# still slightly in the air.)
arm_motor.off()
arm_motor.on(speed=SpeedPercent(-75))
arm_motor.wait_until_not_moving(timeout=5000)
arm_motor.off()

# Initialize our drive base - MyMoveDifferential extends MoveDifferential, which is a 'tank-like'
# class.  Then drive forward at 25% speed for 24.0 inches.
mdiff = MyMoveDifferential(left_motor_port=LEFT_MOTOR_PORT,
    right_motor_port=RIGHT_MOTOR_PORT, wheel_class=EV3EducationSetTire,
    wheel_distance_mm=AXLE_TRACK_MM)
Example #2
0
us_front.mode = 'US-DIST-CM'
us_side.mode = 'US-DIST-CM'

colors = ('red', 'blue')

while (True):

    if cl.color == 5:
        tank_drive.on_for_seconds(SpeedPercent(0), SpeedPercent(0), 2)

        # change LED colours to green if a true victim is detected
        leds.set_color("LEFT", "GREEN")
        leds.set_color("RIGHT", "GREEN")

        # lower scoop
        medMotor.polarity = 'inversed'
        medMotor.on_for_rotations(SpeedPercent(50), 2)

        # move robot into position
        tank_drive.on_for_seconds(SpeedPercent(-20), SpeedPercent(-20), 2)
        tank_drive.on_for_rotations(SpeedPercent(20), SpeedPercent(-20), 1 / 5)
        tank_drive.on_for_seconds(SpeedPercent(20), SpeedPercent(20), 3.5)
        # time of robot driving forward (3.5) needs to be tested to finalize.

        # lift up scoop
        medMotor.polarity = 'normal'
        medMotor.on_for_rotations(SpeedPercent(50), 2)

        # drive back, so that if rescue fails it can start over at original position
        tank_drive.on_for_seconds(SpeedPercent(20), SpeedPercent(20), 3.5)