Class CarWheels

java.lang.Object
com.pocolifo.robobase.motor.CarWheels
All Implemented Interfaces:
MovementAware, AutoCloseable

public class CarWheels extends Object implements AutoCloseable, MovementAware
Contains functions to move the robot very intuitively. Intended for use in Autonomous. The wheels must be organized just like a car; this means all wheels are parallel, two on each side of the robot.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final Wheel
    The back left Wheel, if looking from the back of the robot and in the same direction of the robot.
    final Wheel
    The back right Wheel, if looking from the back of the robot and in the same direction of the robot.
    final Wheel
    The front left Wheel, if looking from the back of the robot and in the same direction of the robot.
    final Wheel
    The front right Wheel, if looking from the back of the robot and in the same direction of the robot.
    final Robot
    The Robot that is associated with these CarWheels.
    final Wheel
    Deprecated.
  • Constructor Summary

    Constructors
    Constructor
    Description
    CarWheels(Robot robot, Wheel frontLeft, Wheel frontRight, Wheel backLeft, Wheel backRight, Wheel specialWheel)
    Instantiate CarWheels.
    CarWheels(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap, double motorTickCount, double wheelDiameterCm, Robot robot, String frontLeft, String frontRight, String backLeft, String backRight, String specialWheel)
    Quickly instantiate CarWheels.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes the internal motors.
    void
    drive(double centimeters, boolean horizontal)
    Drive the motors forward or backward.
    void
    drive(double centimeters, double speed, boolean horizontal)
    Drive the motors forward or backward at a certain speed.
    void
    drive(double lateralCm, double horizontalCm, double speed)
    Drives the robot in a specified lateral and horizontal direction at a given speed using omni-wheel drive.
    void
    driveIndividually(double frontLeft, double frontRight, double backLeft, double backRight)
    Sets the motor speed of each wheel individually.
    void
    driveOmni(double[] power)
    Drives the robot using omni-wheel control based on the provided power values for each direction.
    void
    driveOmni(double verticalPower, double horizontalPower, double rotationalPower)
    Drive the robot with omni-drive.
    void
    follow(DisplacementSequence sequence, double power)
    Executes a sequence of displacements, driving the robot to each target position with a specified power.
    Get the most recent completed movement events.
    void
    rotate(double degrees, double power)
    Rotates the robot.
    void
    rotateClockwise(double degrees, double power)
    Rotates the robot clockwise.
    void
    rotateCounterclockwise(double degrees, double power)
    Rotates the robot counterclockwise.
    void
    setDriveTarget(double centimeters)
    Sets the motor target of the special wheel.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • robot

      public final Robot robot
      The Robot that is associated with these CarWheels.
    • frontLeft

      public final Wheel frontLeft
      The front left Wheel, if looking from the back of the robot and in the same direction of the robot.
    • frontRight

      public final Wheel frontRight
      The front right Wheel, if looking from the back of the robot and in the same direction of the robot.
    • backLeft

      public final Wheel backLeft
      The back left Wheel, if looking from the back of the robot and in the same direction of the robot.
    • backRight

      public final Wheel backRight
      The back right Wheel, if looking from the back of the robot and in the same direction of the robot.
    • specialWheel

      @Deprecated public final Wheel specialWheel
      Deprecated.
      The Wheel used for encoder-related calculations.
  • Constructor Details

    • CarWheels

      public CarWheels(Robot robot, Wheel frontLeft, Wheel frontRight, Wheel backLeft, Wheel backRight, Wheel specialWheel)
      Instantiate CarWheels. The specialWheel is used for encoder-related calculations.
      Parameters:
      robot - The associated Robot that has these CarWheels.
      frontLeft - The Wheel associated with the front left motor, if looking from the back of the robot and in the same direction of the robot.
      frontRight - The Wheel associated with the front right motor, if looking from the back of the robot and in the same direction of the robot.
      backLeft - The Wheel associated with the back left motor, if looking from the back of the robot and in the same direction of the robot.
      backRight - The Wheel associated with the back right motor, if looking from the back of the robot and in the same direction of the robot.
      specialWheel - The wheel that is used for encoder-related calculations.
    • CarWheels

      public CarWheels(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap, double motorTickCount, double wheelDiameterCm, Robot robot, String frontLeft, String frontRight, String backLeft, String backRight, String specialWheel)
      Quickly instantiate CarWheels.
      Parameters:
      hardwareMap - The HardwareMap which contains the motors.
      motorTickCount - The number of encoder ticks for a revolution for each motor.
      wheelDiameterCm - The diameter of each wheel in centimeters.
      robot - The Robot that is associated with the hardwareMap.
      frontLeft - The name of the front left motor, if looking from the back of the robot and in the same direction of the robot.
      frontRight - The name of the front right motor, if looking from the back of the robot and in the same direction of the robot.
      backLeft - The name of the back left motor, if looking from the back of the robot and in the same direction of the robot.
      backRight - The name of the back right motor, if looking from the back of the robot and in the same direction of the robot.
      specialWheel - The wheel that has the encoder connector connected to it and the Control Hub. The connector is mandatory because it's how we know how far the robot has traveled!
      See Also:
  • Method Details

    • drive

      public void drive(double centimeters, boolean horizontal)
      Drive the motors forward or backward.
      Parameters:
      centimeters - The number of centimeters to move. This should be negative to move backwards, and positive to move forwards. If power is negative, this should be too.
      horizontal - Whether the robot moves vertically or horizontally.
    • drive

      public void drive(double centimeters, double speed, boolean horizontal)
      Drive the motors forward or backward at a certain speed.
      Parameters:
      centimeters - The number of centimeters to move. This should be negative to move backwards, and positive to move forwards. If power is negative, this should be too.
      speed - The speed at which the robot should move. Should be [0, 1].
      horizontal - Whether the robot moves vertically or horizontally.
    • driveIndividually

      public void driveIndividually(double frontLeft, double frontRight, double backLeft, double backRight)
      Sets the motor speed of each wheel individually. Setting the motor speed actually moves it in real life.
      Parameters:
      frontLeft - The speed to set the front left wheel to.
      frontRight - The speed to set the front right wheel to.
      backLeft - The speed to set the back left wheel to.
      backRight - The speed to set the back right wheel to.
    • setDriveTarget

      public void setDriveTarget(double centimeters)
      Sets the motor target of the special wheel. Use this to specify how far the car should go.
      Parameters:
      centimeters - The target to set the special wheel to, in centimeters.
    • rotate

      public void rotate(double degrees, double power)
      Rotates the robot.
      Parameters:
      degrees - Degrees to rotate. Positive for right (clockwise). Negative for left (counterclockwise).
      power - The power to drive the motors at. Valid values are from -1.0 to 1.0, inclusive. This should be negative to rotate counterclockwise, and positive to rotate clockwise.
    • rotateClockwise

      public void rotateClockwise(double degrees, double power)
      Rotates the robot clockwise. This is just for readability purposes.
      Parameters:
      degrees - Degrees to rotate clockwise.
      power - The power to drive the motors at. Valid values are from -1.0 to 1.0, inclusive. This should be negative to rotate counterclockwise, and positive to rotate clockwise.
      See Also:
    • rotateCounterclockwise

      public void rotateCounterclockwise(double degrees, double power)
      Rotates the robot counterclockwise. This is just for readability purposes.
      Parameters:
      degrees - Degrees to rotate counterclockwise.
      power - The power to drive the motors at. Valid values are from -1.0 to 1.0, inclusive. This should be negative to rotate counterclockwise, and positive to rotate clockwise.
      See Also:
    • driveOmni

      public void driveOmni(double verticalPower, double horizontalPower, double rotationalPower)
      Drive the robot with omni-drive. Omni-drive allows the robot to move horizontally without rotating, drive diagonally, and drive and rotate the robot normally.
      Parameters:
      verticalPower - The power at which to move the robot forward and backward. Inclusive from -1.0 to 1.0.
      horizontalPower - The power at which to move the robot left and right. Inclusive from -1.0 to 1.0.
      rotationalPower - The power at which to rotate the robot. Inclusive from -1.0 (rotate counterclockwise) to 1.0 (clockwise).
    • driveOmni

      public void driveOmni(double[] power)
      Drives the robot using omni-wheel control based on the provided power values for each direction.
      Parameters:
      power - An array of power values representing the desired speed and direction for each wheel. The array should have three elements: [powerX, powerY, powerRotation]. - powerX: The lateral movement power. - powerY: The horizontal movement power. - powerRotation: The rotational movement power.
    • close

      public void close()
      Closes the internal motors.
      Specified by:
      close in interface AutoCloseable
    • getPastMovementEvents

      public List<MovementEvent> getPastMovementEvents()
      Description copied from interface: MovementAware
      Get the most recent completed movement events. Index 0 is the most recent event, and the last index is the least recent event.
      Specified by:
      getPastMovementEvents in interface MovementAware
      Returns:
      An ordered list of the most recent movement events that have been completed
    • follow

      public void follow(DisplacementSequence sequence, double power)
      Executes a sequence of displacements, driving the robot to each target position with a specified power.
      Parameters:
      sequence - The sequence of displacements to follow, containing the target positions in both lateral (yCm) and horizontal (xCm) directions.
      power - The power at which the robot should move during each displacement, ranging from -1.0 (full reverse) to 1.0 (full forward). A power of 0.0 indicates no motion.
    • drive

      public void drive(double lateralCm, double horizontalCm, double speed)
      Drives the robot in a specified lateral and horizontal direction at a given speed using omni-wheel drive.
      Parameters:
      lateralCm - The lateral distance to drive in centimeters.
      horizontalCm - The horizontal distance to drive in centimeters.
      speed - The speed at which the robot should move, ranging from -1.0 (full reverse) to 1.0 (full forward). A speed of 0.0 indicates no motion.