Add tests for equivilance of RobotDrive and DifferentialDrive/MecanumDrive (#732)

Add documentation for how to get same results as RobotDrive and improve
RobotDrive documentation
This commit is contained in:
sciencewhiz
2017-11-29 21:41:00 -08:00
committed by Peter Johnson
parent e308dd28f3
commit cbd08a1e11
10 changed files with 484 additions and 21 deletions

View File

@@ -200,7 +200,8 @@ public class RobotDrive implements MotorSafety {
/**
* Provide tank steering using the stored robot configuration. drive the robot using two joystick
* inputs. The Y-axis will be selected from each Joystick object.
* inputs. The Y-axis will be selected from each Joystick object. The calculated values will be
* squared to decrease sensitivity at low speeds.
*
* @param leftStick The joystick to control the left side of the robot.
* @param rightStick The joystick to control the right side of the robot.
@@ -229,7 +230,8 @@ public class RobotDrive implements MotorSafety {
/**
* Provide tank steering using the stored robot configuration. This function lets you pick the
* axis to be used on each Joystick object for the left and right sides of the robot.
* axis to be used on each Joystick object for the left and right sides of the robot. The
* calculated values will be squared to decrease sensitivity at low speeds.
*
* @param leftStick The Joystick object to use for the left side of the robot.
* @param leftAxis The axis to select on the left side Joystick object.
@@ -292,7 +294,8 @@ public class RobotDrive implements MotorSafety {
/**
* Provide tank steering using the stored robot configuration. This function lets you directly
* provide joystick values from any source.
* provide joystick values from any source. The calculated values will be squared to decrease
* sensitivity at low speeds.
*
* @param leftValue The value of the left stick.
* @param rightValue The value of the right stick.
@@ -304,7 +307,8 @@ public class RobotDrive implements MotorSafety {
/**
* Arcade drive implements single stick driving. Given a single Joystick, the class assumes the Y
* axis for the move value and the X axis for the rotate value. (Should add more information here
* regarding the way that arcade drive works.)
* regarding the way that arcade drive works.) The calculated values will be squared to decrease
* sensitivity at low speeds.
*
* @param stick The joystick to use for Arcade single-stick driving. The Y-axis will be
* selected for forwards/backwards and the X-axis will be selected for
@@ -319,7 +323,8 @@ public class RobotDrive implements MotorSafety {
/**
* Arcade drive implements single stick driving. Given a single Joystick, the class assumes the Y
* axis for the move value and the X axis for the rotate value. (Should add more information here
* regarding the way that arcade drive works.)
* regarding the way that arcade drive works.) The calculated values will be squared to decrease
* sensitivity at low speeds.
*
* @param stick The joystick to use for Arcade single-stick driving. The Y-axis will be selected
* for forwards/backwards and the X-axis will be selected for rotation rate.
@@ -350,7 +355,8 @@ public class RobotDrive implements MotorSafety {
/**
* Arcade drive implements single stick driving. Given two joystick instances and two axis,
* compute the values to send to either two or four motors.
* compute the values to send to either two or four motors. The calculated values will be
* squared to decrease sensitivity at low speeds.
*
* @param moveStick The Joystick object that represents the forward/backward direction
* @param moveAxis The axis on the moveStick object to use for forwards/backwards (typically
@@ -418,7 +424,8 @@ public class RobotDrive implements MotorSafety {
/**
* Arcade drive implements single stick driving. This function lets you directly provide
* joystick values from any source.
* joystick values from any source. The calculated values will be squared to decrease
* sensitivity at low speeds.
*
* @param moveValue The value to use for forwards/backwards
* @param rotateValue The value to use for the rotate right/left
@@ -486,9 +493,9 @@ public class RobotDrive implements MotorSafety {
* so that the front and back wheels are toed in 45 degrees. When looking at the wheels from the
* top, the roller axles should form an X across the robot.
*
* @param magnitude The speed that the robot should drive in a given direction.
* @param direction The direction the robot should drive in degrees. The direction and magnitude
* are independent of the rotation rate.
* @param magnitude The speed that the robot should drive in a given direction. [-1.0..1.0]
* @param direction The angle the robot should drive in degrees. The direction and magnitude
* are independent of the rotation rate. [-180.0..180.0]
* @param rotation The rate of rotation for the robot that is completely independent of the
* magnitude or direction. [-1.0..1.0]
*/
@@ -501,7 +508,7 @@ public class RobotDrive implements MotorSafety {
// Normalized for full power along the Cartesian axes.
magnitude = limit(magnitude) * Math.sqrt(2.0);
// The rollers are at 45 degree angles.
double dirInRad = (direction + 45.0) * 3.14159 / 180.0;
double dirInRad = (direction + 45.0) * Math.PI / 180.0;
double cosD = Math.cos(dirInRad);
double sinD = Math.sin(dirInRad);
@@ -529,7 +536,7 @@ public class RobotDrive implements MotorSafety {
* <p>This is an alias to mecanumDrive_Polar() for backward compatibility
*
* @param magnitude The speed that the robot should drive in a given direction. [-1.0..1.0]
* @param direction The direction the robot should drive. The direction and maginitute are
* @param direction The direction the robot should drive. The direction and maginitude are
* independent of the rotation rate.
* @param rotation The rate of rotation for the robot that is completely independent of the
* magnitute or direction. [-1.0..1.0]
@@ -601,8 +608,8 @@ public class RobotDrive implements MotorSafety {
*/
@SuppressWarnings("ParameterName")
protected static double[] rotateVector(double x, double y, double angle) {
double cosA = Math.cos(angle * (3.14159 / 180.0));
double sinA = Math.sin(angle * (3.14159 / 180.0));
double cosA = Math.cos(angle * (Math.PI / 180.0));
double sinA = Math.sin(angle * (Math.PI / 180.0));
double[] out = new double[2];
out[0] = x * cosA - y * sinA;
out[1] = x * sinA + y * cosA;

View File

@@ -18,7 +18,8 @@ import edu.wpi.first.wpilibj.hal.HAL;
*
* <p>These drive bases typically have drop-center / skid-steer with two or more wheels per side
* (e.g., 6WD or 8WD). This class takes a SpeedController per side. For four and
* six motor drivetrains, construct and pass in {@link SpeedControllerGroup} instances as follows.
* six motor drivetrains, construct and pass in {@link edu.wpi.first.wpilibj.SpeedControllerGroup}
* instances as follows.
*
* <p>Four motor drivetrain:
* <pre><code>
@@ -73,6 +74,20 @@ import edu.wpi.first.wpilibj.hal.HAL;
* <p>The positive X axis points ahead, the positive Y axis points right, and the positive Z axis
* points down. Rotations follow the right-hand rule, so clockwise rotation around the Z axis is
* positive.
*
* <p>Inputs smaller then {@value edu.wpi.first.wpilibj.drive.RobotDriveBase#kDefaultDeadband} will
* be set to 0, and larger values will be scaled so that the full range is still used. This
* deadband value can be changed with {@link #setDeadband}.
*
* <p>RobotDrive porting guide:
* <br>{@link #tankDrive(double, double)} is equivalent to
* {@link edu.wpi.first.wpilibj.RobotDrive#tankDrive(double, double)} if a deadband of 0 is used.
* <br>{@link #arcadeDrive(double, double)} is equivalent to
* {@link edu.wpi.first.wpilibj.RobotDrive#arcadeDrive(double, double)} if a deadband of 0 is used
* and the the rotation input is inverted eg arcadeDrive(y, -rotation)
* <br>{@link #curvatureDrive(double, double, boolean)} is similar in concept to
* {@link edu.wpi.first.wpilibj.RobotDrive#drive(double, double)} with the addition of a quick turn
* mode. However, it is not designed to give exactly the same response.
*/
public class DifferentialDrive extends RobotDriveBase {
public static final double kDefaultQuickStopThreshold = 0.2;
@@ -99,6 +114,7 @@ public class DifferentialDrive extends RobotDriveBase {
/**
* Arcade drive method for differential drive platform.
* The calculated values will be squared to decrease sensitivity at low speeds.
*
* @param xSpeed The robot's speed along the X axis [-1.0..1.0]. Forward is positive.
* @param zRotation The robot's rotation rate around the Z axis [-1.0..1.0]. Clockwise is
@@ -246,6 +262,7 @@ public class DifferentialDrive extends RobotDriveBase {
/**
* Tank drive method for differential drive platform.
* The calculated values will be squared to decrease sensitivity at low speeds.
*
* @param leftSpeed The robot's left side speed along the X axis [-1.0..1.0]. Forward is
* positive.

View File

@@ -39,6 +39,21 @@ import edu.wpi.first.wpilibj.hal.HAL;
* <p>The positive X axis points ahead, the positive Y axis points right, and the positive Z axis
* points down. Rotations follow the right-hand rule, so clockwise rotation around the Z axis is
* positive.
*
* <p>Inputs smaller then {@value edu.wpi.first.wpilibj.drive.RobotDriveBase#kDefaultDeadband} will
* be set to 0, and larger values will be scaled so that the full range is still used. This
* deadband value can be changed with {@link #setDeadband}.
*
* <p>RobotDrive porting guide:
* <br>In MecanumDrive, the right side speed controllers are automatically inverted, while in
* RobotDrive, no speed controllers are automatically inverted.
* <br>{@link #driveCartesian(double, double, double, double)} is equivalent to
* {@link edu.wpi.first.wpilibj.RobotDrive#mecanumDrive_Cartesian(double, double, double, double)}
* if a deadband of 0 is used, and the ySpeed and gyroAngle values are inverted compared to
* RobotDrive (eg driveCartesian(xSpeed, -ySpeed, zRotation, -gyroAngle).
* <br>{@link #drivePolar(double, double, double)} is equivalent to
* {@link edu.wpi.first.wpilibj.RobotDrive#mecanumDrive_Polar(double, double, double)} if a
* deadband of 0 is used.
*/
public class MecanumDrive extends RobotDriveBase {
private SpeedController m_frontLeftMotor;

View File

@@ -14,8 +14,11 @@ import edu.wpi.first.wpilibj.MotorSafetyHelper;
* Common base class for drive platforms.
*/
public abstract class RobotDriveBase implements MotorSafety {
protected double m_deadband = 0.02;
protected double m_maxOutput = 1.0;
public static final double kDefaultDeadband = 0.02;
public static final double kDefaultMaxOutput = 1.0;
protected double m_deadband = kDefaultDeadband;
protected double m_maxOutput = kDefaultMaxOutput;
protected MotorSafetyHelper m_safetyHelper = new MotorSafetyHelper(this);
/**
@@ -37,13 +40,22 @@ public abstract class RobotDriveBase implements MotorSafety {
m_safetyHelper.setSafetyEnabled(true);
}
/**
* Change the default value for deadband scaling. The default value is
* {@value #kDefaultDeadband}. Values smaller then the deadband are set to 0, while values
* larger then the deadband are scaled from 0.0 to 1.0. See {@link #applyDeadband}.
*
* @param deadband The deadband to set.
*/
public void setDeadband(double deadband) {
m_deadband = deadband;
}
/**
* Configure the scaling factor for using RobotDrive with motor controllers in a mode other than
* PercentVbus.
* Configure the scaling factor for using drive methods with motor controllers in a mode other
* than PercentVbus or to limit the maximum output.
*
* <p>The default value is {@value #kDefaultMaxOutput}.
*
* @param maxOutput Multiplied with the output percentage computed by the drive functions.
*/