[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:
Tyler Veness
2024-01-01 13:37:51 -08:00
committed by GitHub
parent 8aca706217
commit e7c9f27683
132 changed files with 1159 additions and 697 deletions

View File

@@ -4,10 +4,14 @@
#pragma once
#include <wpi/deprecated.h>
#include "frc/motorcontrol/MotorController.h"
namespace frc {
WPI_IGNORE_DEPRECATED
class MockMotorController : public MotorController {
public:
void Set(double speed) override;
@@ -22,4 +26,6 @@ class MockMotorController : public MotorController {
bool m_isInverted = false;
};
WPI_UNIGNORE_DEPRECATED
} // namespace frc

View File

@@ -0,0 +1,23 @@
// 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.
#pragma once
namespace frc {
class MockPWMMotorController {
public:
void Set(double speed);
double Get() const;
void SetInverted(bool isInverted);
bool GetInverted() const;
void Disable();
void StopMotor();
private:
double m_speed = 0.0;
bool m_isInverted = false;
};
} // namespace frc