示例#1
0
class VRex:
    MOTOR_PORT = 7

    CONTROLLER_DEADBAND = 3  # seconds

    def __init__(self):
        self.motor = \
            Motor(
                self.MOTOR_PORT,   # port
                False   # switch_polarity
            )

        self.controller = Joystick()
        self.controller.set_deadband(self.CONTROLLER_DEADBAND)

    def drive_once_by_controller(self):
        self.motor.run(
            self.controller.axisA(),  # power
            None,  # distance
            False  # hold
        )

    def keep_driving_by_controller(self):
        while True:
            self.drive_once_by_controller()
示例#2
0
    def __init__(self):
        self.drivetrain = \
            Drivetrain(
                Motor(
                    self.LEFT_MOTOR_PORT,   # port
                    self.LEFT_MOTOR_REVERSE_POLARITY   # switch_polarity
                ),   # left_motor
                Motor(
                    self.RIGHT_MOTOR_PORT,   # port
                    self.RIGHT_MOTOR_REVERSE_POLARITY   # switch_polarity
                ),   # right_motor
                self.WHEEL_TRAVEL_MM,   # wheel_travel_mm
                self.TRACK_MM   # track_mm
            )

        self.arm_motor = \
            Motor(
                self.ARM_MOTOR_PORT,   # index
                self.ARM_MOTOR_REVERSE_POLARITY   # reverse
            )

        self.claw_motor = \
            Motor(
                self.CLAW_MOTOR_PORT,   # index
                self.CLAW_MOTOR_REVERSE_POLARITY   # reverse
            )
示例#3
0
    def __init__(self):
        self.drivetrain = \
            Drivetrain(
                Motor(
                    self.LEFT_MOTOR_PORT,   # port
                    self.LEFT_MOTOR_REVERSE_POLARITY   # switch_polarity
                ),   # left_motor
                Motor(
                    self.RIGHT_MOTOR_PORT,   # port
                    self.RIGHT_MOTOR_REVERSE_POLARITY   # switch_polarity
                ),   # right_motor
                self.WHEEL_TRAVEL_MM,   # wheel_travel_mm
                self.TRACK_MM   # track_mm
            )

        self.touch_led = TouchLed(self.TOUCH_LED_PORT)

        self.color_sensor = \
            ColorSensor(
                self.COLOR_SENSOR_PORT,   # index
                False,   # is_grayscale
                700   # proximity
            )

        self.gyro_sensor = \
            Gyro(
                self.GYRO_SENSOR_PORT,   # index
                True   # calibrate
            )

        self.distance_sensor = \
            DistanceSensor(
                self.DISTANCE_SENSOR_PORT,   # port
                self.DISTANCE_SENSOR_UNIT   # unit
            )
示例#4
0
    def __init__(self):
        self.motor = \
            Motor(
                self.MOTOR_PORT,   # port
                False   # switch_polarity
            )

        self.controller = Joystick()
        self.controller.set_deadband(self.CONTROLLER_DEADBAND)
