diff --git a/wpilibc/src/main/native/cpp/motorcontrol/MotorControllerGroup.cpp b/wpilibc/src/main/native/cpp/motorcontrol/MotorControllerGroup.cpp deleted file mode 100644 index 311c71f7b1..0000000000 --- a/wpilibc/src/main/native/cpp/motorcontrol/MotorControllerGroup.cpp +++ /dev/null @@ -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 -#include - -#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>&& 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 diff --git a/wpilibc/src/main/native/include/wpi/hardware/motor/MotorControllerGroup.hpp b/wpilibc/src/main/native/include/wpi/hardware/motor/MotorControllerGroup.hpp deleted file mode 100644 index ca53987181..0000000000 --- a/wpilibc/src/main/native/include/wpi/hardware/motor/MotorControllerGroup.hpp +++ /dev/null @@ -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 -#include - -#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 { - 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 - explicit MotorControllerGroup(MotorController& motorController, - MotorControllers&... motorControllers) - : m_motorControllers(std::vector>{ - motorController, motorControllers...}) { - Initialize(); - } - - /** - * Create a new MotorControllerGroup with the provided MotorControllers. - * - * @param motorControllers The MotorControllers to add. - */ - explicit MotorControllerGroup( - std::vector>&& 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> m_motorControllers; - - void Initialize(); -}; - -} // namespace wpi - -WPI_UNIGNORE_DEPRECATED diff --git a/wpilibc/src/test/native/cpp/motorcontrol/MotorControllerGroupTest.cpp b/wpilibc/src/test/native/cpp/motorcontrol/MotorControllerGroupTest.cpp deleted file mode 100644 index 6eeeae570c..0000000000 --- a/wpilibc/src/test/native/cpp/motorcontrol/MotorControllerGroupTest.cpp +++ /dev/null @@ -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 -#include - -#include - -#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 { - protected: - std::vector m_motorControllers; - std::unique_ptr m_group; - - void SetUp() override { - switch (GetParam()) { - case TEST_ONE: { - m_motorControllers.emplace_back(); - m_group = std::make_unique(m_motorControllers[0]); - break; - } - - case TEST_TWO: { - m_motorControllers.emplace_back(); - m_motorControllers.emplace_back(); - m_group = std::make_unique(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(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 diff --git a/wpilibj/src/main/java/org/wpilib/hardware/motor/MotorControllerGroup.java b/wpilibj/src/main/java/org/wpilib/hardware/motor/MotorControllerGroup.java deleted file mode 100644 index 71368214ed..0000000000 --- a/wpilibj/src/main/java/org/wpilib/hardware/motor/MotorControllerGroup.java +++ /dev/null @@ -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); - } -} diff --git a/wpilibj/src/test/java/org/wpilib/hardware/motor/MotorControllerGroupTest.java b/wpilibj/src/test/java/org/wpilib/hardware/motor/MotorControllerGroupTest.java deleted file mode 100644 index a9bf69be18..0000000000 --- a/wpilibj/src/test/java/org/wpilib/hardware/motor/MotorControllerGroupTest.java +++ /dev/null @@ -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 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); - } -}