[wpilib] Remove deprecated MotorControllerGroup (#8349)

This commit is contained in:
Charlotte
2025-11-09 13:31:26 -05:00
committed by GitHub
parent 4ea584b64f
commit 5636b8cd77
5 changed files with 0 additions and 505 deletions

View File

@@ -1,82 +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.
#include "wpi/hardware/motor/MotorControllerGroup.hpp"
#include <utility>
#include <vector>
#include "wpi/util/sendable/SendableBuilder.hpp"
#include "wpi/util/sendable/SendableRegistry.hpp"
using namespace wpi;
// 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)) {
Initialize();
}
void MotorControllerGroup::Initialize() {
for (auto& motorController : m_motorControllers) {
wpi::util::SendableRegistry::AddChild(this, &motorController.get());
}
static int instances = 0;
++instances;
wpi::util::SendableRegistry::Add(this, "MotorControllerGroup", instances);
}
void MotorControllerGroup::Set(double speed) {
for (auto motorController : m_motorControllers) {
motorController.get().Set(m_isInverted ? -speed : speed);
}
}
void MotorControllerGroup::SetVoltage(wpi::units::volt_t output) {
for (auto motorController : m_motorControllers) {
motorController.get().SetVoltage(m_isInverted ? -output : output);
}
}
double MotorControllerGroup::Get() const {
if (!m_motorControllers.empty()) {
return m_motorControllers.front().get().Get() * (m_isInverted ? -1 : 1);
}
return 0.0;
}
void MotorControllerGroup::SetInverted(bool isInverted) {
m_isInverted = isInverted;
}
bool MotorControllerGroup::GetInverted() const {
return m_isInverted;
}
void MotorControllerGroup::Disable() {
for (auto motorController : m_motorControllers) {
motorController.get().Disable();
}
}
void MotorControllerGroup::StopMotor() {
for (auto motorController : m_motorControllers) {
motorController.get().StopMotor();
}
}
void MotorControllerGroup::InitSendable(wpi::util::SendableBuilder& builder) {
builder.SetSmartDashboardType("Motor Controller");
builder.SetActuator(true);
builder.AddDoubleProperty(
"Value", [=, this] { return Get(); },
[=, this](double value) { Set(value); });
}
WPI_UNIGNORE_DEPRECATED

View File

@@ -1,74 +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.
#pragma once
#include <functional>
#include <vector>
#include "wpi/hardware/motor/MotorController.hpp"
#include "wpi/util/deprecated.hpp"
#include "wpi/util/sendable/Sendable.hpp"
#include "wpi/util/sendable/SendableHelper.hpp"
WPI_IGNORE_DEPRECATED
namespace wpi {
/**
* Allows multiple MotorController objects to be linked together.
*/
class [[deprecated(
"Use PWMMotorController::AddFollower() or if using CAN motor controllers,"
"use their method of following.")]] MotorControllerGroup
: public wpi::util::Sendable,
public MotorController,
public wpi::util::SendableHelper<MotorControllerGroup> {
public:
/**
* Create a new MotorControllerGroup with the provided MotorControllers.
*
* @tparam MotorControllers The MotorController types.
* @param motorController The first MotorController to add
* @param motorControllers The MotorControllers to add
*/
template <class... MotorControllers>
explicit MotorControllerGroup(MotorController& motorController,
MotorControllers&... motorControllers)
: m_motorControllers(std::vector<std::reference_wrapper<MotorController>>{
motorController, motorControllers...}) {
Initialize();
}
/**
* Create a new MotorControllerGroup with the provided MotorControllers.
*
* @param motorControllers The MotorControllers to add.
*/
explicit MotorControllerGroup(
std::vector<std::reference_wrapper<MotorController>>&& motorControllers);
MotorControllerGroup(MotorControllerGroup&&) = default;
MotorControllerGroup& operator=(MotorControllerGroup&&) = default;
void Set(double speed) override;
void SetVoltage(wpi::units::volt_t output) override;
double Get() const override;
void SetInverted(bool isInverted) override;
bool GetInverted() const override;
void Disable() override;
void StopMotor() override;
void InitSendable(wpi::util::SendableBuilder& builder) override;
private:
bool m_isInverted = false;
std::vector<std::reference_wrapper<MotorController>> m_motorControllers;
void Initialize();
};
} // namespace wpi
WPI_UNIGNORE_DEPRECATED

View File