示例#5
0
class Slick:
    # Drive Base configs
    LEFT_MOTOR_PORT = 1
    LEFT_MOTOR_REVERSE_POLARITY = False

    RIGHT_MOTOR_PORT = 6
    RIGHT_MOTOR_REVERSE_POLARITY = True

    WHEEL_TRAVEL_MM = 200
    TRACK_MM = 176

    # Controller configs
    CONTROLLER_DEADBAND = 3

    def __init__(self):
        self.left_motor = \
            Motor(
                self.LEFT_MOTOR_PORT,   # port
                self.LEFT_MOTOR_REVERSE_POLARITY   # switch_polarity
            )
        self.right_motor = \
            Motor(
                self.RIGHT_MOTOR_PORT,   # port
                self.RIGHT_MOTOR_REVERSE_POLARITY   # switch_polarity
            )
        self.drivetrain = \
            Drivetrain(
                self.left_motor,   # left_motor
                self.right_motor,   # right_motor
                self.WHEEL_TRAVEL_MM,   # wheel_travel_mm
                self.TRACK_MM   # track_mm
            )

        self.controller = Joystick()
        self.controller.set_deadband(self.CONTROLLER_DEADBAND)

    def drive_by_controller(self):
        self.left_motor.run(
            self.controller.axisA(),  # power
            None,  # distance
            False  # hold
        )
        self.right_motor.run(
            self.controller.axisD(),  # power
            None,  # distance
            False  # hold
        )

    def keep_driving_by_controller(self):
        while True:
            self.drive_by_controller()

    def main(self):
        self.keep_driving_by_controller()
 def __init__(self):
     self.drivetrain = \
         Drivetrain(
             Motor(
                 self.LEFT_MOTOR_PORT,   # port
                 self.LEFT_MOTOR_REVERSE_POLARITY   # switch_polarity
             ),   # left_motor
             Motor(
                 self.RIGHT_MOTOR_PORT,   # port
                 self.RIGHT_MOTOR_REVERSE_POLARITY   # switch_polarity
             ),   # right_motor
             self.WHEEL_TRAVEL_MM,   # wheel_travel_mm
             self.TRACK_MM   # track_mm
         )
    def __init__(self):
        self.arm_motor = \
            Motor(
                self.ARM_MOTOR_PORT,   # index
                self.ARM_MOTOR_REVERSE_POLARITY   # reverse
            )

        self.claw_motor = \
            Motor(
                self.CLAW_MOTOR_PORT,   # index
                self.CLAW_MOTOR_REVERSE_POLARITY   # reverse
            )

        self.control_arm_or_claw = 0
示例#8
0
    def __init__(self):
        self.left_motor = \
            Motor(
                self.LEFT_MOTOR_PORT,   # port
                self.LEFT_MOTOR_REVERSE_POLARITY   # switch_polarity
            )
        self.right_motor = \
            Motor(
                self.RIGHT_MOTOR_PORT,   # port
                self.RIGHT_MOTOR_REVERSE_POLARITY   # switch_polarity
            )
        self.drivetrain = \
            Drivetrain(
                self.left_motor,   # left_motor
                self.right_motor,   # right_motor
                self.WHEEL_TRAVEL_MM,   # wheel_travel_mm
                self.TRACK_MM   # track_mm
            )

        self.arm_motor = \
            Motor(
                self.ARM_MOTOR_PORT,   # index
                self.ARM_MOTOR_REVERSE_POLARITY   # reverse
            )

        self.claw_motor = \
            Motor(
                self.CLAW_MOTOR_PORT,   # index
                self.CLAW_MOTOR_REVERSE_POLARITY   # reverse
            )
        self.claw_motor.stall_timeout = self.CLAW_MOTOR_TIMEOUT_SECS

        self.touch_led = TouchLed(self.TOUCH_LED_PORT)

        self.color_sensor = \
            ColorSensor(
                self.COLOR_SENSOR_PORT,   # index
                False,   # is_grayscale
                700   # proximity
            )

        self.gyro_sensor = \
            Gyro(
                self.GYRO_SENSOR_PORT,   # index
                True   # calibrate
            )

        self.distance_sensor = \
            DistanceSensor(
                self.DISTANCE_SENSOR_PORT,   # port
                self.DISTANCE_SENSOR_UNIT   # unit
            )

        self.bumper_switch = Bumper(self.BUMPER_SWITCH_PORT)

        self.controller = Joystick()
        self.controller.set_deadband(self.CONTROLLER_DEADBAND)
