2019-08-25 23:55:59 -04:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
/* Copyright (c) 2019 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. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#include "frc2/command/SubsystemBase.h"
|
|
|
|
|
|
|
|
|
|
#include <frc/smartdashboard/SendableBuilder.h>
|
2019-09-14 15:22:54 -05:00
|
|
|
#include <frc/smartdashboard/SendableRegistry.h>
|
2019-08-25 23:55:59 -04:00
|
|
|
#include <frc2/command/Command.h>
|
|
|
|
|
#include <frc2/command/CommandScheduler.h>
|
|
|
|
|
|
|
|
|
|
using namespace frc2;
|
|
|
|
|
|
|
|
|
|
SubsystemBase::SubsystemBase() {
|
2019-09-14 15:22:54 -05:00
|
|
|
frc::SendableRegistry::GetInstance().AddLW(this, GetTypeName(*this));
|
2019-08-25 23:55:59 -04:00
|
|
|
CommandScheduler::GetInstance().RegisterSubsystem({this});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SubsystemBase::InitSendable(frc::SendableBuilder& builder) {
|
|
|
|
|
builder.SetSmartDashboardType("Subsystem");
|
|
|
|
|
builder.AddBooleanProperty(".hasDefault",
|
|
|
|
|
[this] { return GetDefaultCommand() != nullptr; },
|
|
|
|
|
nullptr);
|
|
|
|
|
builder.AddStringProperty(".default",
|
|
|
|
|
[this]() -> std::string {
|
|
|
|
|
auto command = GetDefaultCommand();
|
|
|
|
|
if (command == nullptr) return "none";
|
|
|
|
|
return command->GetName();
|
|
|
|
|
},
|
|
|
|
|
nullptr);
|
|
|
|
|
builder.AddBooleanProperty(".hasCommand",
|
|
|
|
|
[this] { return GetCurrentCommand() != nullptr; },
|
|
|
|
|
nullptr);
|
|
|
|
|
builder.AddStringProperty(".command",
|
|
|
|
|
[this]() -> std::string {
|
|
|
|
|
auto command = GetCurrentCommand();
|
|
|
|
|
if (command == nullptr) return "none";
|
|
|
|
|
return command->GetName();
|
|
|
|
|
},
|
|
|
|
|
nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-14 15:22:54 -05:00
|
|
|
std::string SubsystemBase::GetName() const {
|
|
|
|
|
return frc::SendableRegistry::GetInstance().GetName(this);
|
|
|
|
|
}
|
2019-08-25 23:55:59 -04:00
|
|
|
|
2019-09-14 15:22:54 -05:00
|
|
|
void SubsystemBase::SetName(const wpi::Twine& name) {
|
|
|
|
|
frc::SendableRegistry::GetInstance().SetName(this, name);
|
|
|
|
|
}
|
2019-08-25 23:55:59 -04:00
|
|
|
|
2019-09-14 15:22:54 -05:00
|
|
|
std::string SubsystemBase::GetSubsystem() const {
|
|
|
|
|
return frc::SendableRegistry::GetInstance().GetSubsystem(this);
|
|
|
|
|
}
|
2019-08-25 23:55:59 -04:00
|
|
|
|
2019-09-14 15:22:54 -05:00
|
|
|
void SubsystemBase::SetSubsystem(const wpi::Twine& name) {
|
|
|
|
|
frc::SendableRegistry::GetInstance().SetSubsystem(this, name);
|
|
|
|
|
}
|
2019-08-25 23:55:59 -04:00
|
|
|
|
|
|
|
|
void SubsystemBase::AddChild(std::string name, frc::Sendable* child) {
|
2019-09-14 15:22:54 -05:00
|
|
|
auto& registry = frc::SendableRegistry::GetInstance();
|
|
|
|
|
registry.AddLW(child, GetSubsystem(), name);
|
|
|
|
|
registry.AddChild(this, child);
|
2019-08-25 23:55:59 -04:00
|
|
|
}
|