@@ -1,131 +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.
#include "wpi/hardware/motor/MotorControllerGroup.hpp" // NOLINT(build/include_order)
#include <memory>
#include <vector>
#include <gtest/gtest.h>
#include "motorcontrol/MockMotorController.hpp"
#include "wpi/util/deprecated.hpp"
using namespace wpi;
enum MotorControllerGroupTestType { TEST_ONE, TEST_TWO, TEST_THREE };
std::ostream& operator<<(std::ostream& os,
const MotorControllerGroupTestType& type) {
switch (type) {
case TEST_ONE:
os << "MotorControllerGroup with one motor controller";
break;
case TEST_TWO:
os << "MotorControllerGroup with two motor controllers";
break;
case TEST_THREE:
os << "MotorControllerGroup with three motor controllers";
break;
}
return os;
}
WPI_IGNORE_DEPRECATED
/**
* A fixture used for MotorControllerGroup testing.
*/
class MotorControllerGroupTest
: public testing::TestWithParam<MotorControllerGroupTestType> {
protected:
std::vector<MockMotorController> m_motorControllers;
std::unique_ptr<MotorControllerGroup> m_group;
void SetUp() override {
switch (GetParam()) {
case TEST_ONE: {
m_motorControllers.emplace_back();
m_group = std::make_unique<MotorControllerGroup>(m_motorControllers[0]);
break;
}
case TEST_TWO: {
m_motorControllers.emplace_back();
m_motorControllers.emplace_back();
m_group = std::make_unique<MotorControllerGroup>(m_motorControllers[0],
m_motorControllers[1]);
break;
}
case TEST_THREE: {
m_motorControllers.emplace_back();
m_motorControllers.emplace_back();
m_motorControllers.emplace_back();
m_group = std::make_unique<MotorControllerGroup>(m_motorControllers[0],
m_motorControllers[1],
m_motorControllers[2]);
break;
}
}
}
};
TEST_P(MotorControllerGroupTest, Set) {
m_group->Set(1.0);
for (auto& motorController : m_motorControllers) {
EXPECT_FLOAT_EQ(motorController.Get(), 1.0);
}
}
TEST_P(MotorControllerGroupTest, GetInverted) {
m_group->SetInverted(true);
EXPECT_TRUE(m_group->GetInverted());
}
TEST_P(MotorControllerGroupTest, SetInvertedDoesNotModifyMotorControllers) {
for (auto& motorController : m_motorControllers) {
motorController.SetInverted(false);
}
m_group->SetInverted(true);
for (auto& motorController : m_motorControllers) {
EXPECT_EQ(motorController.GetInverted(), false);
}
}
TEST_P(MotorControllerGroupTest, SetInvertedDoesInvert) {
m_group->SetInverted(true);
m_group->Set(1.0);
for (auto& motorController : m_motorControllers) {
EXPECT_FLOAT_EQ(motorController.Get(), -1.0);
}
}
TEST_P(MotorControllerGroupTest, Disable) {
m_group->Set(1.0);
m_group->Disable();
for (auto& motorController : m_motorControllers) {
EXPECT_FLOAT_EQ(motorController.Get(), 0.0);
}
}
TEST_P(MotorControllerGroupTest, StopMotor) {
m_group->Set(1.0);
m_group->StopMotor();
for (auto& motorController : m_motorControllers) {
EXPECT_FLOAT_EQ(motorController.Get(), 0.0);
}
}
INSTANTIATE_TEST_SUITE_P(Tests, MotorControllerGroupTest,
testing::Values(TEST_ONE, TEST_TWO, TEST_THREE));
WPI_UNIGNORE_DEPRECATED

View File