示例#9
0
    def __init__(self):
        self.left_motor = \
            Motor(
                self.LEFT_MOTOR_PORT,   # port
                self.LEFT_MOTOR_REVERSE_POLARITY   # switch_polarity
            )
        self.right_motor = \
            Motor(
                self.RIGHT_MOTOR_PORT,   # port
                self.RIGHT_MOTOR_REVERSE_POLARITY   # switch_polarity
            )
        self.drivetrain = \
            Drivetrain(
                self.left_motor,   # left_motor
                self.right_motor,   # right_motor
                self.WHEEL_TRAVEL_MM,   # wheel_travel_mm
                self.TRACK_MM   # track_mm
            )

        self.controller = Joystick()
        self.controller.set_deadband(self.CONTROLLER_DEADBAND)
    def __init__(self):
        self.front_left_motor = \
            Motor(
                self.FRONT_LEFT_MOTOR_PORT,   # port
                self.FRONT_LEFT_MOTOR_REVERSE_POLARITY   # switch_polarity
            )
        self.front_right_motor = \
            Motor(
                self.FRONT_RIGHT_MOTOR_PORT,   # port
                True   # switch_polarity
            )
        self.rear_left_motor = \
            Motor(
                self.REAR_LEFT_MOTOR_PORT,   # port
                self.REAR_LEFT_MOTOR_REVERSE_POLARITY   # switch_polarity
            )
        self.rear_right_motor = \
            Motor(
                self.REAR_RIGHT_MOTOR_PORT,   # port
                self.REAR_RIGHT_MOTOR_REVERSE_POLARITY   # switch_polarity
            )

        self.controller = Joystick()
        self.controller.set_deadband(self.CONTROLLER_DEADBAND)
示例#11
0
 def __init__(self):
     self.claw_motor = \
         Motor(
             self.CLAW_MOTOR_PORT,   # index
             self.CLAW_MOTOR_REVERSE_POLARITY   # reverse
         )
from drivetrain import Drivetrain
from vexiq import (
    Bumper,
    ColorSensor,
    DistanceSensor,
    Gyro,
    Joystick,
    Motor,
    TouchLed,
    UNIT_CM
)


# Drive Base configs
LEFT_MOTOR = Motor(1,   # port
                   False   # switch_polarity
                   )
RIGHT_MOTOR = Motor(6,   # port
                    True   # switch_polarity
                    )
DRIVETRAIN = Drivetrain(LEFT_MOTOR,   # left_motor
                        RIGHT_MOTOR,   # right_motor
                        200,   # wheel_travel_mm
                        176   # track_mm
                        )

# Arm motor configs
ARM_MOTOR = Motor(10,   # index
                  False   # switch_polarity
                  )
ARM_MOTOR_VELOCITY_PERCENT = 30
示例#13
0
 def __init__(self):
     self.arm_motor = \
         Motor(
             self.ARM_MOTOR_PORT,   # index
             self.ARM_MOTOR_REVERSE_POLARITY   # reverse
         )
class Allie:
    FRONT_LEFT_MOTOR_PORT = 1
    FRONT_LEFT_MOTOR_REVERSE_POLARITY = False

    FRONT_RIGHT_MOTOR_PORT = 6
    FRONT_RIGHT_MOTOR_REVERSE_POLARITY = True

    REAR_LEFT_MOTOR_PORT = 7
    REAR_LEFT_MOTOR_REVERSE_POLARITY = False

    REAR_RIGHT_MOTOR_PORT = 12
    REAR_RIGHT_MOTOR_REVERSE_POLARITY = True

    MOTOR_ROTATION_RESOLUTION_DEGS = 10

    CONTROLLER_DEADBAND = 3  # seconds

    def __init__(self):
        self.front_left_motor = \
            Motor(
                self.FRONT_LEFT_MOTOR_PORT,   # port
                self.FRONT_LEFT_MOTOR_REVERSE_POLARITY   # switch_polarity
            )
        self.front_right_motor = \
            Motor(
                self.FRONT_RIGHT_MOTOR_PORT,   # port
                True   # switch_polarity
            )
        self.rear_left_motor = \
            Motor(
                self.REAR_LEFT_MOTOR_PORT,   # port
                self.REAR_LEFT_MOTOR_REVERSE_POLARITY   # switch_polarity
            )
        self.rear_right_motor = \
            Motor(
                self.REAR_RIGHT_MOTOR_PORT,   # port
                self.REAR_RIGHT_MOTOR_REVERSE_POLARITY   # switch_polarity
            )

        self.controller = Joystick()
        self.controller.set_deadband(self.CONTROLLER_DEADBAND)

    def reset_motor(self, motor):
        # rotate motor up to 270 degrees within 1 second
        # using max velocity but very light power/torque
        # ...

        # set motor encoder to 0
        motor.reset_position()

        # restore max motor power/torque to 100% again
        # ...

    def reset_legs(self):
        self.reset_motor(self.front_left_motor)
        self.reset_motor(self.front_right_motor)
        self.reset_motor(self.rear_left_motor)
        self.reset_motor(self.rear_right_motor)

    def drive_once_by_controller(self):
        if self.controller.bLdown():
            self.front_left_motor.run_until(
                100,  # power
                self.MOTOR_ROTATION_RESOLUTION_DEGS,  # distance
                True  # hold
            )

        elif self.controller.bLup():
            self.front_left_motor.run_until(
                -100,  # power
                self.MOTOR_ROTATION_RESOLUTION_DEGS,  # distance
                True  # hold
            )

        elif self.controller.bRdown():
            self.front_right_motor.run_until(
                100,  # power
                self.MOTOR_ROTATION_RESOLUTION_DEGS,  # distance
                True  # hold
            )

        elif self.controller.bRup():
            self.front_right_motor.run_until(
                -100,  # power
                self.MOTOR_ROTATION_RESOLUTION_DEGS,  # distance
                True  # hold
            )

        elif self.controller.bEup():
            self.rear_left_motor.run_until(
                100,  # power
                self.MOTOR_ROTATION_RESOLUTION_DEGS,  # distance
                True  # hold
            )

        elif self.controller.bEdown():
            self.rear_left_motor.run_until(
                -100,  # power
                self.MOTOR_ROTATION_RESOLUTION_DEGS,  # distance
                True  # hold
            )

        elif self.controller.bFup():
            self.rear_right_motor.run_until(
                100,  # power
                self.MOTOR_ROTATION_RESOLUTION_DEGS,  # distance
                True  # hold
            )

        elif self.controller.bFdown():
            self.rear_right_motor.run_until(
                -100,  # power
                self.MOTOR_ROTATION_RESOLUTION_DEGS,  # distance
                True  # hold
            )

    def keep_driving_by_controller(self):
        while True:
            self.drive_once_by_controller()
