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/SubsystemBase.h"
|
|
|
|
|
|
2021-06-13 16:38:05 -07:00
|
|
|
#include <wpi/sendable/SendableBuilder.h>
|
|
|
|
|
#include <wpi/sendable/SendableRegistry.h>
|
2019-11-05 20:52:49 -08:00
|
|
|
|
|
|
|
|
#include "frc2/command/Command.h"
|
|
|
|
|
#include "frc2/command/CommandScheduler.h"
|
2019-08-25 23:55:59 -04:00
|
|
|
|
|
|
|
|
using namespace frc2;
|
|
|
|
|
|
|
|
|
|
SubsystemBase::SubsystemBase() {
|
2021-06-15 23:06:03 -07:00
|
|
|
wpi::SendableRegistry::AddLW(this, GetTypeName(*this));
|
2019-08-25 23:55:59 -04:00
|
|
|
CommandScheduler::GetInstance().RegisterSubsystem({this});
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-13 16:38:05 -07:00
|
|
|
void SubsystemBase::InitSendable(wpi::SendableBuilder& builder) {
|
2019-08-25 23:55:59 -04:00
|
|
|
builder.SetSmartDashboardType("Subsystem");
|
2020-06-27 20:39:00 -07:00
|
|
|
builder.AddBooleanProperty(
|
|
|
|
|
".hasDefault", [this] { return GetDefaultCommand() != nullptr; },
|
|
|
|
|
nullptr);
|
|
|
|
|
builder.AddStringProperty(
|
|
|
|
|
".default",
|
|
|
|
|
[this]() -> std::string {
|
|
|
|
|
auto command = GetDefaultCommand();
|
2020-12-28 12:58:06 -08:00
|
|
|
if (command == nullptr) {
|
|
|
|
|
return "none";
|
|
|
|
|
}
|
2020-06-27 20:39:00 -07:00
|
|
|
return command->GetName();
|
|
|
|
|
},
|
|
|
|
|
nullptr);
|
|
|
|
|
builder.AddBooleanProperty(
|
|
|
|
|
".hasCommand", [this] { return GetCurrentCommand() != nullptr; },
|
|
|
|
|
nullptr);
|
|
|
|
|
builder.AddStringProperty(
|
|
|
|
|
".command",
|
|
|
|
|
[this]() -> std::string {
|
|
|
|
|
auto command = GetCurrentCommand();
|
2020-12-28 12:58:06 -08:00
|
|
|
if (command == nullptr) {
|
|
|
|
|
return "none";
|
|
|
|
|
}
|
2020-06-27 20:39:00 -07:00
|
|
|
return command->GetName();
|
|
|
|
|
},
|
|
|
|
|
nullptr);
|
2019-08-25 23:55:59 -04:00
|
|
|
}
|
|
|
|
|
|
2019-09-14 15:22:54 -05:00
|
|
|
std::string SubsystemBase::GetName() const {
|
2021-06-15 23:06:03 -07:00
|
|
|
return wpi::SendableRegistry::GetName(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 SubsystemBase::SetName(std::string_view name) {
|
2021-06-15 23:06:03 -07:00
|
|
|
wpi::SendableRegistry::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 SubsystemBase::GetSubsystem() const {
|
2021-06-15 23:06:03 -07:00
|
|
|
return wpi::SendableRegistry::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 SubsystemBase::SetSubsystem(std::string_view name) {
|
2021-06-15 23:06:03 -07:00
|
|
|
wpi::SendableRegistry::SetSubsystem(this, name);
|
2019-09-14 15:22:54 -05:00
|
|
|
}
|
2019-08-25 23:55:59 -04:00
|
|
|
|
2021-06-13 16:38:05 -07:00
|
|
|
void SubsystemBase::AddChild(std::string name, wpi::Sendable* child) {
|
2021-06-15 23:06:03 -07:00
|
|
|
wpi::SendableRegistry::AddLW(child, GetSubsystem(), name);
|
2019-08-25 23:55:59 -04:00
|
|
|
}
|