Skip to content

Commit 5d67c86

Browse files
committed
add MecanumDrive to DriveParameters
1 parent 6bc6f91 commit 5d67c86

File tree

6 files changed

+313
-81
lines changed

6 files changed

+313
-81
lines changed

src/main/java/org/hyperonline/hyperlib/driving/ArcadeDriveParams.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.hyperonline.hyperlib.driving;
22

33
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
4+
import edu.wpi.first.wpilibj.drive.MecanumDrive;
45

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

2526
/**
26-
* Construct a new {@link ArcadeDriveParams}.
27-
*
28-
* @param move
29-
* The amount to move forwards or backwards
30-
* @param rotate
31-
* The amount to rotate
32-
* @param squareInputs
33-
* Whether to square the inputs. This is desirable if the input
34-
* is coming from a joystick, as it creates a "soft deadzone". If
35-
* coming from another source, like a PID controller, this should
36-
* be <code>false</code>.
37-
*/
27+
* Construct a new {@link ArcadeDriveParams}.
28+
*
29+
* @param move The amount to move forwards or backwards
30+
* @param rotate The amount to rotate
31+
* @param squareInputs Whether to square the inputs. This is desirable if the
32+
* input is coming from a joystick, as it creates a "soft
33+
* deadzone". If coming from another source, like a PID
34+
* controller, this should be <code>false</code>.
35+
*/
3836
public ArcadeDriveParams(double move, double rotate, boolean squareInputs) {
3937
m_move = move;
4038
m_rotate = rotate;
@@ -49,6 +47,14 @@ public void drive(DifferentialDrive driveTrain, double currentGyro) {
4947
driveTrain.arcadeDrive(m_move, m_rotate, m_squareInputs);
5048
}
5149

50+
/**
51+
* {@inheritDoc}
52+
*/
53+
@Override
54+
public void drive(MecanumDrive driveTrain, double currentGyro) throws WrongDriveTypeException {
55+
throw new WrongDriveTypeException("using Arcade with MecanumDrive");
56+
}
57+
5258
/**
5359
* Get the move parameter
5460
*
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package org.hyperonline.hyperlib.driving;
2+
3+
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
4+
import edu.wpi.first.wpilibj.drive.MecanumDrive;
5+
6+
/**
7+
*
8+
* @author Chris McGroarty
9+
*
10+
*/
11+
public class CartesianDriveParams implements DriveParameters {
12+
13+
private double m_ySpeed, m_xSpeed, m_zRotate, m_gyroAngle;
14+
15+
/**
16+
* get the speed on the y-axis
17+
*
18+
* @return the y-axis speed
19+
*/
20+
public double ySpeed() {
21+
return m_ySpeed;
22+
}
23+
24+
/**
25+
* get the speed on the x-axis
26+
*
27+
* @return the x-axis speed
28+
*/
29+
public double xSpeed() {
30+
return m_xSpeed;
31+
}
32+
33+
/**
34+
* get the rotation from the z-axis
35+
*
36+
* @return the z-axis rotation
37+
*/
38+
public double zRotate() {
39+
return m_zRotate;
40+
}
41+
42+
/**
43+
* get the gyro angle
44+
*
45+
* @return the gyro angle
46+
*/
47+
public double gyroAngle() {
48+
return m_gyroAngle;
49+
}
50+
51+
/**
52+
* Construct a new {@link CartesianDriveParams}.
53+
*
54+
* @param ySpeed the speed to move in the y-axis
55+
* @param xSpeed the speed to move in the x-axis
56+
* @param zRotate the rotation to apply in the z-axis
57+
* @param gyroAngle the gyroAngle to use
58+
*/
59+
public CartesianDriveParams(double ySpeed, double xSpeed, double zRotate, double gyroAngle) {
60+
m_ySpeed = ySpeed;
61+
m_xSpeed = xSpeed;
62+
m_zRotate = zRotate;
63+
m_gyroAngle = gyroAngle;
64+
}
65+
66+
/**
67+
* {@inheritDoc}
68+
*/
69+
@Override
70+
public void drive(DifferentialDrive driveTrain, double currentGyro) throws WrongDriveTypeException {
71+
throw new WrongDriveTypeException("using Cartesian with DifferentialDrive");
72+
73+
}
74+
75+
/**
76+
* {@inheritDoc}
77+
*/
78+
@Override
79+
public void drive(MecanumDrive driveTrain, double currentGyro) {
80+
driveTrain.driveCartesian(m_ySpeed, m_xSpeed, m_zRotate, m_gyroAngle);
81+
82+
}
83+
84+
}
Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.hyperonline.hyperlib.driving;
22

33
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
4+
import edu.wpi.first.wpilibj.drive.MecanumDrive;
45

56
/**
67
* The {@link DriveParameters} interface allows one to use polymorphism to
@@ -19,21 +20,37 @@
1920
*
2021
*/
2122
public interface DriveParameters {
22-
/**
23-
* Drive the robot. This method should not call any "stateful" methods of
24-
* the drivetrain (anything that starts with "set") to allow one to switch
25-
* between modes easily.
26-
*
27-
* TODO: pass a wrapper of DifferentialDrive, which only allows certain methods
28-
* TODO: remove currentGyro. This is pretty irrelevant, and can be obtained
29-
* in other ways.
30-
*
31-
* @param driveTrain
32-
* A {@link DifferentialDrive} object representing the drivetrain of the
33-
* robot.
34-
* @param currentGyro
35-
* The current gyro heading, if a gyro exists. Nothing should use
36-
* this right now, so just pass in 0.0 if you're not sure.
37-
*/
38-
void drive(DifferentialDrive driveTrain, double currentGyro);
23+
/**
24+
* Drive the robot. This method should not call any "stateful" methods of the
25+
* drivetrain (anything that starts with "set") to allow one to switch between
26+
* modes easily.
27+
*
28+
* TODO: pass a wrapper of DifferentialDrive, which only allows certain methods
29+
* TODO: remove currentGyro. This is pretty irrelevant, and can be obtained in
30+
* other ways.
31+
*
32+
* @param driveTrain A {@link DifferentialDrive} object representing the
33+
* drivetrain of the robot.
34+
* @param currentGyro The current gyro heading, if a gyro exists. Nothing should
35+
* use this right now, so just pass in 0.0 if you're not
36+
* sure.
37+
*
38+
* @throws WrongDriveTypeException if an incompatible Drive type is used
39+
*/
40+
void drive(DifferentialDrive driveTrain, double currentGyro) throws WrongDriveTypeException;
41+
42+
/**
43+
* Drive the robot. This method should not call any "stateful" methods of the
44+
* drivetrain (anything that starts with "set") to allow one to switch between
45+
* modes easily.
46+
*
47+
* @param driveTrain A {@link MecanumDrive} object representing the drivetrain
48+
* of the robot.
49+
* @param currentGyro The current gyro heading, if a gyro exists. Nothing should
50+
* use this right now, so just pass in 0.0 if you're not
51+
* sure.
52+
*
53+
* @throws WrongDriveTypeException if an incompatible Drive type is used
54+
*/
55+
void drive(MecanumDrive driveTrain, double currentGyro) throws WrongDriveTypeException;
3956
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package org.hyperonline.hyperlib.driving;
2+
3+
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
4+
import edu.wpi.first.wpilibj.drive.MecanumDrive;
5+
6+
/**
7+
*
8+
* @author Chris McGroarty
9+
*
10+
*/
11+
public class PolarDriveParams implements DriveParameters {
12+
13+
private double m_magnitude, m_angle, m_zRotation;
14+
15+
/**
16+
* get the magnitude
17+
*
18+
* @return the magnitude
19+
*/
20+
public double magnitude() {
21+
return m_magnitude;
22+
}
23+
24+
/**
25+
* get the angle
26+
*
27+
* @return the angle
28+
*/
29+
public double angle() {
30+
return m_angle;
31+
}
32+
33+
/**
34+
* get the rotation
35+
*
36+
* @return the z-axis rotation
37+
*/
38+
public double rotate() {
39+
return m_zRotation;
40+
}
41+
42+
/**
43+
* Construct a new {@link PolarDriveParams}.
44+
*
45+
* @param magnitude the amount to move
46+
* @param angle the angle to move at
47+
* @param rotate the rotation to apply
48+
*/
49+
public PolarDriveParams(double magnitude, double angle, double rotate) {
50+
m_magnitude = magnitude;
51+
m_angle = angle;
52+
m_zRotation = rotate;
53+
}
54+
55+
/**
56+
* {@inheritDoc}
57+
*/
58+
@Override
59+
public void drive(DifferentialDrive driveTrain, double currentGyro) throws WrongDriveTypeException {
60+
throw new WrongDriveTypeException("using Polar with DifferentialDrive");
61+
62+
}
63+
64+
/**
65+
* {@inheritDoc}
66+
*/
67+
@Override
68+
public void drive(MecanumDrive driveTrain, double currentGyro) {
69+
driveTrain.drivePolar(m_magnitude, m_angle, m_zRotation);
70+
}
71+
72+
}

0 commit comments

Comments
 (0)