示例#15
0
class Clawbot:
    # Drive Base configs
    LEFT_MOTOR_PORT = 1
    LEFT_MOTOR_REVERSE_POLARITY = False

    RIGHT_MOTOR_PORT = 6
    RIGHT_MOTOR_REVERSE_POLARITY = True

    WHEEL_TRAVEL_MM = 200
    TRACK_MM = 176

    # Arm motor configs
    ARM_MOTOR_PORT = 10
    ARM_MOTOR_REVERSE_POLARITY = False
    ARM_MOTOR_VELOCITY_PERCENT = 30

    # Claw motor configs
    CLAW_MOTOR_PORT = 11
    CLAW_MOTOR_REVERSE_POLARITY = False
    CLAW_MOTOR_TIMEOUT_SECS = 3
    CLAW_MOTOR_VELOCITY_PERCENT = 60

    # sensor configs
    TOUCH_LED_PORT = 2
    COLOR_SENSOR_PORT = 3
    GYRO_SENSOR_PORT = 4
    DISTANCE_SENSOR_PORT = 7
    DISTANCE_SENSOR_UNIT = UNIT_CM
    BUMPER_SWITCH_PORT = 8

    # Controller configs
    CONTROLLER_DEADBAND = 3

    def __init__(self):
        self.left_motor = \
            Motor(
                self.LEFT_MOTOR_PORT,   # port
                self.LEFT_MOTOR_REVERSE_POLARITY   # switch_polarity
            )
        self.right_motor = \
            Motor(
                self.RIGHT_MOTOR_PORT,   # port
                self.RIGHT_MOTOR_REVERSE_POLARITY   # switch_polarity
            )
        self.drivetrain = \
            Drivetrain(
                self.left_motor,   # left_motor
                self.right_motor,   # right_motor
                self.WHEEL_TRAVEL_MM,   # wheel_travel_mm
                self.TRACK_MM   # track_mm
            )

        self.arm_motor = \
            Motor(
                self.ARM_MOTOR_PORT,   # index
                self.ARM_MOTOR_REVERSE_POLARITY   # reverse
            )

        self.claw_motor = \
            Motor(
                self.CLAW_MOTOR_PORT,   # index
                self.CLAW_MOTOR_REVERSE_POLARITY   # reverse
            )
        self.claw_motor.stall_timeout = self.CLAW_MOTOR_TIMEOUT_SECS

        self.touch_led = TouchLed(self.TOUCH_LED_PORT)

        self.color_sensor = \
            ColorSensor(
                self.COLOR_SENSOR_PORT,   # index
                False,   # is_grayscale
                700   # proximity
            )

        self.gyro_sensor = \
            Gyro(
                self.GYRO_SENSOR_PORT,   # index
                True   # calibrate
            )

        self.distance_sensor = \
            DistanceSensor(
                self.DISTANCE_SENSOR_PORT,   # port
                self.DISTANCE_SENSOR_UNIT   # unit
            )

        self.bumper_switch = Bumper(self.BUMPER_SWITCH_PORT)

        self.controller = Joystick()
        self.controller.set_deadband(self.CONTROLLER_DEADBAND)

    def drive_by_controller(self):
        self.left_motor.run(
            self.controller.axisA(),   # power
            None,   # distance
            False   # hold
        )
        self.right_motor.run(
            self.controller.axisD(),   # power
            None,   # distance
            False   # hold
        )

    def keep_driving_by_controller(self):
        while True:
            self.drive_by_controller()

    def lower_or_raise_arm_by_controller(self):
        if self.controller.bLdown():
            self.arm_motor.run(
                -self.ARM_MOTOR_VELOCITY_PERCENT,   # power
                None,   # distance
                False   # hold
            )

        elif self.controller.bLup():
            self.arm_motor.run(
                self.ARM_MOTOR_VELOCITY_PERCENT,   # power
                None,   # distance
                False   # hold
            )

        else:
            self.arm_motor.hold()

    def keep_lowering_or_raising_arm_by_controller(self):
        while True:
            self.lower_or_raise_arm_by_controller()

    def grab_or_release_object_by_controller(self):
        if self.controller.bRdown():
            self.claw_motor.run(
                -self.CLAW_MOTOR_VELOCITY_PERCENT,   # power
                None,   # distance
                False   # hold
            )

        elif self.controller.bRup():
            self.claw_motor.run(
                self.CLAW_MOTOR_VELOCITY_PERCENT,   # power
                None,   # distance
                False   # hold
            )

        else:
            self.claw_motor.hold()

    def keep_grabbing_or_releasing_objects_by_controller(self):
        while True:
            self.grab_or_release_object_by_controller()

    def main(self):
        while True:
            self.drive_by_controller()
            self.lower_or_raise_arm_by_controller()
            self.grab_or_release_object_by_controller()
