mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[wpilib] Add functional interface equivalents to MotorController (#6053)
This does not deprecate any current functionality, but prepares the way for future deprecation. The drive classes now accept void(double) functions, which makes them more flexible. The C++ API ended up a bit more verbose, but the Java API is really concise with method references, which is >80% of our userbase. For example: `DifferentialDrive drive = new DifferentialDrive(m_leftMotor::set, m_rightMotor::set);` Lambdas can be passed to interoperate with vendor motor controller APIs that don't have e.g., set(double), so CTRE doesn't have to maintain their WPI_ classes anymore. MotorControllerGroup was replaced with PWMMotorController.addFollower() for PWM motor controllers. Users of CAN motor controllers should use their vendor's follower functionality.
This commit is contained in:
@@ -22,6 +22,7 @@ import java.util.logging.Logger;
|
||||
* fixture. This allows tests to be mailable so that you can easily reconfigure the physical testbed
|
||||
* without breaking the tests.
|
||||
*/
|
||||
@SuppressWarnings("removal")
|
||||
public abstract class MotorEncoderFixture<T extends MotorController> implements ITestFixture {
|
||||
private static final Logger logger = Logger.getLogger(MotorEncoderFixture.class.getName());
|
||||
private boolean m_initialized = false;
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.motorcontrol;
|
||||
|
||||
public class MockMotorController implements MotorController {
|
||||
private double m_speed;
|
||||
private boolean m_isInverted;
|
||||
|
||||
@Override
|
||||
public void set(double speed) {
|
||||
m_speed = m_isInverted ? -speed : speed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get() {
|
||||
return m_speed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInverted(boolean isInverted) {
|
||||
m_isInverted = isInverted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getInverted() {
|
||||
return m_isInverted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
m_speed = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopMotor() {
|
||||
disable();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user