Skip to content

Commit

Permalink
add MecanumDrive to DriveParameters
Browse files Browse the repository at this point in the history
  • Loading branch information
cmcgroarty committed Jan 9, 2019
1 parent 6bc6f91 commit 5d67c86
Show file tree
Hide file tree
Showing 6 changed files with 313 additions and 81 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.hyperonline.hyperlib.driving;

import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import edu.wpi.first.wpilibj.drive.MecanumDrive;

/**
* A class which represents arcade drive. Arcade drive uses two values: move and
Expand All @@ -23,18 +24,15 @@ public class ArcadeDriveParams implements DriveParameters {
private final boolean m_squareInputs;

/**
* Construct a new {@link ArcadeDriveParams}.
*
* @param move
* The amount to move forwards or backwards
* @param rotate
* The amount to rotate
* @param squareInputs
* Whether to square the inputs. This is desirable if the input
* is coming from a joystick, as it creates a "soft deadzone". If
* coming from another source, like a PID controller, this should
* be <code>false</code>.
*/
* Construct a new {@link ArcadeDriveParams}.
*
* @param move The amount to move forwards or backwards
* @param rotate The amount to rotate
* @param squareInputs Whether to square the inputs. This is desirable if the
* input is coming from a joystick, as it creates a "soft
* deadzone". If coming from another source, like a PID
* controller, this should be <code>false</code>.
*/
public ArcadeDriveParams(double move, double rotate, boolean squareInputs) {
m_move = move;
m_rotate = rotate;
Expand All @@ -49,6 +47,14 @@ public void drive(DifferentialDrive driveTrain, double currentGyro) {
driveTrain.arcadeDrive(m_move, m_rotate, m_squareInputs);
}

/**
* {@inheritDoc}
*/
@Override
public void drive(MecanumDrive driveTrain, double currentGyro) throws WrongDriveTypeException {
throw new WrongDriveTypeException("using Arcade with MecanumDrive");
}

/**
* Get the move parameter
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package org.hyperonline.hyperlib.driving;

import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import edu.wpi.first.wpilibj.drive.MecanumDrive;

/**
*
* @author Chris McGroarty
*
*/
public class CartesianDriveParams implements DriveParameters {

private double m_ySpeed, m_xSpeed, m_zRotate, m_gyroAngle;

/**
* get the speed on the y-axis
*
* @return the y-axis speed
*/
public double ySpeed() {
return m_ySpeed;
}

/**
* get the speed on the x-axis
*
* @return the x-axis speed
*/
public double xSpeed() {
return m_xSpeed;
}

/**
* get the rotation from the z-axis
*
* @return the z-axis rotation
*/
public double zRotate() {
return m_zRotate;
}

/**
* get the gyro angle
*
* @return the gyro angle
*/
public double gyroAngle() {
return m_gyroAngle;
}

/**
* Construct a new {@link CartesianDriveParams}.
*
* @param ySpeed the speed to move in the y-axis
* @param xSpeed the speed to move in the x-axis
* @param zRotate the rotation to apply in the z-axis
* @param gyroAngle the gyroAngle to use
*/
public CartesianDriveParams(double ySpeed, double xSpeed, double zRotate, double gyroAngle) {
m_ySpeed = ySpeed;
m_xSpeed = xSpeed;
m_zRotate = zRotate;
m_gyroAngle = gyroAngle;
}

/**
* {@inheritDoc}
*/
@Override
public void drive(DifferentialDrive driveTrain, double currentGyro) throws WrongDriveTypeException {
throw new WrongDriveTypeException("using Cartesian with DifferentialDrive");

}

/**
* {@inheritDoc}
*/
@Override
public void drive(MecanumDrive driveTrain, double currentGyro) {
driveTrain.driveCartesian(m_ySpeed, m_xSpeed, m_zRotate, m_gyroAngle);

}

}
51 changes: 34 additions & 17 deletions src/main/java/org/hyperonline/hyperlib/driving/DriveParameters.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.hyperonline.hyperlib.driving;

import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import edu.wpi.first.wpilibj.drive.MecanumDrive;

/**
* The {@link DriveParameters} interface allows one to use polymorphism to
Expand All @@ -19,21 +20,37 @@
*
*/
public interface DriveParameters {
/**
* Drive the robot. This method should not call any "stateful" methods of
* the drivetrain (anything that starts with "set") to allow one to switch
* between modes easily.
*
* TODO: pass a wrapper of DifferentialDrive, which only allows certain methods
* TODO: remove currentGyro. This is pretty irrelevant, and can be obtained
* in other ways.
*
* @param driveTrain
* A {@link DifferentialDrive} object representing the drivetrain of the
* robot.
* @param currentGyro
* The current gyro heading, if a gyro exists. Nothing should use
* this right now, so just pass in 0.0 if you're not sure.
*/
void drive(DifferentialDrive driveTrain, double currentGyro);
/**
* Drive the robot. This method should not call any "stateful" methods of the
* drivetrain (anything that starts with "set") to allow one to switch between
* modes easily.
*
* TODO: pass a wrapper of DifferentialDrive, which only allows certain methods
* TODO: remove currentGyro. This is pretty irrelevant, and can be obtained in
* other ways.
*
* @param driveTrain A {@link DifferentialDrive} object representing the
* drivetrain of the robot.
* @param currentGyro The current gyro heading, if a gyro exists. Nothing should
* use this right now, so just pass in 0.0 if you're not
* sure.
*
* @throws WrongDriveTypeException if an incompatible Drive type is used
*/
void drive(DifferentialDrive driveTrain, double currentGyro) throws WrongDriveTypeException;

/**
* Drive the robot. This method should not call any "stateful" methods of the
* drivetrain (anything that starts with "set") to allow one to switch between
* modes easily.
*
* @param driveTrain A {@link MecanumDrive} object representing the drivetrain
* of the robot.
* @param currentGyro The current gyro heading, if a gyro exists. Nothing should
* use this right now, so just pass in 0.0 if you're not
* sure.
*
* @throws WrongDriveTypeException if an incompatible Drive type is used
*/
void drive(MecanumDrive driveTrain, double currentGyro) throws WrongDriveTypeException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package org.hyperonline.hyperlib.driving;

import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import edu.wpi.first.wpilibj.drive.MecanumDrive;

/**
*
* @author Chris McGroarty
*
*/
public class PolarDriveParams implements DriveParameters {

private double m_magnitude, m_angle, m_zRotation;

/**
* get the magnitude
*
* @return the magnitude
*/
public double magnitude() {
return m_magnitude;
}

/**
* get the angle
*
* @return the angle
*/
public double angle() {
return m_angle;
}

/**
* get the rotation
*
* @return the z-axis rotation
*/
public double rotate() {
return m_zRotation;
}

/**
* Construct a new {@link PolarDriveParams}.
*
* @param magnitude the amount to move
* @param angle the angle to move at
* @param rotate the rotation to apply
*/
public PolarDriveParams(double magnitude, double angle, double rotate) {
m_magnitude = magnitude;
m_angle = angle;
m_zRotation = rotate;
}

/**
* {@inheritDoc}
*/
@Override
public void drive(DifferentialDrive driveTrain, double currentGyro) throws WrongDriveTypeException {
throw new WrongDriveTypeException("using Polar with DifferentialDrive");

}

/**
* {@inheritDoc}
*/
@Override
public void drive(MecanumDrive driveTrain, double currentGyro) {
driveTrain.drivePolar(m_magnitude, m_angle, m_zRotation);
}

}
Loading

0 comments on commit 5d67c86

Please sign in to comment.