@@ -1,116 +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 org.wpilib.hardware.motor;
import java.util.Arrays;
import org.wpilib.util.sendable.Sendable;
import org.wpilib.util.sendable.SendableBuilder;
import org.wpilib.util.sendable.SendableRegistry;
/**
* Allows multiple {@link MotorController} objects to be linked together.
*
* @deprecated Use {@link PWMMotorController#addFollower(PWMMotorController)} or if using CAN motor
* controllers, use their method of following.
*/
@SuppressWarnings("removal")
@Deprecated(forRemoval = true, since = "2024")
public class MotorControllerGroup implements MotorController, Sendable, AutoCloseable {
private boolean m_isInverted;
private final MotorController[] m_motorControllers;
private static int instances;
/**
* Create a new MotorControllerGroup with the provided MotorControllers.
*
* @param motorController The first MotorController to add
* @param motorControllers The MotorControllers to add
*/
@SuppressWarnings("this-escape")
public MotorControllerGroup(
MotorController motorController, MotorController... motorControllers) {
m_motorControllers = new MotorController[motorControllers.length + 1];
m_motorControllers[0] = motorController;
System.arraycopy(motorControllers, 0, m_motorControllers, 1, motorControllers.length);
init();
}
/**
* Create a new MotorControllerGroup with the provided MotorControllers.
*
* @param motorControllers The MotorControllers to add.
*/
@SuppressWarnings("this-escape")
public MotorControllerGroup(MotorController[] motorControllers) {
m_motorControllers = Arrays.copyOf(motorControllers, motorControllers.length);
init();
}
private void init() {
for (MotorController controller : m_motorControllers) {
SendableRegistry.addChild(this, controller);
}
instances++;
SendableRegistry.add(this, "MotorControllerGroup", instances);
}
@Override
public void close() {
SendableRegistry.remove(this);
}
@Override
public void set(double speed) {
for (MotorController motorController : m_motorControllers) {
motorController.set(m_isInverted ? -speed : speed);
}
}
@Override
public void setVoltage(double outputVolts) {
for (MotorController motorController : m_motorControllers) {
motorController.setVoltage(m_isInverted ? -outputVolts : outputVolts);
}
}
@Override
public double get() {
if (m_motorControllers.length > 0) {
return m_motorControllers[0].get() * (m_isInverted ? -1 : 1);
}
return 0.0;
}
@Override
public void setInverted(boolean isInverted) {
m_isInverted = isInverted;
}
@Override
public boolean getInverted() {
return m_isInverted;
}
@Override
public void disable() {
for (MotorController motorController : m_motorControllers) {
motorController.disable();
}
}
@Override
public void stopMotor() {
for (MotorController motorController : m_motorControllers) {
motorController.stopMotor();
}
}
@Override
public void initSendable(SendableBuilder builder) {
builder.setSmartDashboardType("Motor Controller");
builder.setActuator(true);
builder.addDoubleProperty("Value", this::get, this::set);
}
}

View File

@@ -1,102 +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 org.wpilib.hardware.motor;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Arrays;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
@SuppressWarnings("removal")
class MotorControllerGroupTest {
private static Stream<Arguments> motorControllerArguments() {
return IntStream.of(1, 2, 3)
.mapToObj(
number -> {
MotorController[] motorControllers =
Stream.generate(MockMotorController::new)
.limit(number)
.toArray(MotorController[]::new);
MotorControllerGroup group =
new MotorControllerGroup(
motorControllers[0],
Arrays.copyOfRange(motorControllers, 1, motorControllers.length));
return Arguments.of(group, motorControllers);
});
}
@ParameterizedTest
@MethodSource("motorControllerArguments")
void setTest(final MotorControllerGroup group, final MotorController[] motorControllers) {
group.set(1.0);
assertArrayEquals(
DoubleStream.generate(() -> 1.0).limit(motorControllers.length).toArray(),
Arrays.stream(motorControllers).mapToDouble(MotorController::get).toArray(),
0.00005);
}
@ParameterizedTest
@MethodSource("motorControllerArguments")
void getInvertedTest(final MotorControllerGroup group, final MotorController[] motorControllers) {
group.setInverted(true);
assertTrue(group.getInverted());
}
@ParameterizedTest
@MethodSource("motorControllerArguments")
void setInvertedDoesNotModifyMotorControllersTest(
final MotorControllerGroup group, final MotorController[] motorControllers) {
group.setInverted(true);
assertArrayEquals(
Stream.generate(() -> false).limit(motorControllers.length).toArray(),
Arrays.stream(motorControllers).map(MotorController::getInverted).toArray());
}
@ParameterizedTest
@MethodSource("motorControllerArguments")
void setInvertedDoesInvertTest(
final MotorControllerGroup group, final MotorController[] motorControllers) {
group.setInverted(true);
group.set(1.0);
assertArrayEquals(
DoubleStream.generate(() -> -1.0).limit(motorControllers.length).toArray(),
Arrays.stream(motorControllers).mapToDouble(MotorController::get).toArray(),
0.00005);
}
@ParameterizedTest
@MethodSource("motorControllerArguments")
void disableTest(final MotorControllerGroup group, final MotorController[] motorControllers) {
group.set(1.0);
group.disable();
assertArrayEquals(
DoubleStream.generate(() -> 0.0).limit(motorControllers.length).toArray(),
Arrays.stream(motorControllers).mapToDouble(MotorController::get).toArray(),
0.00005);
}
@ParameterizedTest
@MethodSource("motorControllerArguments")
void stopMotorTest(final MotorControllerGroup group, final MotorController[] motorControllers) {
group.set(1.0);
group.stopMotor();
assertArrayEquals(
DoubleStream.generate(() -> 0.0).limit(motorControllers.length).toArray(),
Arrays.stream(motorControllers).mapToDouble(MotorController::get).toArray(),
0.00005);
}
}