Class CarWheels

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public class CarWheels
    extends java.lang.Object
    implements java.lang.AutoCloseable
    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:
    Wheel
    • Field Summary

      Fields 
      Modifier and Type Field Description
      Wheel backLeft
      The back left Wheel, if looking from the back of the robot and in the same direction of the robot.
      Wheel backRight
      The back right Wheel, if looking from the back of the robot and in the same direction of the robot.
      Wheel frontLeft
      The front left Wheel, if looking from the back of the robot and in the same direction of the robot.
      Wheel frontRight
      The front right Wheel, if looking from the back of the robot and in the same direction of the robot.
      Robot robot
      The Robot that is associated with these CarWheels.
    • 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, int motorTickCount, double wheelDiameterCm, Robot robot, java.lang.String frontLeft, java.lang.String frontRight, java.lang.String backLeft, java.lang.String backRight, java.lang.String specialWheel)
      Quickly instantiate CarWheels.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      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 driveIndividually​(double frontLeft, double frontRight, double backLeft, double backRight)
      Sets the motor speed of each wheel individually.
      void driveOmni​(float verticalPower, float horizontalPower, float rotationalPower)
      Drive the robot with omni-drive.
      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 Detail

      • 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.
    • Constructor Detail

      • 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,
                         int motorTickCount,
                         double wheelDiameterCm,
                         Robot robot,
                         java.lang.String frontLeft,
                         java.lang.String frontRight,
                         java.lang.String backLeft,
                         java.lang.String backRight,
                         java.lang.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:
        CarWheels(Robot, Wheel, Wheel, Wheel, Wheel, Wheel)
    • Method Detail

      • 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:
        rotate(double, double)
      • 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:
        rotate(double, double)
      • driveOmni

        public void driveOmni​(float verticalPower,
                              float horizontalPower,
                              float 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).
      • close

        public void close()
        Closes the internal motors. THIS SHOULD BE CALLED WHEN THE MOTORS ARE DONE BEING USED!
        Specified by:
        close in interface java.lang.AutoCloseable