2020-12-26 14:12:05 -08:00
|
|
|
// 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.
|
2019-08-25 23:55:59 -04:00
|
|
|
|
|
|
|
|
#include "frc2/command/CommandBase.h"
|
|
|
|
|
|
2021-06-13 16:38:05 -07:00
|
|
|
#include <wpi/sendable/SendableBuilder.h>
|
|
|
|
|
#include <wpi/sendable/SendableRegistry.h>
|
2019-08-25 23:55:59 -04:00
|
|
|
|
|
|
|
|
using namespace frc2;
|
|
|
|
|
|
|
|
|
|
CommandBase::CommandBase() {
|
2021-06-13 16:38:05 -07:00
|
|
|
wpi::SendableRegistry::GetInstance().Add(this, GetTypeName(*this));
|
2019-08-25 23:55:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CommandBase::AddRequirements(
|
|
|
|
|
std::initializer_list<Subsystem*> requirements) {
|
|
|
|
|
m_requirements.insert(requirements.begin(), requirements.end());
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-06 19:51:14 -07:00
|
|
|
void CommandBase::AddRequirements(wpi::span<Subsystem* const> requirements) {
|
2020-01-01 20:09:17 -08:00
|
|
|
m_requirements.insert(requirements.begin(), requirements.end());
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-25 23:55:59 -04:00
|
|
|
void CommandBase::AddRequirements(wpi::SmallSet<Subsystem*, 4> requirements) {
|
|
|
|
|
m_requirements.insert(requirements.begin(), requirements.end());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wpi::SmallSet<Subsystem*, 4> CommandBase::GetRequirements() const {
|
|
|
|
|
return m_requirements;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-26 17:44:18 -07:00
|
|
|
void CommandBase::SetName(std::string_view name) {
|
2021-06-13 16:38:05 -07:00
|
|
|
wpi::SendableRegistry::GetInstance().SetName(this, name);
|
2019-09-14 15:22:54 -05:00
|
|
|
}
|
2019-08-25 23:55:59 -04:00
|
|
|
|
2019-09-14 15:22:54 -05:00
|
|
|
std::string CommandBase::GetName() const {
|
2021-06-13 16:38:05 -07:00
|
|
|
return wpi::SendableRegistry::GetInstance().GetName(this);
|
2019-09-14 15:22:54 -05:00
|
|
|
}
|
2019-08-25 23:55:59 -04:00
|
|
|
|
2019-09-14 15:22:54 -05:00
|
|
|
std::string CommandBase::GetSubsystem() const {
|
2021-06-13 16:38:05 -07:00
|
|
|
return wpi::SendableRegistry::GetInstance().GetSubsystem(this);
|
2019-09-14 15:22:54 -05:00
|
|
|
}
|
2019-08-25 23:55:59 -04:00
|
|
|
|
2021-05-26 17:44:18 -07:00
|
|
|
void CommandBase::SetSubsystem(std::string_view subsystem) {
|
2021-06-13 16:38:05 -07:00
|
|
|
wpi::SendableRegistry::GetInstance().SetSubsystem(this, subsystem);
|
2019-08-25 23:55:59 -04:00
|
|
|
}
|
|
|
|
|
|
2021-06-13 16:38:05 -07:00
|
|
|
void CommandBase::InitSendable(wpi::SendableBuilder& builder) {
|
2019-08-25 23:55:59 -04:00
|
|
|
builder.SetSmartDashboardType("Command");
|
2020-06-27 20:39:00 -07:00
|
|
|
builder.AddStringProperty(
|
|
|
|
|
".name", [this] { return GetName(); }, nullptr);
|
|
|
|
|
builder.AddBooleanProperty(
|
|
|
|
|
"running", [this] { return IsScheduled(); },
|
|
|
|
|
[this](bool value) {
|
|
|
|
|
bool isScheduled = IsScheduled();
|
|
|
|
|
if (value && !isScheduled) {
|
|
|
|
|
Schedule();
|
|
|
|
|
} else if (!value && isScheduled) {
|
|
|
|
|
Cancel();
|
|
|
|
|
}
|
|
|
|
|
});
|
2019-08-25 23:55:59 -04:00
|
|
|
}
|