[wpilib] Rename MotorController setDutyCycle() to setThrottle() (#8720)

Fixes #8716.
This commit is contained in:
Tyler Veness
2026-04-09 22:28:01 -07:00
committed by GitHub
parent a4e035ba64
commit b6849a8da3
160 changed files with 659 additions and 706 deletions

View File

@@ -13,7 +13,7 @@ using namespace wpi;
{{ name }}::{{ name }}(int channel) : PWMMotorController("{{ name }}", channel) {
SetBounds({{ pulse_width_ms.max }}_ms, {{ pulse_width_ms.deadbandMax }}_ms, {{ pulse_width_ms.center }}_ms, {{ pulse_width_ms.deadbandMin }}_ms, {{ pulse_width_ms.min }}_ms);
m_pwm.SetOutputPeriod({{ OutputPeriod | default("5", true)}}_ms);
SetDutyCycle(0.0);
SetThrottle(0.0);
HAL_ReportUsage("IO", GetChannel(), "{{ ResourceName }}");
}

View File

@@ -13,7 +13,7 @@ using namespace wpi;
Koors40::Koors40(int channel) : PWMMotorController("Koors40", channel) {
SetBounds(2.004_ms, 1.52_ms, 1.5_ms, 1.48_ms, 0.997_ms);
m_pwm.SetOutputPeriod(20_ms);
SetDutyCycle(0.0);
SetThrottle(0.0);
HAL_ReportUsage("IO", GetChannel(), "Koors40");
}

View File

@@ -13,7 +13,7 @@ using namespace wpi;
PWMSparkFlex::PWMSparkFlex(int channel) : PWMMotorController("PWMSparkFlex", channel) {
SetBounds(2.003_ms, 1.55_ms, 1.5_ms, 1.46_ms, 0.999_ms);
m_pwm.SetOutputPeriod(5_ms);
SetDutyCycle(0.0);
SetThrottle(0.0);
HAL_ReportUsage("IO", GetChannel(), "RevSparkFlexPWM");
}

View File

@@ -13,7 +13,7 @@ using namespace wpi;
PWMSparkMax::PWMSparkMax(int channel) : PWMMotorController("PWMSparkMax", channel) {
SetBounds(2.003_ms, 1.55_ms, 1.5_ms, 1.46_ms, 0.999_ms);
m_pwm.SetOutputPeriod(5_ms);
SetDutyCycle(0.0);
SetThrottle(0.0);
HAL_ReportUsage("IO", GetChannel(), "RevSparkMaxPWM");
}

View File

@@ -13,7 +13,7 @@ using namespace wpi;
PWMTalonFX::PWMTalonFX(int channel) : PWMMotorController("PWMTalonFX", channel) {
SetBounds(2.004_ms, 1.52_ms, 1.5_ms, 1.48_ms, 0.997_ms);
m_pwm.SetOutputPeriod(5_ms);
SetDutyCycle(0.0);
SetThrottle(0.0);
HAL_ReportUsage("IO", GetChannel(), "TalonFX");
}

View File

@@ -13,7 +13,7 @@ using namespace wpi;
PWMTalonSRX::PWMTalonSRX(int channel) : PWMMotorController("PWMTalonSRX", channel) {
SetBounds(2.004_ms, 1.52_ms, 1.5_ms, 1.48_ms, 0.997_ms);
m_pwm.SetOutputPeriod(5_ms);
SetDutyCycle(0.0);
SetThrottle(0.0);
HAL_ReportUsage("IO", GetChannel(), "PWMTalonSRX");
}

View File

@@ -13,7 +13,7 @@ using namespace wpi;
PWMVenom::PWMVenom(int channel) : PWMMotorController("PWMVenom", channel) {
SetBounds(2.004_ms, 1.52_ms, 1.5_ms, 1.48_ms, 0.997_ms);
m_pwm.SetOutputPeriod(5_ms);
SetDutyCycle(0.0);
SetThrottle(0.0);
HAL_ReportUsage("IO", GetChannel(), "FusionVenom");
}

View File

@@ -13,7 +13,7 @@ using namespace wpi;
PWMVictorSPX::PWMVictorSPX(int channel) : PWMMotorController("PWMVictorSPX", channel) {
SetBounds(2.004_ms, 1.52_ms, 1.5_ms, 1.48_ms, 0.997_ms);
m_pwm.SetOutputPeriod(5_ms);
SetDutyCycle(0.0);
SetThrottle(0.0);
HAL_ReportUsage("IO", GetChannel(), "PWMVictorSPX");
}

View File

@@ -13,7 +13,7 @@ using namespace wpi;
Spark::Spark(int channel) : PWMMotorController("Spark", channel) {
SetBounds(2.003_ms, 1.55_ms, 1.5_ms, 1.46_ms, 0.999_ms);
m_pwm.SetOutputPeriod(5_ms);
SetDutyCycle(0.0);
SetThrottle(0.0);
HAL_ReportUsage("IO", GetChannel(), "RevSPARK");
}

View File

@@ -13,7 +13,7 @@ using namespace wpi;
SparkMini::SparkMini(int channel) : PWMMotorController("SparkMini", channel) {
SetBounds(2.5_ms, 1.51_ms, 1.5_ms, 1.49_ms, 0.5_ms);
m_pwm.SetOutputPeriod(5_ms);
SetDutyCycle(0.0);
SetThrottle(0.0);
HAL_ReportUsage("IO", GetChannel(), "RevSPARK");
}

View File

@@ -13,7 +13,7 @@ using namespace wpi;
Talon::Talon(int channel) : PWMMotorController("Talon", channel) {
SetBounds(2.037_ms, 1.539_ms, 1.513_ms, 1.487_ms, 0.989_ms);
m_pwm.SetOutputPeriod(5_ms);
SetDutyCycle(0.0);
SetThrottle(0.0);
HAL_ReportUsage("IO", GetChannel(), "Talon");
}

View File

@@ -13,7 +13,7 @@ using namespace wpi;
VictorSP::VictorSP(int channel) : PWMMotorController("VictorSP", channel) {
SetBounds(2.004_ms, 1.52_ms, 1.5_ms, 1.48_ms, 0.997_ms);
m_pwm.SetOutputPeriod(5_ms);
SetDutyCycle(0.0);
SetThrottle(0.0);
HAL_ReportUsage("IO", GetChannel(), "VictorSP");
}

View File

@@ -17,19 +17,15 @@
using namespace wpi;
WPI_IGNORE_DEPRECATED
DifferentialDrive::DifferentialDrive(MotorController& leftMotor,
MotorController& rightMotor)
: DifferentialDrive{
[&](double output) { leftMotor.SetDutyCycle(output); },
[&](double output) { rightMotor.SetDutyCycle(output); }} {
[&](double output) { leftMotor.SetThrottle(output); },
[&](double output) { rightMotor.SetThrottle(output); }} {
wpi::util::SendableRegistry::AddChild(this, &leftMotor);
wpi::util::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)} {

View File

@@ -17,25 +17,20 @@
using namespace wpi;
WPI_IGNORE_DEPRECATED
MecanumDrive::MecanumDrive(MotorController& frontLeftMotor,
MotorController& rearLeftMotor,
MotorController& frontRightMotor,
MotorController& rearRightMotor)
: MecanumDrive{
[&](double output) { frontLeftMotor.SetDutyCycle(output); },
[&](double output) { rearLeftMotor.SetDutyCycle(output); },
[&](double output) { frontRightMotor.SetDutyCycle(output); },
[&](double output) { rearRightMotor.SetDutyCycle(output); }} {
: MecanumDrive{[&](double output) { frontLeftMotor.SetThrottle(output); },
[&](double output) { rearLeftMotor.SetThrottle(output); },
[&](double output) { frontRightMotor.SetThrottle(output); },
[&](double output) { rearRightMotor.SetThrottle(output); }} {
wpi::util::SendableRegistry::AddChild(this, &frontLeftMotor);
wpi::util::SendableRegistry::AddChild(this, &rearLeftMotor);
wpi::util::SendableRegistry::AddChild(this, &frontRightMotor);
wpi::util::SendableRegistry::AddChild(this, &rearRightMotor);
}
WPI_UNIGNORE_DEPRECATED
MecanumDrive::MecanumDrive(std::function<void(double)> frontLeftMotor,
std::function<void(double)> rearLeftMotor,
std::function<void(double)> frontRightMotor,

View File

@@ -92,10 +92,10 @@ ExpansionHubMotor::~ExpansionHubMotor() noexcept {
m_hub.UnreserveMotor(m_channel);
}
void ExpansionHubMotor::SetDutyCycle(double dutyCycle) {
void ExpansionHubMotor::SetThrottle(double throttle) {
SetEnabled(true);
m_modePublisher.Set(kPercentageMode);
m_setpointPublisher.Set(dutyCycle);
m_setpointPublisher.Set(throttle);
}
void ExpansionHubMotor::SetVoltage(wpi::units::volt_t voltage) {

View File

@@ -10,5 +10,5 @@ using namespace wpi;
void MotorController::SetVoltage(wpi::units::volt_t voltage) {
// NOLINTNEXTLINE(bugprone-integer-division)
SetDutyCycle(voltage / RobotController::GetBatteryVoltage());
SetThrottle(voltage / RobotController::GetBatteryVoltage());
}

View File

@@ -14,28 +14,28 @@
using namespace wpi;
void PWMMotorController::SetDutyCycle(double dutyCycle) {
void PWMMotorController::SetThrottle(double throttle) {
if (m_isInverted) {
dutyCycle = -dutyCycle;
throttle = -throttle;
}
SetDutyCycleInternal(dutyCycle);
SetDutyCycleInternal(throttle);
for (auto& follower : m_nonowningFollowers) {
follower->SetDutyCycle(dutyCycle);
follower->SetThrottle(throttle);
}
for (auto& follower : m_owningFollowers) {
follower->SetDutyCycle(dutyCycle);
follower->SetThrottle(throttle);
}
Feed();
}
double PWMMotorController::GetDutyCycle() const {
double PWMMotorController::GetThrottle() const {
return GetDutyCycleInternal() * (m_isInverted ? -1.0 : 1.0);
}
wpi::units::volt_t PWMMotorController::GetVoltage() const {
return GetDutyCycle() * RobotController::GetBatteryVoltage();
return GetThrottle() * RobotController::GetBatteryVoltage();
}
void PWMMotorController::SetInverted(bool isInverted) {
@@ -49,8 +49,8 @@ bool PWMMotorController::GetInverted() const {
void PWMMotorController::Disable() {
m_pwm.SetDisabled();
if (m_simDutyCycle) {
m_simDutyCycle.Set(0.0);
if (m_simThrottle) {
m_simThrottle.Set(0.0);
}
for (auto& follower : m_nonowningFollowers) {
@@ -81,28 +81,24 @@ 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::util::SendableRegistry::Add(this, name, channel);
m_simDevice = wpi::hal::SimDevice{"PWMMotorController", channel};
if (m_simDevice) {
m_simDutyCycle = m_simDevice.CreateDouble(
"DutyCycle", wpi::hal::SimDevice::Direction::OUTPUT, 0.0);
m_simThrottle = m_simDevice.CreateDouble(
"Throttle", wpi::hal::SimDevice::Direction::OUTPUT, 0.0);
m_pwm.SetSimDevice(m_simDevice);
}
}
WPI_UNIGNORE_DEPRECATED
void PWMMotorController::InitSendable(wpi::util::SendableBuilder& builder) {
builder.SetSmartDashboardType("Motor Controller");
builder.SetActuator(true);
builder.AddDoubleProperty(
"Value", [=, this] { return GetDutyCycle(); },
[=, this](double value) { SetDutyCycle(value); });
"Value", [=, this] { return GetThrottle(); },
[=, this](double value) { SetThrottle(value); });
}
wpi::units::microsecond_t PWMMotorController::GetMinPositivePwm() const {
@@ -136,8 +132,8 @@ void PWMMotorController::SetDutyCycleInternal(double dutyCycle) {
dutyCycle = 0.0;
}
if (m_simDutyCycle) {
m_simDutyCycle.Set(dutyCycle);
if (m_simThrottle) {
m_simThrottle.Set(dutyCycle);
}
wpi::units::microsecond_t rawValue;

View File

@@ -16,9 +16,9 @@ PWMMotorControllerSim::PWMMotorControllerSim(
PWMMotorControllerSim::PWMMotorControllerSim(int channel) {
wpi::sim::SimDeviceSim deviceSim{"PWMMotorController", channel};
m_simDutyCycle = deviceSim.GetDouble("DutyCycle");
m_simThrottle = deviceSim.GetDouble("Throttle");
}
double PWMMotorControllerSim::GetDutyCycle() const {
return m_simDutyCycle.Get();
double PWMMotorControllerSim::GetThrottle() const {
return m_simThrottle.Get();
}

View File

@@ -8,7 +8,6 @@
#include <string>
#include "wpi/drive/RobotDriveBase.hpp"
#include "wpi/util/deprecated.hpp"
#include "wpi/util/sendable/Sendable.hpp"
#include "wpi/util/sendable/SendableHelper.hpp"
@@ -70,8 +69,6 @@ class DifferentialDrive : public RobotDriveBase,
double right = 0.0;
};
WPI_IGNORE_DEPRECATED
/**
* Construct a DifferentialDrive.
*
@@ -84,8 +81,6 @@ class DifferentialDrive : public RobotDriveBase,
*/
DifferentialDrive(MotorController& leftMotor, MotorController& rightMotor);
WPI_UNIGNORE_DEPRECATED
/**
* Construct a DifferentialDrive.
*

View File

@@ -5,13 +5,11 @@
#pragma once
#include <functional>
#include <memory>
#include <string>
#include "wpi/drive/RobotDriveBase.hpp"
#include "wpi/math/geometry/Rotation2d.hpp"
#include "wpi/units/angle.hpp"
#include "wpi/util/deprecated.hpp"
#include "wpi/util/sendable/Sendable.hpp"
#include "wpi/util/sendable/SendableHelper.hpp"
@@ -71,8 +69,6 @@ class MecanumDrive : public RobotDriveBase,
double rearRight = 0.0;
};
WPI_IGNORE_DEPRECATED
/**
* Construct a MecanumDrive.
*
@@ -87,8 +83,6 @@ class MecanumDrive : public RobotDriveBase,
MotorController& frontRightMotor,
MotorController& rearRightMotor);
WPI_UNIGNORE_DEPRECATED
/**
* Construct a MecanumDrive.
*

View File

@@ -4,7 +4,6 @@
#pragma once
#include <memory>
#include <span>
#include <string>

View File

@@ -4,16 +4,12 @@
#pragma once
#include <memory>
#include "wpi/hardware/expansionhub/ExpansionHub.hpp"
#include "wpi/hardware/expansionhub/ExpansionHubPidConstants.hpp"
#include "wpi/nt/BooleanTopic.hpp"
#include "wpi/nt/DoubleTopic.hpp"
#include "wpi/nt/IntegerTopic.hpp"
#include "wpi/units/angle.hpp"
#include "wpi/units/current.hpp"
#include "wpi/units/time.hpp"
#include "wpi/units/voltage.hpp"
namespace wpi {
@@ -33,12 +29,12 @@ class ExpansionHubMotor {
~ExpansionHubMotor() noexcept;
/**
* Sets the duty cycle.
* Sets the throttle.
*
* @param dutyCycle The duty cycle between -1 and 1 (sign indicates
* direction).
* @param throttle The throttle where -1 indicates full reverse and 1
* indicates full forward.
*/
void SetDutyCycle(double dutyCycle);
void SetThrottle(double throttle);
/**
* Sets the voltage to run the motor at. This value will be continously scaled

View File

@@ -16,12 +16,12 @@ class MotorController {
virtual ~MotorController() = default;
/**
* Sets the duty cycle of the motor controller.
* Sets the throttle of the motor controller.
*
* @param dutyCycle The duty cycle between -1 and 1 (sign indicates
* direction).
* @param throttle The throttle where -1 indicates full reverse and 1
* indicates full forward.
*/
virtual void SetDutyCycle(double dutyCycle) = 0;
virtual void SetThrottle(double throttle) = 0;
/**
* Sets the voltage output of the motor controller.
@@ -40,11 +40,12 @@ class MotorController {
virtual void SetVoltage(wpi::units::volt_t voltage);
/**
* Gets the duty cycle of the motor controller.
* Gets the throttle of the motor controller.
*
* @return The duty cycle between -1 and 1 (sign indicates direction).
* @return The throttle where -1 represents full reverse and 1 represents full
* forward.
*/
virtual double GetDutyCycle() const = 0;
virtual double GetThrottle() const = 0;
/**
* Sets the inversion state of the motor controller.

View File

@@ -17,14 +17,11 @@
#include "wpi/hardware/motor/MotorController.hpp"
#include "wpi/hardware/motor/MotorSafety.hpp"
#include "wpi/units/voltage.hpp"
#include "wpi/util/deprecated.hpp"
#include "wpi/util/sendable/Sendable.hpp"
#include "wpi/util/sendable/SendableHelper.hpp"
namespace wpi {
WPI_IGNORE_DEPRECATED
/**
* Common base class for all PWM Motor Controllers.
*/
@@ -37,9 +34,9 @@ class PWMMotorController
PWMMotorController(PWMMotorController&&) = default;
PWMMotorController& operator=(PWMMotorController&&) = default;
void SetDutyCycle(double dutyCycle) override;
void SetThrottle(double throttle) override;
double GetDutyCycle() const override;
double GetThrottle() const override;
/**
* Gets the voltage output of the motor controller, nominally between -12 V
@@ -119,7 +116,7 @@ class PWMMotorController
std::vector<std::unique_ptr<PWMMotorController>> m_owningFollowers;
wpi::hal::SimDevice m_simDevice;
wpi::hal::SimDouble m_simDutyCycle;
wpi::hal::SimDouble m_simThrottle;
bool m_eliminateDeadband{0};
wpi::units::microsecond_t m_minPwm{0};
@@ -136,6 +133,4 @@ class PWMMotorController
PWM* GetPwm() { return &m_pwm; }
};
WPI_UNIGNORE_DEPRECATED
} // namespace wpi

View File

@@ -19,10 +19,10 @@ class PWMMotorControllerSim {
explicit PWMMotorControllerSim(int channel);
double GetDutyCycle() const;
double GetThrottle() const;
private:
wpi::hal::SimDouble m_simDutyCycle;
wpi::hal::SimDouble m_simThrottle;
};
} // namespace sim
} // namespace wpi

View File

@@ -2,7 +2,7 @@ classes:
wpi::ExpansionHubMotor:
methods:
ExpansionHubMotor:
SetDutyCycle:
SetThrottle:
SetVoltage:
SetPositionSetpoint:
SetVelocitySetpoint:

View File

@@ -1,9 +1,9 @@
classes:
wpi::MotorController:
methods:
SetDutyCycle:
SetThrottle:
SetVoltage:
GetDutyCycle:
GetThrottle:
SetInverted:
GetInverted:
Disable:

View File

@@ -33,9 +33,9 @@ classes:
param_override:
args:
ignore: true
SetDutyCycle:
SetThrottle:
SetVoltage:
GetDutyCycle:
GetThrottle:
SetInverted:
GetInverted:
Disable:

View File

@@ -8,8 +8,8 @@ classes:
attributes:
m_pwm:
methods:
SetDutyCycle:
GetDutyCycle:
SetThrottle:
GetThrottle:
GetVoltage:
SetInverted:
GetInverted:

View File

@@ -5,4 +5,4 @@ classes:
overloads:
const PWMMotorController&:
int:
GetDutyCycle:
GetThrottle:

View File

@@ -17,9 +17,9 @@ void PyMotorControllerGroup::Initialize() {
wpi::util::SendableRegistry::Add(this, "MotorControllerGroup", instances);
}
void PyMotorControllerGroup::SetDutyCycle(double dutyCycle) {
void PyMotorControllerGroup::SetThrottle(double throttle) {
for (auto motorController : m_motorControllers) {
motorController->SetDutyCycle(m_isInverted ? -dutyCycle : dutyCycle);
motorController->SetThrottle(m_isInverted ? -throttle : throttle);
}
}
@@ -29,9 +29,9 @@ void PyMotorControllerGroup::SetVoltage(wpi::units::volt_t voltage) {
}
}
double PyMotorControllerGroup::GetDutyCycle() const {
double PyMotorControllerGroup::GetThrottle() const {
if (!m_motorControllers.empty()) {
return m_motorControllers.front()->GetDutyCycle() * (m_isInverted ? -1 : 1);
return m_motorControllers.front()->GetThrottle() * (m_isInverted ? -1 : 1);
}
return 0.0;
}
@@ -51,6 +51,6 @@ void PyMotorControllerGroup::Disable() {
void PyMotorControllerGroup::InitSendable(wpi::util::SendableBuilder& builder) {
builder.SetSmartDashboardType("Motor Controller");
builder.SetActuator(true);
builder.AddDoubleProperty("Value", [=, this]() { return GetDutyCycle(); },
[=, this](double value) { SetDutyCycle(value); });
builder.AddDoubleProperty("Value", [=, this]() { return GetThrottle(); },
[=, this](double value) { SetThrottle(value); });
}

View File

@@ -26,9 +26,9 @@ class PyMotorControllerGroup : public wpi::util::Sendable,
PyMotorControllerGroup(PyMotorControllerGroup&&) = default;
PyMotorControllerGroup& operator=(PyMotorControllerGroup&&) = default;
void SetDutyCycle(double dutyCycle) override;
void SetThrottle(double throttle) override;
void SetVoltage(wpi::units::volt_t voltage) override;
double GetDutyCycle() const override;
double GetThrottle() const override;
void SetInverted(bool isInverted) override;
bool GetInverted() const override;
void Disable() override;

View File

@@ -244,232 +244,232 @@ TEST(DifferentialDriveTest, ArcadeDrive) {
wpi::MockPWMMotorController left;
wpi::MockPWMMotorController right;
wpi::DifferentialDrive drive{
[&](double output) { left.SetDutyCycle(output); },
[&](double output) { right.SetDutyCycle(output); }};
[&](double output) { left.SetThrottle(output); },
[&](double output) { right.SetThrottle(output); }};
drive.SetDeadband(0.0);
// Forward
drive.ArcadeDrive(1.0, 0.0, false);
EXPECT_DOUBLE_EQ(1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, right.GetThrottle());
// Forward left turn
drive.ArcadeDrive(0.5, 0.5, false);
EXPECT_DOUBLE_EQ(0.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.5, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(0.5, right.GetThrottle());
// Forward right turn
drive.ArcadeDrive(0.5, -0.5, false);
EXPECT_DOUBLE_EQ(0.5, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.5, left.GetThrottle());
EXPECT_DOUBLE_EQ(0.0, right.GetThrottle());
// Backward
drive.ArcadeDrive(-1.0, 0.0, false);
EXPECT_DOUBLE_EQ(-1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, right.GetThrottle());
// Backward left turn
drive.ArcadeDrive(-0.5, 0.5, false);
EXPECT_DOUBLE_EQ(-0.5, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(-0.5, left.GetThrottle());
EXPECT_DOUBLE_EQ(0.0, right.GetThrottle());
// Backward right turn
drive.ArcadeDrive(-0.5, -0.5, false);
EXPECT_DOUBLE_EQ(0.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(-0.5, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(-0.5, right.GetThrottle());
}
TEST(DifferentialDriveTest, ArcadeDriveSquared) {
wpi::MockPWMMotorController left;
wpi::MockPWMMotorController right;
wpi::DifferentialDrive drive{
[&](double output) { left.SetDutyCycle(output); },
[&](double output) { right.SetDutyCycle(output); }};
[&](double output) { left.SetThrottle(output); },
[&](double output) { right.SetThrottle(output); }};
drive.SetDeadband(0.0);
// Forward
drive.ArcadeDrive(1.0, 0.0, true);
EXPECT_DOUBLE_EQ(1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, right.GetThrottle());
// Forward left turn
drive.ArcadeDrive(0.5, 0.5, true);
EXPECT_DOUBLE_EQ(0.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.25, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(0.25, right.GetThrottle());
// Forward right turn
drive.ArcadeDrive(0.5, -0.5, true);
EXPECT_DOUBLE_EQ(0.25, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.25, left.GetThrottle());
EXPECT_DOUBLE_EQ(0.0, right.GetThrottle());
// Backward
drive.ArcadeDrive(-1.0, 0.0, true);
EXPECT_DOUBLE_EQ(-1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, right.GetThrottle());
// Backward left turn
drive.ArcadeDrive(-0.5, 0.5, true);
EXPECT_DOUBLE_EQ(-0.25, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(-0.25, left.GetThrottle());
EXPECT_DOUBLE_EQ(0.0, right.GetThrottle());
// Backward right turn
drive.ArcadeDrive(-0.5, -0.5, true);
EXPECT_DOUBLE_EQ(0.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(-0.25, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(-0.25, right.GetThrottle());
}
TEST(DifferentialDriveTest, CurvatureDrive) {
wpi::MockPWMMotorController left;
wpi::MockPWMMotorController right;
wpi::DifferentialDrive drive{
[&](double output) { left.SetDutyCycle(output); },
[&](double output) { right.SetDutyCycle(output); }};
[&](double output) { left.SetThrottle(output); },
[&](double output) { right.SetThrottle(output); }};
drive.SetDeadband(0.0);
// Forward
drive.CurvatureDrive(1.0, 0.0, false);
EXPECT_DOUBLE_EQ(1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, right.GetThrottle());
// Forward left turn
drive.CurvatureDrive(0.5, 0.5, false);
EXPECT_DOUBLE_EQ(0.25, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.75, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.25, left.GetThrottle());
EXPECT_DOUBLE_EQ(0.75, right.GetThrottle());
// Forward right turn
drive.CurvatureDrive(0.5, -0.5, false);
EXPECT_DOUBLE_EQ(0.75, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.25, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.75, left.GetThrottle());
EXPECT_DOUBLE_EQ(0.25, right.GetThrottle());
// Backward
drive.CurvatureDrive(-1.0, 0.0, false);
EXPECT_DOUBLE_EQ(-1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, right.GetThrottle());
// Backward left turn
drive.CurvatureDrive(-0.5, 0.5, false);
EXPECT_DOUBLE_EQ(-0.75, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(-0.25, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(-0.75, left.GetThrottle());
EXPECT_DOUBLE_EQ(-0.25, right.GetThrottle());
// Backward right turn
drive.CurvatureDrive(-0.5, -0.5, false);
EXPECT_DOUBLE_EQ(-0.25, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(-0.75, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(-0.25, left.GetThrottle());
EXPECT_DOUBLE_EQ(-0.75, right.GetThrottle());
}
TEST(DifferentialDriveTest, CurvatureDriveTurnInPlace) {
wpi::MockPWMMotorController left;
wpi::MockPWMMotorController right;
wpi::DifferentialDrive drive{
[&](double output) { left.SetDutyCycle(output); },
[&](double output) { right.SetDutyCycle(output); }};
[&](double output) { left.SetThrottle(output); },
[&](double output) { right.SetThrottle(output); }};
drive.SetDeadband(0.0);
// Forward
drive.CurvatureDrive(1.0, 0.0, true);
EXPECT_DOUBLE_EQ(1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, right.GetThrottle());
// Forward left turn
drive.CurvatureDrive(0.5, 0.5, true);
EXPECT_DOUBLE_EQ(0.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, right.GetThrottle());
// Forward right turn
drive.CurvatureDrive(0.5, -0.5, true);
EXPECT_DOUBLE_EQ(1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(0.0, right.GetThrottle());
// Backward
drive.CurvatureDrive(-1.0, 0.0, true);
EXPECT_DOUBLE_EQ(-1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, right.GetThrottle());
// Backward left turn
drive.CurvatureDrive(-0.5, 0.5, true);
EXPECT_DOUBLE_EQ(-1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(0.0, right.GetThrottle());
// Backward right turn
drive.CurvatureDrive(-0.5, -0.5, true);
EXPECT_DOUBLE_EQ(0.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, right.GetThrottle());
}
TEST(DifferentialDriveTest, TankDrive) {
wpi::MockPWMMotorController left;
wpi::MockPWMMotorController right;
wpi::DifferentialDrive drive{
[&](double output) { left.SetDutyCycle(output); },
[&](double output) { right.SetDutyCycle(output); }};
[&](double output) { left.SetThrottle(output); },
[&](double output) { right.SetThrottle(output); }};
drive.SetDeadband(0.0);
// Forward
drive.TankDrive(1.0, 1.0, false);
EXPECT_DOUBLE_EQ(1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, right.GetThrottle());
// Forward left turn
drive.TankDrive(0.5, 1.0, false);
EXPECT_DOUBLE_EQ(0.5, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.5, left.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, right.GetThrottle());
// Forward right turn
drive.TankDrive(1.0, 0.5, false);
EXPECT_DOUBLE_EQ(1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.5, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(0.5, right.GetThrottle());
// Backward
drive.TankDrive(-1.0, -1.0, false);
EXPECT_DOUBLE_EQ(-1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, right.GetThrottle());
// Backward left turn
drive.TankDrive(-0.5, -1.0, false);
EXPECT_DOUBLE_EQ(-0.5, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(-0.5, left.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, right.GetThrottle());
// Backward right turn
drive.TankDrive(-0.5, 1.0, false);
EXPECT_DOUBLE_EQ(-0.5, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(-0.5, left.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, right.GetThrottle());
}
TEST(DifferentialDriveTest, TankDriveSquared) {
wpi::MockPWMMotorController left;
wpi::MockPWMMotorController right;
wpi::DifferentialDrive drive{
[&](double output) { left.SetDutyCycle(output); },
[&](double output) { right.SetDutyCycle(output); }};
[&](double output) { left.SetThrottle(output); },
[&](double output) { right.SetThrottle(output); }};
drive.SetDeadband(0.0);
// Forward
drive.TankDrive(1.0, 1.0, true);
EXPECT_DOUBLE_EQ(1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, right.GetThrottle());
// Forward left turn
drive.TankDrive(0.5, 1.0, true);
EXPECT_DOUBLE_EQ(0.25, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.25, left.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, right.GetThrottle());
// Forward right turn
drive.TankDrive(1.0, 0.5, true);
EXPECT_DOUBLE_EQ(1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.25, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(0.25, right.GetThrottle());
// Backward
drive.TankDrive(-1.0, -1.0, true);
EXPECT_DOUBLE_EQ(-1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, right.GetThrottle());
// Backward left turn
drive.TankDrive(-0.5, -1.0, true);
EXPECT_DOUBLE_EQ(-0.25, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(-0.25, left.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, right.GetThrottle());
// Backward right turn
drive.TankDrive(-1.0, -0.5, true);
EXPECT_DOUBLE_EQ(-1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(-0.25, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(-0.25, right.GetThrottle());
}

View File

@@ -87,46 +87,46 @@ TEST(MecanumDriveTest, Cartesian) {
wpi::MockPWMMotorController rl;
wpi::MockPWMMotorController fr;
wpi::MockPWMMotorController rr;
wpi::MecanumDrive drive{[&](double output) { fl.SetDutyCycle(output); },
[&](double output) { rl.SetDutyCycle(output); },
[&](double output) { fr.SetDutyCycle(output); },
[&](double output) { rr.SetDutyCycle(output); }};
wpi::MecanumDrive drive{[&](double output) { fl.SetThrottle(output); },
[&](double output) { rl.SetThrottle(output); },
[&](double output) { fr.SetThrottle(output); },
[&](double output) { rr.SetThrottle(output); }};
drive.SetDeadband(0.0);
// Forward
drive.DriveCartesian(1.0, 0.0, 0.0);
EXPECT_DOUBLE_EQ(1.0, fl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, fr.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rr.GetThrottle());
// Left
drive.DriveCartesian(0.0, -1.0, 0.0);
EXPECT_DOUBLE_EQ(-1.0, fl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rl.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, rr.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, fl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, fr.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rl.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, rr.GetThrottle());
// Right
drive.DriveCartesian(0.0, 1.0, 0.0);
EXPECT_DOUBLE_EQ(1.0, fl.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, fr.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, rl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fl.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, fr.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, rl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rr.GetThrottle());
// Rotate CCW
drive.DriveCartesian(0.0, 0.0, -1.0);
EXPECT_DOUBLE_EQ(-1.0, fl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fr.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, rl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rr.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, fl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, fr.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, rl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rr.GetThrottle());
// Rotate CW
drive.DriveCartesian(0.0, 0.0, 1.0);
EXPECT_DOUBLE_EQ(1.0, fl.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, fr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rl.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, rr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fl.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, fr.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rl.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, rr.GetThrottle());
}
TEST(MecanumDriveTest, CartesianGyro90CW) {
@@ -134,46 +134,46 @@ TEST(MecanumDriveTest, CartesianGyro90CW) {
wpi::MockPWMMotorController rl;
wpi::MockPWMMotorController fr;
wpi::MockPWMMotorController rr;
wpi::MecanumDrive drive{[&](double output) { fl.SetDutyCycle(output); },
[&](double output) { rl.SetDutyCycle(output); },
[&](double output) { fr.SetDutyCycle(output); },
[&](double output) { rr.SetDutyCycle(output); }};
wpi::MecanumDrive drive{[&](double output) { fl.SetThrottle(output); },
[&](double output) { rl.SetThrottle(output); },
[&](double output) { fr.SetThrottle(output); },
[&](double output) { rr.SetThrottle(output); }};
drive.SetDeadband(0.0);
// Forward in global frame; left in robot frame
drive.DriveCartesian(1.0, 0.0, 0.0, 90_deg);
EXPECT_DOUBLE_EQ(-1.0, fl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rl.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, rr.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, fl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, fr.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rl.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, rr.GetThrottle());
// Left in global frame; backward in robot frame
drive.DriveCartesian(0.0, -1.0, 0.0, 90_deg);
EXPECT_DOUBLE_EQ(-1.0, fl.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, fr.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, rl.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, rr.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, fl.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, fr.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, rl.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, rr.GetThrottle());
// Right in global frame; forward in robot frame
drive.DriveCartesian(0.0, 1.0, 0.0, 90_deg);
EXPECT_DOUBLE_EQ(1.0, fl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, fr.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rr.GetThrottle());
// Rotate CCW
drive.DriveCartesian(0.0, 0.0, -1.0, 90_deg);
EXPECT_DOUBLE_EQ(-1.0, fl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fr.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, rl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rr.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, fl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, fr.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, rl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rr.GetThrottle());
// Rotate CW
drive.DriveCartesian(0.0, 0.0, 1.0, 90_deg);
EXPECT_DOUBLE_EQ(1.0, fl.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, fr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rl.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, rr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fl.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, fr.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rl.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, rr.GetThrottle());
}
TEST(MecanumDriveTest, Polar) {
@@ -181,44 +181,44 @@ TEST(MecanumDriveTest, Polar) {
wpi::MockPWMMotorController rl;
wpi::MockPWMMotorController fr;
wpi::MockPWMMotorController rr;
wpi::MecanumDrive drive{[&](double output) { fl.SetDutyCycle(output); },
[&](double output) { rl.SetDutyCycle(output); },
[&](double output) { fr.SetDutyCycle(output); },
[&](double output) { rr.SetDutyCycle(output); }};
wpi::MecanumDrive drive{[&](double output) { fl.SetThrottle(output); },
[&](double output) { rl.SetThrottle(output); },
[&](double output) { fr.SetThrottle(output); },
[&](double output) { rr.SetThrottle(output); }};
drive.SetDeadband(0.0);
// Forward
drive.DrivePolar(1.0, 0_deg, 0.0);
EXPECT_DOUBLE_EQ(1.0, fl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, fr.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rr.GetThrottle());
// Left
drive.DrivePolar(1.0, -90_deg, 0.0);
EXPECT_DOUBLE_EQ(-1.0, fl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rl.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, rr.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, fl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, fr.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rl.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, rr.GetThrottle());
// Right
drive.DrivePolar(1.0, 90_deg, 0.0);
EXPECT_DOUBLE_EQ(1.0, fl.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, fr.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, rl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fl.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, fr.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, rl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rr.GetThrottle());
// Rotate CCW
drive.DrivePolar(0.0, 0_deg, -1.0);
EXPECT_DOUBLE_EQ(-1.0, fl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fr.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, rl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rr.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, fl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, fr.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, rl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rr.GetThrottle());
// Rotate CW
drive.DrivePolar(0.0, 0_deg, 1.0);
EXPECT_DOUBLE_EQ(1.0, fl.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, fr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rl.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, rr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fl.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, fr.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rl.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, rr.GetThrottle());
}

View File

@@ -6,12 +6,12 @@
using namespace wpi;
void MockMotorController::SetDutyCycle(double dutyCycle) {
m_dutyCycle = m_isInverted ? -dutyCycle : dutyCycle;
void MockMotorController::SetThrottle(double throttle) {
m_throttle = m_isInverted ? -throttle : throttle;
}
double MockMotorController::GetDutyCycle() const {
return m_dutyCycle;
double MockMotorController::GetThrottle() const {
return m_throttle;
}
void MockMotorController::SetInverted(bool isInverted) {
@@ -23,5 +23,5 @@ bool MockMotorController::GetInverted() const {
}
void MockMotorController::Disable() {
m_dutyCycle = 0;
m_throttle = 0;
}

View File

@@ -6,12 +6,12 @@
using namespace wpi;
void MockPWMMotorController::SetDutyCycle(double dutyCycle) {
m_dutyCycle = m_isInverted ? -dutyCycle : dutyCycle;
void MockPWMMotorController::SetThrottle(double throttle) {
m_throttle = m_isInverted ? -throttle : throttle;
}
double MockPWMMotorController::GetDutyCycle() const {
return m_dutyCycle;
double MockPWMMotorController::GetThrottle() const {
return m_throttle;
}
void MockPWMMotorController::SetInverted(bool isInverted) {
@@ -23,7 +23,7 @@ bool MockPWMMotorController::GetInverted() const {
}
void MockPWMMotorController::Disable() {
m_dutyCycle = 0;
m_throttle = 0;
}
void MockPWMMotorController::StopMotor() {

View File

@@ -37,7 +37,7 @@ TEST(DCMotorSimTest, VoltageSteadyState) {
// Then, SimulationPeriodic runs
wpi::sim::RoboRioSim::SetVInVoltage(
wpi::sim::BatterySim::Calculate({sim.GetCurrentDraw()}));
sim.SetInputVoltage(motor.GetDutyCycle() *
sim.SetInputVoltage(motor.GetThrottle() *
wpi::RobotController::GetBatteryVoltage());
sim.Update(20_ms);
encoderSim.SetRate(sim.GetAngularVelocity().value());
@@ -53,7 +53,7 @@ TEST(DCMotorSimTest, VoltageSteadyState) {
// Then, SimulationPeriodic runs
wpi::sim::RoboRioSim::SetVInVoltage(
wpi::sim::BatterySim::Calculate({sim.GetCurrentDraw()}));
sim.SetInputVoltage(motor.GetDutyCycle() *
sim.SetInputVoltage(motor.GetThrottle() *
wpi::RobotController::GetBatteryVoltage());
sim.Update(20_ms);
encoderSim.SetRate(sim.GetAngularVelocity().value());
@@ -80,12 +80,12 @@ TEST(DCMotorSimTest, PositionFeedbackControl) {
for (int i = 0; i < 140; i++) {
// RobotPeriodic runs first
motor.SetDutyCycle(controller.Calculate(encoder.GetDistance(), 750));
motor.SetThrottle(controller.Calculate(encoder.GetDistance(), 750));
// Then, SimulationPeriodic runs
wpi::sim::RoboRioSim::SetVInVoltage(
wpi::sim::BatterySim::Calculate({sim.GetCurrentDraw()}));
sim.SetInputVoltage(motor.GetDutyCycle() *
sim.SetInputVoltage(motor.GetThrottle() *
wpi::RobotController::GetBatteryVoltage());
sim.Update(20_ms);
encoderSim.SetDistance(sim.GetAngularPosition().value());

View File

@@ -30,9 +30,9 @@ TEST(ElevatorSimTest, StateSpaceSim) {
for (size_t i = 0; i < 100; ++i) {
controller.SetSetpoint(2.0);
auto nextVoltage = controller.Calculate(encoderSim.GetDistance());
motor.SetDutyCycle(nextVoltage / wpi::RobotController::GetInputVoltage());
motor.SetThrottle(nextVoltage / wpi::RobotController::GetInputVoltage());
wpi::math::Vectord<1> u{motor.GetDutyCycle() *
wpi::math::Vectord<1> u{motor.GetThrottle() *
wpi::RobotController::GetInputVoltage()};
sim.SetInput(u);
sim.Update(20_ms);

View File

@@ -15,13 +15,13 @@ TEST(PWMMotorControllerSimTest, TestMotor) {
wpi::Spark spark{0};
wpi::sim::PWMMotorControllerSim sim{spark};
spark.SetDutyCycle(0);
EXPECT_EQ(0, sim.GetDutyCycle());
spark.SetThrottle(0);
EXPECT_EQ(0, sim.GetThrottle());
spark.SetDutyCycle(0.354);
EXPECT_EQ(0.354, sim.GetDutyCycle());
spark.SetThrottle(0.354);
EXPECT_EQ(0.354, sim.GetThrottle());
spark.SetDutyCycle(-0.785);
EXPECT_EQ(-0.785, sim.GetDutyCycle());
spark.SetThrottle(-0.785);
EXPECT_EQ(-0.785, sim.GetThrottle());
}
} // namespace wpi::sim

View File

@@ -42,7 +42,7 @@ TEST(StateSpaceSimTest, FlywheelSim) {
wpi::sim::RoboRioSim::SetVInVoltage(
wpi::sim::BatterySim::Calculate({sim.GetCurrentDraw()}));
sim.SetInput(wpi::math::Vectord<1>{
motor.GetDutyCycle() * wpi::RobotController::GetInputVoltage()});
motor.GetThrottle() * wpi::RobotController::GetInputVoltage()});
sim.Update(20_ms);
encoderSim.SetRate(sim.GetAngularVelocity().value());
}

View File

@@ -5,25 +5,20 @@
#pragma once
#include "wpi/hardware/motor/MotorController.hpp"
#include "wpi/util/deprecated.hpp"
namespace wpi {
WPI_IGNORE_DEPRECATED
class MockMotorController : public MotorController {
public:
void SetDutyCycle(double dutyCycle) override;
double GetDutyCycle() const override;
void SetThrottle(double throttle) override;
double GetThrottle() const override;
void SetInverted(bool isInverted) override;
bool GetInverted() const override;
void Disable() override;
private:
double m_dutyCycle = 0.0;
double m_throttle = 0.0;
bool m_isInverted = false;
};
WPI_UNIGNORE_DEPRECATED
} // namespace wpi

View File

@@ -8,15 +8,15 @@ namespace wpi {
class MockPWMMotorController {
public:
void SetDutyCycle(double dutyCycle);
double GetDutyCycle() const;
void SetThrottle(double throttle);
double GetThrottle() const;
void SetInverted(bool isInverted);
bool GetInverted() const;
void Disable();
void StopMotor();
private:
double m_dutyCycle = 0.0;
double m_throttle = 0.0;
bool m_isInverted = false;
};

View File

@@ -27,13 +27,13 @@ def test_motorcontrollergroup():
t2 = wpilib.Talon(8)
g = wpilib.MotorControllerGroup(t1, t2)
g.setDutyCycle(1)
assert t1.getDutyCycle() == pytest.approx(1)
assert t2.getDutyCycle() == pytest.approx(1)
g.setThrottle(1)
assert t1.getThrottle() == pytest.approx(1)
assert t2.getThrottle() == pytest.approx(1)
g.setDutyCycle(-1)
assert t1.getDutyCycle() == pytest.approx(-1)
assert t2.getDutyCycle() == pytest.approx(-1)
g.setThrottle(-1)
assert t1.getThrottle() == pytest.approx(-1)
assert t2.getThrottle() == pytest.approx(-1)
def test_motorcontrollergroup_error():