class Clawbot:
    ARM_MOTOR_PORT = 10
    ARM_MOTOR_REVERSE_POLARITY = False

    CLAW_MOTOR_PORT = 11
    CLAW_MOTOR_REVERSE_POLARITY = False

    def __init__(self):
        self.arm_motor = \
            Motor(
                self.ARM_MOTOR_PORT,   # index
                self.ARM_MOTOR_REVERSE_POLARITY   # reverse
            )

        self.claw_motor = \
            Motor(
                self.CLAW_MOTOR_PORT,   # index
                self.CLAW_MOTOR_REVERSE_POLARITY   # reverse
            )

        self.control_arm_or_claw = 0

    def switch_between_arm_and_claw(self):
        if is_check_button_pressed():
            self.control_arm_or_claw = 1 - self.control_arm_or_claw

    def control_arm(self):
        if not self.control_arm_or_claw:
            if is_up_button_pressed():
                self.arm_motor.run(
                    100,  # power,
                    None,  # distance
                    False  # hold
                )

            elif is_down_button_pressed():
                self.arm_motor.run(
                    -100,  # power,
                    None,  # distance
                    False  # hold
                )

            else:
                self.arm_motor.hold()

        else:
            self.arm_motor.hold()

    def control_claw(self):
        if self.control_arm_or_claw:
            if is_down_button_pressed():
                self.claw_motor.run(
                    -100,  # power,
                    None,  # distance
                    False  # hold
                )

            elif is_up_button_pressed():
                self.claw_motor.run(
                    100,  # power,
                    None,  # distance
                    False  # hold
                )

            else:
                self.claw_motor.hold()

        else:
            self.claw_motor.hold()