mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
[wpimath] Replace Speeds with Velocities (#8479)
I left "free speed" alone since that's the technical term for it. In general, velocity is a vector quantity, and speed is a magnitude (i.e., a strictly positive value). This PR also replaces the speed verbiage in MotorController with duty cycle. Fixes #8423.
This commit is contained in:
@@ -10,23 +10,23 @@ import org.wpilib.examples.romireference.subsystems.Drivetrain;
|
||||
|
||||
public class ArcadeDrive extends Command {
|
||||
private final Drivetrain m_drivetrain;
|
||||
private final Supplier<Double> m_xaxisSpeedSupplier;
|
||||
private final Supplier<Double> m_xaxisVelocitySupplier;
|
||||
private final Supplier<Double> m_zaxisRotateSupplier;
|
||||
|
||||
/**
|
||||
* Creates a new ArcadeDrive. This command will drive your robot according to the speed supplier
|
||||
* lambdas. This command does not terminate.
|
||||
* Creates a new ArcadeDrive. This command will drive your robot according to the velocity
|
||||
* supplier lambdas. This command does not terminate.
|
||||
*
|
||||
* @param drivetrain The drivetrain subsystem on which this command will run
|
||||
* @param xaxisSpeedSupplier Lambda supplier of forward/backward speed
|
||||
* @param zaxisRotateSupplier Lambda supplier of rotational speed
|
||||
* @param xaxisVelocitySupplier Lambda supplier of forward/backward velocity
|
||||
* @param zaxisRotateSupplier Lambda supplier of rotational velocity
|
||||
*/
|
||||
public ArcadeDrive(
|
||||
Drivetrain drivetrain,
|
||||
Supplier<Double> xaxisSpeedSupplier,
|
||||
Supplier<Double> xaxisVelocitySupplier,
|
||||
Supplier<Double> zaxisRotateSupplier) {
|
||||
m_drivetrain = drivetrain;
|
||||
m_xaxisSpeedSupplier = xaxisSpeedSupplier;
|
||||
m_xaxisVelocitySupplier = xaxisVelocitySupplier;
|
||||
m_zaxisRotateSupplier = zaxisRotateSupplier;
|
||||
addRequirements(drivetrain);
|
||||
}
|
||||
@@ -38,7 +38,7 @@ public class ArcadeDrive extends Command {
|
||||
// Called every time the scheduler runs while the command is scheduled.
|
||||
@Override
|
||||
public void execute() {
|
||||
m_drivetrain.arcadeDrive(m_xaxisSpeedSupplier.get(), m_zaxisRotateSupplier.get());
|
||||
m_drivetrain.arcadeDrive(m_xaxisVelocitySupplier.get(), m_zaxisRotateSupplier.get());
|
||||
}
|
||||
|
||||
// Called once the command ends or is interrupted.
|
||||
|
||||
@@ -10,19 +10,19 @@ import org.wpilib.examples.romireference.subsystems.Drivetrain;
|
||||
public class DriveDistance extends Command {
|
||||
private final Drivetrain m_drive;
|
||||
private final double m_distance;
|
||||
private final double m_speed;
|
||||
private final double m_velocity;
|
||||
|
||||
/**
|
||||
* Creates a new DriveDistance. This command will drive your your robot for a desired distance at
|
||||
* a desired speed.
|
||||
* a desired velocity.
|
||||
*
|
||||
* @param speed The speed at which the robot will drive
|
||||
* @param velocity The velocity at which the robot will drive
|
||||
* @param inches The number of inches the robot will drive
|
||||
* @param drive The drivetrain subsystem on which this command will run
|
||||
*/
|
||||
public DriveDistance(double speed, double inches, Drivetrain drive) {
|
||||
public DriveDistance(double velocity, double inches, Drivetrain drive) {
|
||||
m_distance = inches;
|
||||
m_speed = speed;
|
||||
m_velocity = velocity;
|
||||
m_drive = drive;
|
||||
addRequirements(drive);
|
||||
}
|
||||
@@ -37,7 +37,7 @@ public class DriveDistance extends Command {
|
||||
// Called every time the scheduler runs while the command is scheduled.
|
||||
@Override
|
||||
public void execute() {
|
||||
m_drive.arcadeDrive(m_speed, 0);
|
||||
m_drive.arcadeDrive(m_velocity, 0);
|
||||
}
|
||||
|
||||
// Called once the command ends or is interrupted.
|
||||
|
||||
@@ -9,19 +9,19 @@ import org.wpilib.examples.romireference.subsystems.Drivetrain;
|
||||
|
||||
public class DriveTime extends Command {
|
||||
private final double m_duration;
|
||||
private final double m_speed;
|
||||
private final double m_velocity;
|
||||
private final Drivetrain m_drive;
|
||||
private long m_startTime;
|
||||
|
||||
/**
|
||||
* Creates a new DriveTime. This command will drive your robot for a desired speed and time.
|
||||
* Creates a new DriveTime. This command will drive your robot for a desired velocity and time.
|
||||
*
|
||||
* @param speed The speed which the robot will drive. Negative is in reverse.
|
||||
* @param velocity The velocity which the robot will drive. Negative is in reverse.
|
||||
* @param time How much time to drive in seconds
|
||||
* @param drive The drivetrain subsystem on which this command will run
|
||||
*/
|
||||
public DriveTime(double speed, double time, Drivetrain drive) {
|
||||
m_speed = speed;
|
||||
public DriveTime(double velocity, double time, Drivetrain drive) {
|
||||
m_velocity = velocity;
|
||||
m_duration = time * 1000;
|
||||
m_drive = drive;
|
||||
addRequirements(drive);
|
||||
@@ -37,7 +37,7 @@ public class DriveTime extends Command {
|
||||
// Called every time the scheduler runs while the command is scheduled.
|
||||
@Override
|
||||
public void execute() {
|
||||
m_drive.arcadeDrive(m_speed, 0);
|
||||
m_drive.arcadeDrive(m_velocity, 0);
|
||||
}
|
||||
|
||||
// Called once the command ends or is interrupted.
|
||||
|
||||
@@ -10,19 +10,19 @@ import org.wpilib.examples.romireference.subsystems.Drivetrain;
|
||||
public class TurnDegrees extends Command {
|
||||
private final Drivetrain m_drive;
|
||||
private final double m_degrees;
|
||||
private final double m_speed;
|
||||
private final double m_velocity;
|
||||
|
||||
/**
|
||||
* Creates a new TurnDegrees. This command will turn your robot for a desired rotation (in
|
||||
* degrees) and rotational speed.
|
||||
* degrees) and rotational velocity.
|
||||
*
|
||||
* @param speed The speed which the robot will drive. Negative is in reverse.
|
||||
* @param velocity The velocity which the robot will drive. Negative is in reverse.
|
||||
* @param degrees Degrees to turn. Leverages encoders to compare distance.
|
||||
* @param drive The drive subsystem on which this command will run
|
||||
*/
|
||||
public TurnDegrees(double speed, double degrees, Drivetrain drive) {
|
||||
public TurnDegrees(double velocity, double degrees, Drivetrain drive) {
|
||||
m_degrees = degrees;
|
||||
m_speed = speed;
|
||||
m_velocity = velocity;
|
||||
m_drive = drive;
|
||||
addRequirements(drive);
|
||||
}
|
||||
@@ -38,7 +38,7 @@ public class TurnDegrees extends Command {
|
||||
// Called every time the scheduler runs while the command is scheduled.
|
||||
@Override
|
||||
public void execute() {
|
||||
m_drive.arcadeDrive(0, m_speed);
|
||||
m_drive.arcadeDrive(0, m_velocity);
|
||||
}
|
||||
|
||||
// Called once the command ends or is interrupted.
|
||||
|
||||
@@ -9,23 +9,23 @@ import org.wpilib.examples.romireference.subsystems.Drivetrain;
|
||||
|
||||
/*
|
||||
* Creates a new TurnTime command. This command will turn your robot for a
|
||||
* desired rotational speed and time.
|
||||
* desired rotational velocity and time.
|
||||
*/
|
||||
public class TurnTime extends Command {
|
||||
private final double m_duration;
|
||||
private final double m_rotationalSpeed;
|
||||
private final double m_rotationalVelocity;
|
||||
private final Drivetrain m_drive;
|
||||
private long m_startTime;
|
||||
|
||||
/**
|
||||
* Creates a new TurnTime.
|
||||
*
|
||||
* @param speed The speed which the robot will turn. Negative is in reverse.
|
||||
* @param velocity The velocity which the robot will turn. Negative is in reverse.
|
||||
* @param time How much time to turn in seconds
|
||||
* @param drive The drive subsystem on which this command will run
|
||||
*/
|
||||
public TurnTime(double speed, double time, Drivetrain drive) {
|
||||
m_rotationalSpeed = speed;
|
||||
public TurnTime(double velocity, double time, Drivetrain drive) {
|
||||
m_rotationalVelocity = velocity;
|
||||
m_duration = time * 1000;
|
||||
m_drive = drive;
|
||||
addRequirements(drive);
|
||||
@@ -41,7 +41,7 @@ public class TurnTime extends Command {
|
||||
// Called every time the scheduler runs while the command is scheduled.
|
||||
@Override
|
||||
public void execute() {
|
||||
m_drive.arcadeDrive(0, m_rotationalSpeed);
|
||||
m_drive.arcadeDrive(0, m_rotationalVelocity);
|
||||
}
|
||||
|
||||
// Called once the command ends or is interrupted.
|
||||
|
||||
@@ -27,7 +27,7 @@ public class Drivetrain extends SubsystemBase {
|
||||
|
||||
// Set up the differential drive controller
|
||||
private final DifferentialDrive m_diffDrive =
|
||||
new DifferentialDrive(m_leftMotor::set, m_rightMotor::set);
|
||||
new DifferentialDrive(m_leftMotor::setDutyCycle, m_rightMotor::setDutyCycle);
|
||||
|
||||
// Set up the RomiGyro
|
||||
private final RomiGyro m_gyro = new RomiGyro();
|
||||
@@ -48,8 +48,8 @@ public class Drivetrain extends SubsystemBase {
|
||||
resetEncoders();
|
||||
}
|
||||
|
||||
public void arcadeDrive(double xaxisSpeed, double zaxisRotate) {
|
||||
m_diffDrive.arcadeDrive(xaxisSpeed, zaxisRotate);
|
||||
public void arcadeDrive(double xaxisVelocity, double zaxisRotate) {
|
||||
m_diffDrive.arcadeDrive(xaxisVelocity, zaxisRotate);
|
||||
}
|
||||
|
||||
public void resetEncoders() {
|
||||
|
||||
Reference in New Issue
Block a user