示例#1
0
    def __init__(self):
        # Initialize each motor with the correct direction and gearing.
        self.left_rear_wheels = Motor(Port.E, Direction.CLOCKWISE,
                                      self.REAR_GEARS)
        self.right_rear_wheels = Motor(Port.F, Direction.COUNTERCLOCKWISE,
                                       self.REAR_GEARS)
        self.left_front_wheel = Motor(Port.C, Direction.COUNTERCLOCKWISE, None)
        self.right_front_wheel = Motor(Port.D, Direction.CLOCKWISE, None)

        # Initialize sensors, named after the Perseverance Mars Rover instruments.
        self.mast_cam = UltrasonicSensor(Port.B)
        self.sherloc = ColorSensor(Port.A)

        # Initialize the hub and start the animation
        self.hub = InventorHub()
        self.hub.display.animate(self.HEART_BEAT, 30)
示例#2
0
    def __init__(self):
        self.hub = InventorHub()

        # Configure the drive base
        self.left_motor = Motor(Port.C, Direction.COUNTERCLOCKWISE)
        self.right_motor = Motor(Port.A)
        self.drive_base = DriveBase(self.left_motor,
                                    self.right_motor,
                                    wheel_diameter=self.WHEEL_DIAMETER,
                                    axle_track=self.AXLE_TRACK)

        # Configure other motors and sensors
        self.arm_movement_motor = Motor(Port.D)
        self.action_motor = Motor(Port.B)
        self.color_sensor = ColorSensor(Port.E)
        self.distance_sensor = UltrasonicSensor(Port.F)
示例#3
0
    def __init__(self):
        # Configure the hub, the kicker motor, and the sensors.
        self.hub = InventorHub()
        self.kicker_motor = Motor(Port.C)
        self.distance_sensor = UltrasonicSensor(Port.D)
        self.color_sensor = ColorSensor(Port.E)

        # Configure the drive base.
        left_motor = Motor(Port.B, Direction.COUNTERCLOCKWISE)
        right_motor = Motor(Port.A)
        self.drive_base = DriveBase(left_motor, right_motor,
                                    self.WHEEL_DIAMETER, self.AXLE_TRACK)

        # Prepare tricky to start kicking!
        self.distance_sensor.lights.off()
        self.reset_kicker_motor()
        self.distance_sensor.lights.on(100)
示例#4
0
    def __init__(self):
        self.hub = InventorHub(top_side=Axis.Z, front_side=-Axis.X)

        # Configure the leg motors
        self.front_left_leg_motor = Motor(Port.D)
        self.front_right_leg_motor = \
            Motor(Port.C, Direction.COUNTERCLOCKWISE)
        self.rear_left_leg_motor = Motor(Port.B)
        self.rear_right_leg_motor = \
            Motor(Port.A, Direction.COUNTERCLOCKWISE)
        self.leg_motors = [
            self.front_left_leg_motor, self.front_right_leg_motor,
            self.rear_left_leg_motor, self.rear_right_leg_motor
        ]

        # Configure the sensors
        self.color_sensor = ColorSensor(Port.F)
        self.distance_sensor = UltrasonicSensor(Port.E)
示例#5
0
from pybricks.hubs import InventorHub
from pybricks.pupdevices import Motor, ColorSensor
from pybricks.parameters import Port, Button, Stop
from pybricks.tools import wait

# Tuning parameters
SPEED_MAX = 1000
SPEED_TURN = 500
SPEED_OFFLINE = 400

# Initialize the hub, motors, and sensor
hub = InventorHub()
steer_motor = Motor(Port.A)
drive_motor = Motor(Port.B)
sensor = ColorSensor(Port.C)


def wait_for_button(b):
    # Wait for press
    while b not in hub.buttons.pressed():
        wait(10)
    # and release
    while b in hub.buttons.pressed():
        wait(10)


# Use the color saturation value to track line
def get_light():
    return sensor.hsv().s