Package com.pocolifo.robobase.motor
Class CarWheels
- java.lang.Object
-
- com.pocolifo.robobase.motor.CarWheels
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class CarWheels extends java.lang.Object implements java.lang.AutoCloseableContains 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 WheelbackLeftThe back leftWheel, if looking from the back of the robot and in the same direction of the robot.WheelbackRightThe back rightWheel, if looking from the back of the robot and in the same direction of the robot.WheelfrontLeftThe front leftWheel, if looking from the back of the robot and in the same direction of the robot.WheelfrontRightThe front rightWheel, if looking from the back of the robot and in the same direction of the robot.Robotrobot
-
Constructor Summary
Constructors Constructor Description CarWheels(Robot robot, Wheel frontLeft, Wheel frontRight, Wheel backLeft, Wheel backRight, Wheel specialWheel)InstantiateCarWheels.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 instantiateCarWheels.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the internal motors.voiddrive(double centimeters, boolean horizontal)Drive the motors forward or backward.voiddrive(double centimeters, double speed, boolean horizontal)Drive the motors forward or backward at a certain speed.voiddriveIndividually(double frontLeft, double frontRight, double backLeft, double backRight)Sets the motor speed of each wheel individually.voiddriveOmni(float verticalPower, float horizontalPower, float rotationalPower)Drive the robot with omni-drive.voidrotate(double degrees, double power)Rotates the robot.voidrotateClockwise(double degrees, double power)Rotates the robot clockwise.voidrotateCounterclockwise(double degrees, double power)Rotates the robot counterclockwise.voidsetDriveTarget(double centimeters)Sets the motor target of the special wheel.
-
-
-
Field Detail
-
robot
public final Robot robot
-
frontLeft
public final Wheel frontLeft
The front leftWheel, if looking from the back of the robot and in the same direction of the robot.
-
frontRight
public final Wheel frontRight
The front rightWheel, if looking from the back of the robot and in the same direction of the robot.
-
backLeft
public final Wheel backLeft
The back leftWheel, 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)
InstantiateCarWheels. ThespecialWheelis used for encoder-related calculations.- Parameters:
robot- The associatedRobotthat has theseCarWheels.frontLeft- TheWheelassociated with the front left motor, if looking from the back of the robot and in the same direction of the robot.frontRight- TheWheelassociated with the front right motor, if looking from the back of the robot and in the same direction of the robot.backLeft- TheWheelassociated with the back left motor, if looking from the back of the robot and in the same direction of the robot.backRight- TheWheelassociated 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 instantiateCarWheels.- Parameters:
hardwareMap- TheHardwareMapwhich contains the motors.motorTickCount- The number of encoder ticks for a revolution for each motor.wheelDiameterCm- The diameter of each wheel in centimeters.robot- TheRobotthat is associated with thehardwareMap.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. Ifpoweris 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. Ifpoweris 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.0to1.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.0to1.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.0to1.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:
closein interfacejava.lang.AutoCloseable
-
-