mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-01 02:41:48 +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:
@@ -16,11 +16,21 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
WPI_IGNORE_DEPRECATED
|
||||
|
||||
DifferentialDrive::DifferentialDrive(MotorController& leftMotor,
|
||||
MotorController& rightMotor)
|
||||
: m_leftMotor(&leftMotor), m_rightMotor(&rightMotor) {
|
||||
wpi::SendableRegistry::AddChild(this, m_leftMotor);
|
||||
wpi::SendableRegistry::AddChild(this, m_rightMotor);
|
||||
: DifferentialDrive{[&](double output) { leftMotor.Set(output); },
|
||||
[&](double output) { rightMotor.Set(output); }} {
|
||||
wpi::SendableRegistry::AddChild(this, &leftMotor);
|
||||
wpi::SendableRegistry::AddChild(this, &rightMotor);
|
||||
}
|
||||
|
||||
WPI_UNIGNORE_DEPRECATED
|
||||
|
||||
DifferentialDrive::DifferentialDrive(std::function<void(double)> leftMotor,
|
||||
std::function<void(double)> rightMotor)
|
||||
: m_leftMotor{std::move(leftMotor)}, m_rightMotor{std::move(rightMotor)} {
|
||||
static int instances = 0;
|
||||
++instances;
|
||||
wpi::SendableRegistry::AddLW(this, "DifferentialDrive", instances);
|
||||
@@ -40,8 +50,11 @@ void DifferentialDrive::ArcadeDrive(double xSpeed, double zRotation,
|
||||
|
||||
auto [left, right] = ArcadeDriveIK(xSpeed, zRotation, squareInputs);
|
||||
|
||||
m_leftMotor->Set(left * m_maxOutput);
|
||||
m_rightMotor->Set(right * m_maxOutput);
|
||||
m_leftOutput = left * m_maxOutput;
|
||||
m_rightOutput = right * m_maxOutput;
|
||||
|
||||
m_leftMotor(m_leftOutput);
|
||||
m_rightMotor(m_rightOutput);
|
||||
|
||||
Feed();
|
||||
}
|
||||
@@ -60,8 +73,11 @@ void DifferentialDrive::CurvatureDrive(double xSpeed, double zRotation,
|
||||
|
||||
auto [left, right] = CurvatureDriveIK(xSpeed, zRotation, allowTurnInPlace);
|
||||
|
||||
m_leftMotor->Set(left * m_maxOutput);
|
||||
m_rightMotor->Set(right * m_maxOutput);
|
||||
m_leftOutput = left * m_maxOutput;
|
||||
m_rightOutput = right * m_maxOutput;
|
||||
|
||||
m_leftMotor(m_leftOutput);
|
||||
m_rightMotor(m_rightOutput);
|
||||
|
||||
Feed();
|
||||
}
|
||||
@@ -80,8 +96,11 @@ void DifferentialDrive::TankDrive(double leftSpeed, double rightSpeed,
|
||||
|
||||
auto [left, right] = TankDriveIK(leftSpeed, rightSpeed, squareInputs);
|
||||
|
||||
m_leftMotor->Set(left * m_maxOutput);
|
||||
m_rightMotor->Set(right * m_maxOutput);
|
||||
m_leftOutput = left * m_maxOutput;
|
||||
m_rightOutput = right * m_maxOutput;
|
||||
|
||||
m_leftMotor(m_leftOutput);
|
||||
m_rightMotor(m_rightOutput);
|
||||
|
||||
Feed();
|
||||
}
|
||||
@@ -157,8 +176,12 @@ DifferentialDrive::WheelSpeeds DifferentialDrive::TankDriveIK(
|
||||
}
|
||||
|
||||
void DifferentialDrive::StopMotor() {
|
||||
m_leftMotor->StopMotor();
|
||||
m_rightMotor->StopMotor();
|
||||
m_leftOutput = 0.0;
|
||||
m_rightOutput = 0.0;
|
||||
|
||||
m_leftMotor(0.0);
|
||||
m_rightMotor(0.0);
|
||||
|
||||
Feed();
|
||||
}
|
||||
|
||||
@@ -171,9 +194,7 @@ void DifferentialDrive::InitSendable(wpi::SendableBuilder& builder) {
|
||||
builder.SetActuator(true);
|
||||
builder.SetSafeState([=, this] { StopMotor(); });
|
||||
builder.AddDoubleProperty(
|
||||
"Left Motor Speed", [=, this] { return m_leftMotor->Get(); },
|
||||
[=, this](double value) { m_leftMotor->Set(value); });
|
||||
"Left Motor Speed", [&] { return m_leftOutput; }, m_leftMotor);
|
||||
builder.AddDoubleProperty(
|
||||
"Right Motor Speed", [=, this] { return m_rightMotor->Get(); },
|
||||
[=, this](double value) { m_rightMotor->Set(value); });
|
||||
"Right Motor Speed", [&] { return m_rightOutput; }, m_rightMotor);
|
||||
}
|
||||
|
||||
@@ -16,18 +16,32 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
WPI_IGNORE_DEPRECATED
|
||||
|
||||
MecanumDrive::MecanumDrive(MotorController& frontLeftMotor,
|
||||
MotorController& rearLeftMotor,
|
||||
MotorController& frontRightMotor,
|
||||
MotorController& rearRightMotor)
|
||||
: m_frontLeftMotor(&frontLeftMotor),
|
||||
m_rearLeftMotor(&rearLeftMotor),
|
||||
m_frontRightMotor(&frontRightMotor),
|
||||
m_rearRightMotor(&rearRightMotor) {
|
||||
wpi::SendableRegistry::AddChild(this, m_frontLeftMotor);
|
||||
wpi::SendableRegistry::AddChild(this, m_rearLeftMotor);
|
||||
wpi::SendableRegistry::AddChild(this, m_frontRightMotor);
|
||||
wpi::SendableRegistry::AddChild(this, m_rearRightMotor);
|
||||
: MecanumDrive{[&](double output) { frontLeftMotor.Set(output); },
|
||||
[&](double output) { rearLeftMotor.Set(output); },
|
||||
[&](double output) { frontRightMotor.Set(output); },
|
||||
[&](double output) { rearRightMotor.Set(output); }} {
|
||||
wpi::SendableRegistry::AddChild(this, &frontLeftMotor);
|
||||
wpi::SendableRegistry::AddChild(this, &rearLeftMotor);
|
||||
wpi::SendableRegistry::AddChild(this, &frontRightMotor);
|
||||
wpi::SendableRegistry::AddChild(this, &rearRightMotor);
|
||||
}
|
||||
|
||||
WPI_UNIGNORE_DEPRECATED
|
||||
|
||||
MecanumDrive::MecanumDrive(std::function<void(double)> frontLeftMotor,
|
||||
std::function<void(double)> rearLeftMotor,
|
||||
std::function<void(double)> frontRightMotor,
|
||||
std::function<void(double)> rearRightMotor)
|
||||
: m_frontLeftMotor{std::move(frontLeftMotor)},
|
||||
m_rearLeftMotor{std::move(rearLeftMotor)},
|
||||
m_frontRightMotor{std::move(frontRightMotor)},
|
||||
m_rearRightMotor{std::move(rearRightMotor)} {
|
||||
static int instances = 0;
|
||||
++instances;
|
||||
wpi::SendableRegistry::AddLW(this, "MecanumDrive", instances);
|
||||
@@ -47,10 +61,15 @@ void MecanumDrive::DriveCartesian(double xSpeed, double ySpeed,
|
||||
auto [frontLeft, frontRight, rearLeft, rearRight] =
|
||||
DriveCartesianIK(xSpeed, ySpeed, zRotation, gyroAngle);
|
||||
|
||||
m_frontLeftMotor->Set(frontLeft * m_maxOutput);
|
||||
m_frontRightMotor->Set(frontRight * m_maxOutput);
|
||||
m_rearLeftMotor->Set(rearLeft * m_maxOutput);
|
||||
m_rearRightMotor->Set(rearRight * m_maxOutput);
|
||||
m_frontLeftOutput = frontLeft * m_maxOutput;
|
||||
m_rearLeftOutput = rearLeft * m_maxOutput;
|
||||
m_frontRightOutput = frontRight * m_maxOutput;
|
||||
m_rearRightOutput = rearRight * m_maxOutput;
|
||||
|
||||
m_frontLeftMotor(m_frontLeftOutput);
|
||||
m_frontRightMotor(m_frontRightOutput);
|
||||
m_rearLeftMotor(m_rearLeftOutput);
|
||||
m_rearRightMotor(m_rearRightOutput);
|
||||
|
||||
Feed();
|
||||
}
|
||||
@@ -68,10 +87,16 @@ void MecanumDrive::DrivePolar(double magnitude, Rotation2d angle,
|
||||
}
|
||||
|
||||
void MecanumDrive::StopMotor() {
|
||||
m_frontLeftMotor->StopMotor();
|
||||
m_frontRightMotor->StopMotor();
|
||||
m_rearLeftMotor->StopMotor();
|
||||
m_rearRightMotor->StopMotor();
|
||||
m_frontLeftOutput = 0.0;
|
||||
m_frontRightOutput = 0.0;
|
||||
m_rearLeftOutput = 0.0;
|
||||
m_rearRightOutput = 0.0;
|
||||
|
||||
m_frontLeftMotor(0.0);
|
||||
m_frontRightMotor(0.0);
|
||||
m_rearLeftMotor(0.0);
|
||||
m_rearRightMotor(0.0);
|
||||
|
||||
Feed();
|
||||
}
|
||||
|
||||
@@ -108,15 +133,15 @@ void MecanumDrive::InitSendable(wpi::SendableBuilder& builder) {
|
||||
builder.SetActuator(true);
|
||||
builder.SetSafeState([=, this] { StopMotor(); });
|
||||
builder.AddDoubleProperty(
|
||||
"Front Left Motor Speed", [=, this] { return m_frontLeftMotor->Get(); },
|
||||
[=, this](double value) { m_frontLeftMotor->Set(value); });
|
||||
"Front Left Motor Speed", [&] { return m_frontLeftOutput; },
|
||||
m_frontLeftMotor);
|
||||
builder.AddDoubleProperty(
|
||||
"Front Right Motor Speed", [=, this] { return m_frontRightMotor->Get(); },
|
||||
[=, this](double value) { m_frontRightMotor->Set(value); });
|
||||
"Front Right Motor Speed", [&] { return m_frontRightOutput; },
|
||||
m_frontRightMotor);
|
||||
builder.AddDoubleProperty(
|
||||
"Rear Left Motor Speed", [=, this] { return m_rearLeftMotor->Get(); },
|
||||
[=, this](double value) { m_rearLeftMotor->Set(value); });
|
||||
"Rear Left Motor Speed", [&] { return m_rearLeftOutput; },
|
||||
m_rearLeftMotor);
|
||||
builder.AddDoubleProperty(
|
||||
"Rear Right Motor Speed", [=, this] { return m_rearRightMotor->Get(); },
|
||||
[=, this](double value) { m_rearRightMotor->Set(value); });
|
||||
"Rear Right Motor Speed", [&] { return m_rearRightOutput; },
|
||||
m_rearRightMotor);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ using namespace frc;
|
||||
// Can't use a delegated constructor here because of an MSVC bug.
|
||||
// https://developercommunity.visualstudio.com/content/problem/583/compiler-bug-with-delegating-a-constructor.html
|
||||
|
||||
WPI_IGNORE_DEPRECATED
|
||||
|
||||
MotorControllerGroup::MotorControllerGroup(
|
||||
std::vector<std::reference_wrapper<MotorController>>&& motorControllers)
|
||||
: m_motorControllers(std::move(motorControllers)) {
|
||||
@@ -74,3 +76,5 @@ void MotorControllerGroup::InitSendable(wpi::SendableBuilder& builder) {
|
||||
"Value", [=, this] { return Get(); },
|
||||
[=, this](double value) { Set(value); });
|
||||
}
|
||||
|
||||
WPI_UNIGNORE_DEPRECATED
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
WPI_IGNORE_DEPRECATED
|
||||
|
||||
NidecBrushless::NidecBrushless(int pwmChannel, int dioChannel)
|
||||
: m_dio(dioChannel), m_pwm(pwmChannel) {
|
||||
wpi::SendableRegistry::AddChild(this, &m_dio);
|
||||
@@ -26,6 +28,8 @@ NidecBrushless::NidecBrushless(int pwmChannel, int dioChannel)
|
||||
wpi::SendableRegistry::AddLW(this, "Nidec Brushless", pwmChannel);
|
||||
}
|
||||
|
||||
WPI_UNIGNORE_DEPRECATED
|
||||
|
||||
void NidecBrushless::Set(double speed) {
|
||||
if (!m_disabled) {
|
||||
m_speed = speed;
|
||||
|
||||
@@ -8,13 +8,31 @@
|
||||
#include <wpi/sendable/SendableBuilder.h>
|
||||
#include <wpi/sendable/SendableRegistry.h>
|
||||
|
||||
#include "frc/RobotController.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
void PWMMotorController::Set(double speed) {
|
||||
m_pwm.SetSpeed(m_isInverted ? -speed : speed);
|
||||
if (m_isInverted) {
|
||||
speed = -speed;
|
||||
}
|
||||
m_pwm.SetSpeed(speed);
|
||||
|
||||
for (auto& follower : m_nonowningFollowers) {
|
||||
follower->Set(speed);
|
||||
}
|
||||
for (auto& follower : m_owningFollowers) {
|
||||
follower->Set(speed);
|
||||
}
|
||||
|
||||
Feed();
|
||||
}
|
||||
|
||||
void PWMMotorController::SetVoltage(units::volt_t output) {
|
||||
// NOLINTNEXTLINE(bugprone-integer-division)
|
||||
Set(output / RobotController::GetBatteryVoltage());
|
||||
}
|
||||
|
||||
double PWMMotorController::Get() const {
|
||||
return m_pwm.GetSpeed() * (m_isInverted ? -1.0 : 1.0);
|
||||
}
|
||||
@@ -48,11 +66,19 @@ void PWMMotorController::EnableDeadbandElimination(bool eliminateDeadband) {
|
||||
m_pwm.EnableDeadbandElimination(eliminateDeadband);
|
||||
}
|
||||
|
||||
void PWMMotorController::AddFollower(PWMMotorController& follower) {
|
||||
m_nonowningFollowers.emplace_back(&follower);
|
||||
}
|
||||
|
||||
WPI_IGNORE_DEPRECATED
|
||||
|
||||
PWMMotorController::PWMMotorController(std::string_view name, int channel)
|
||||
: m_pwm(channel, false) {
|
||||
wpi::SendableRegistry::AddLW(this, name, channel);
|
||||
}
|
||||
|
||||
WPI_UNIGNORE_DEPRECATED
|
||||
|
||||
void PWMMotorController::InitSendable(wpi::SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("Motor Controller");
|
||||
builder.SetActuator(true);
|
||||
|
||||
@@ -4,8 +4,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
#include <wpi/deprecated.h>
|
||||
#include <wpi/sendable/Sendable.h>
|
||||
#include <wpi/sendable/SendableHelper.h>
|
||||
|
||||
@@ -20,43 +22,9 @@ class MotorController;
|
||||
* the Kit of Parts drive base, "tank drive", or West Coast Drive.
|
||||
*
|
||||
* 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 MotorController per
|
||||
* side. For four and six motor drivetrains, construct and pass in
|
||||
* MotorControllerGroup instances as follows.
|
||||
*
|
||||
* Four motor drivetrain:
|
||||
* @code{.cpp}
|
||||
* class Robot {
|
||||
* public:
|
||||
* frc::PWMVictorSPX m_frontLeft{1};
|
||||
* frc::PWMVictorSPX m_rearLeft{2};
|
||||
* frc::MotorControllerGroup m_left{m_frontLeft, m_rearLeft};
|
||||
*
|
||||
* frc::PWMVictorSPX m_frontRight{3};
|
||||
* frc::PWMVictorSPX m_rearRight{4};
|
||||
* frc::MotorControllerGroup m_right{m_frontRight, m_rearRight};
|
||||
*
|
||||
* frc::DifferentialDrive m_drive{m_left, m_right};
|
||||
* };
|
||||
* @endcode
|
||||
*
|
||||
* Six motor drivetrain:
|
||||
* @code{.cpp}
|
||||
* class Robot {
|
||||
* public:
|
||||
* frc::PWMVictorSPX m_frontLeft{1};
|
||||
* frc::PWMVictorSPX m_midLeft{2};
|
||||
* frc::PWMVictorSPX m_rearLeft{3};
|
||||
* frc::MotorControllerGroup m_left{m_frontLeft, m_midLeft, m_rearLeft};
|
||||
*
|
||||
* frc::PWMVictorSPX m_frontRight{4};
|
||||
* frc::PWMVictorSPX m_midRight{5};
|
||||
* frc::PWMVictorSPX m_rearRight{6};
|
||||
* frc::MotorControllerGroup m_right{m_frontRight, m_midRight, m_rearRight};
|
||||
*
|
||||
* frc::DifferentialDrive m_drive{m_left, m_right};
|
||||
* };
|
||||
* @endcode
|
||||
* wheels per side (e.g., 6WD or 8WD). This class takes a setter per side. For
|
||||
* four and six motor drivetrains, use CAN motor controller followers or
|
||||
* PWMMotorController::AddFollower().
|
||||
*
|
||||
* A differential drive robot has left and right wheels separated by an
|
||||
* arbitrary width.
|
||||
@@ -101,13 +69,33 @@ class DifferentialDrive : public RobotDriveBase,
|
||||
double right = 0.0;
|
||||
};
|
||||
|
||||
WPI_IGNORE_DEPRECATED
|
||||
|
||||
/**
|
||||
* Construct a DifferentialDrive.
|
||||
*
|
||||
* To pass multiple motors per side, use CAN motor controller followers or
|
||||
* PWMSpeedController::AddFollower(). If a motor needs to be inverted, do so
|
||||
* before passing it in.
|
||||
*
|
||||
* @param leftMotor Left motor.
|
||||
* @param rightMotor Right motor.
|
||||
*/
|
||||
DifferentialDrive(MotorController& leftMotor, MotorController& rightMotor);
|
||||
|
||||
WPI_UNIGNORE_DEPRECATED
|
||||
|
||||
/**
|
||||
* Construct a DifferentialDrive.
|
||||
*
|
||||
* To pass multiple motors per side, use a MotorControllerGroup. If a motor
|
||||
* needs to be inverted, do so before passing it in.
|
||||
*
|
||||
* @param leftMotor Left motor setter.
|
||||
* @param rightMotor Right motor setter.
|
||||
*/
|
||||
DifferentialDrive(MotorController& leftMotor, MotorController& rightMotor);
|
||||
DifferentialDrive(std::function<void(double)> leftMotor,
|
||||
std::function<void(double)> rightMotor);
|
||||
|
||||
~DifferentialDrive() override = default;
|
||||
|
||||
@@ -210,8 +198,12 @@ class DifferentialDrive : public RobotDriveBase,
|
||||
void InitSendable(wpi::SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
MotorController* m_leftMotor;
|
||||
MotorController* m_rightMotor;
|
||||
std::function<void(double)> m_leftMotor;
|
||||
std::function<void(double)> m_rightMotor;
|
||||
|
||||
// Used for Sendable property getters
|
||||
double m_leftOutput = 0.0;
|
||||
double m_rightOutput = 0.0;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -4,10 +4,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <units/angle.h>
|
||||
#include <wpi/deprecated.h>
|
||||
#include <wpi/sendable/Sendable.h>
|
||||
#include <wpi/sendable/SendableHelper.h>
|
||||
|
||||
@@ -69,15 +71,39 @@ class MecanumDrive : public RobotDriveBase,
|
||||
double rearRight = 0.0;
|
||||
};
|
||||
|
||||
WPI_IGNORE_DEPRECATED
|
||||
|
||||
/**
|
||||
* Construct a MecanumDrive.
|
||||
*
|
||||
* If a motor needs to be inverted, do so before passing it in.
|
||||
*
|
||||
* @param frontLeftMotor Front-left motor.
|
||||
* @param rearLeftMotor Rear-left motor.
|
||||
* @param frontRightMotor Front-right motor.
|
||||
* @param rearRightMotor Rear-right motor.
|
||||
*/
|
||||
MecanumDrive(MotorController& frontLeftMotor, MotorController& rearLeftMotor,
|
||||
MotorController& frontRightMotor,
|
||||
MotorController& rearRightMotor);
|
||||
|
||||
WPI_UNIGNORE_DEPRECATED
|
||||
|
||||
/**
|
||||
* Construct a MecanumDrive.
|
||||
*
|
||||
* If a motor needs to be inverted, do so before passing it in.
|
||||
*
|
||||
* @param frontLeftMotor Front-left motor setter.
|
||||
* @param rearLeftMotor Rear-left motor setter.
|
||||
* @param frontRightMotor Front-right motor setter.
|
||||
* @param rearRightMotor Rear-right motor setter.
|
||||
*/
|
||||
MecanumDrive(std::function<void(double)> frontLeftMotor,
|
||||
std::function<void(double)> rearLeftMotor,
|
||||
std::function<void(double)> frontRightMotor,
|
||||
std::function<void(double)> rearRightMotor);
|
||||
|
||||
~MecanumDrive() override = default;
|
||||
|
||||
MecanumDrive(MecanumDrive&&) = default;
|
||||
@@ -141,10 +167,16 @@ class MecanumDrive : public RobotDriveBase,
|
||||
void InitSendable(wpi::SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
MotorController* m_frontLeftMotor;
|
||||
MotorController* m_rearLeftMotor;
|
||||
MotorController* m_frontRightMotor;
|
||||
MotorController* m_rearRightMotor;
|
||||
std::function<void(double)> m_frontLeftMotor;
|
||||
std::function<void(double)> m_rearLeftMotor;
|
||||
std::function<void(double)> m_frontRightMotor;
|
||||
std::function<void(double)> m_rearRightMotor;
|
||||
|
||||
// Used for Sendable property getters
|
||||
double m_frontLeftOutput = 0.0;
|
||||
double m_rearLeftOutput = 0.0;
|
||||
double m_frontRightOutput = 0.0;
|
||||
double m_rearRightOutput = 0.0;
|
||||
|
||||
bool reported = false;
|
||||
};
|
||||
|
||||
@@ -7,19 +7,25 @@
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/deprecated.h>
|
||||
#include <wpi/sendable/Sendable.h>
|
||||
#include <wpi/sendable/SendableHelper.h>
|
||||
|
||||
#include "frc/motorcontrol/MotorController.h"
|
||||
|
||||
WPI_IGNORE_DEPRECATED
|
||||
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
* Allows multiple MotorController objects to be linked together.
|
||||
*/
|
||||
class MotorControllerGroup : public wpi::Sendable,
|
||||
public MotorController,
|
||||
public wpi::SendableHelper<MotorControllerGroup> {
|
||||
class [[deprecated(
|
||||
"Use CAN motor controller followers or "
|
||||
"PWMMotorController::AddFollower()")]] MotorControllerGroup
|
||||
: public wpi::Sendable,
|
||||
public MotorController,
|
||||
public wpi::SendableHelper<MotorControllerGroup> {
|
||||
public:
|
||||
template <class... MotorControllers>
|
||||
explicit MotorControllerGroup(MotorController& motorController,
|
||||
@@ -50,3 +56,5 @@ class MotorControllerGroup : public wpi::Sendable,
|
||||
} // namespace frc
|
||||
|
||||
#include "frc/motorcontrol/MotorControllerGroup.inc"
|
||||
|
||||
WPI_UNIGNORE_DEPRECATED
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <wpi/deprecated.h>
|
||||
#include <wpi/sendable/Sendable.h>
|
||||
#include <wpi/sendable/SendableHelper.h>
|
||||
|
||||
@@ -16,6 +17,8 @@
|
||||
|
||||
namespace frc {
|
||||
|
||||
WPI_IGNORE_DEPRECATED
|
||||
|
||||
/**
|
||||
* Nidec Brushless Motor.
|
||||
*/
|
||||
@@ -95,4 +98,6 @@ class NidecBrushless : public MotorController,
|
||||
double m_speed = 0.0;
|
||||
};
|
||||
|
||||
WPI_UNIGNORE_DEPRECATED
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -4,9 +4,16 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <concepts>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <units/voltage.h>
|
||||
#include <wpi/deprecated.h>
|
||||
#include <wpi/sendable/Sendable.h>
|
||||
#include <wpi/sendable/SendableHelper.h>
|
||||
|
||||
@@ -17,6 +24,8 @@
|
||||
namespace frc {
|
||||
class DMA;
|
||||
|
||||
WPI_IGNORE_DEPRECATED
|
||||
|
||||
/**
|
||||
* Common base class for all PWM Motor Controllers.
|
||||
*/
|
||||
@@ -40,6 +49,20 @@ class PWMMotorController : public MotorController,
|
||||
*/
|
||||
void Set(double value) override;
|
||||
|
||||
/**
|
||||
* Sets the voltage output of the PWMMotorController. Compensates for
|
||||
* the current bus voltage to ensure that the desired voltage is output even
|
||||
* if the battery voltage is below 12V - highly useful when the voltage
|
||||
* outputs are "meaningful" (e.g. they come from a feedforward calculation).
|
||||
*
|
||||
* <p>NOTE: This function *must* be called regularly in order for voltage
|
||||
* compensation to work properly - unlike the ordinary set function, it is not
|
||||
* "set it and forget it."
|
||||
*
|
||||
* @param output The voltage to output.
|
||||
*/
|
||||
void SetVoltage(units::volt_t output) override;
|
||||
|
||||
/**
|
||||
* Get the recently set value of the PWM. This value is affected by the
|
||||
* inversion property. If you want the value that is sent directly to the
|
||||
@@ -71,6 +94,24 @@ class PWMMotorController : public MotorController,
|
||||
*/
|
||||
void EnableDeadbandElimination(bool eliminateDeadband);
|
||||
|
||||
/**
|
||||
* Make the given PWM motor controller follow the output of this one.
|
||||
*
|
||||
* @param follower The motor controller follower.
|
||||
*/
|
||||
void AddFollower(PWMMotorController& follower);
|
||||
|
||||
/**
|
||||
* Make the given PWM motor controller follow the output of this one.
|
||||
*
|
||||
* @param follower The motor controller follower.
|
||||
*/
|
||||
template <std::derived_from<PWMMotorController> T>
|
||||
void AddFollower(T&& follower) {
|
||||
m_owningFollowers.emplace_back(
|
||||
std::make_unique<std::decay_t<T>>(std::forward<T>(follower)));
|
||||
}
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Constructor for a PWM Motor %Controller connected via PWM.
|
||||
@@ -87,8 +128,12 @@ class PWMMotorController : public MotorController,
|
||||
|
||||
private:
|
||||
bool m_isInverted = false;
|
||||
std::vector<PWMMotorController*> m_nonowningFollowers;
|
||||
std::vector<std::unique_ptr<PWMMotorController>> m_owningFollowers;
|
||||
|
||||
PWM* GetPwm() { return &m_pwm; }
|
||||
};
|
||||
|
||||
WPI_UNIGNORE_DEPRECATED
|
||||
|
||||
} // namespace frc
|
||||
|
||||
Reference in New Issue
Block a user