mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
[wpilib] SpeedControllerGroup: Add vector-taking constructor (#2194)
This allows the list to be constructed dynamically. Co-authored-by: Thad House <thadhouse1@gmail.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -23,7 +23,8 @@ class SpeedControllerGroup : public Sendable,
|
||||
template <class... SpeedControllers>
|
||||
explicit SpeedControllerGroup(SpeedController& speedController,
|
||||
SpeedControllers&... speedControllers);
|
||||
~SpeedControllerGroup() override = default;
|
||||
explicit SpeedControllerGroup(
|
||||
std::vector<std::reference_wrapper<SpeedController>>&& speedControllers);
|
||||
|
||||
SpeedControllerGroup(SpeedControllerGroup&&) = default;
|
||||
SpeedControllerGroup& operator=(SpeedControllerGroup&&) = default;
|
||||
@@ -41,6 +42,8 @@ class SpeedControllerGroup : public Sendable,
|
||||
private:
|
||||
bool m_isInverted = false;
|
||||
std::vector<std::reference_wrapper<SpeedController>> m_speedControllers;
|
||||
|
||||
void Initialize();
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -7,19 +7,17 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "frc/smartdashboard/SendableRegistry.h"
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
namespace frc {
|
||||
|
||||
template <class... SpeedControllers>
|
||||
SpeedControllerGroup::SpeedControllerGroup(
|
||||
SpeedController& speedController, SpeedControllers&... speedControllers)
|
||||
: m_speedControllers{speedController, speedControllers...} {
|
||||
for (auto& speedController : m_speedControllers)
|
||||
SendableRegistry::GetInstance().AddChild(this, &speedController.get());
|
||||
static int instances = 0;
|
||||
++instances;
|
||||
SendableRegistry::GetInstance().Add(this, "SpeedControllerGroup", instances);
|
||||
: m_speedControllers(std::vector<std::reference_wrapper<SpeedController>>{
|
||||
speedController, speedControllers...}) {
|
||||
Initialize();
|
||||
}
|
||||
|
||||
} // namespace frc
|
||||
|
||||
Reference in New Issue
Block a user