Add a way to indicate a Sendable is an actuator (#1226)

SendableBuilder.setActuator() sets the .actuator key in the network table
so dashboards can change behavior on the client side if desired, and also
sets a local flag (retrievable via isActuator()).

Both make drive bases actuators and call setSafeState on them.
This commit is contained in:
Peter Johnson
2018-07-28 14:04:46 -07:00
committed by GitHub
parent 5fafaf6272
commit 0614913f1a
25 changed files with 78 additions and 0 deletions

View File

@@ -136,6 +136,7 @@ bool DoubleSolenoid::IsRevSolenoidBlackListed() const {
void DoubleSolenoid::InitSendable(SendableBuilder& builder) {
builder.SetSmartDashboardType("Double Solenoid");
builder.SetActuator(true);
builder.SetSafeState([=]() { Set(kOff); });
builder.AddSmallStringProperty(
"Value",

View File

@@ -84,6 +84,7 @@ int NidecBrushless::GetChannel() const { return m_pwm.GetChannel(); }
void NidecBrushless::InitSendable(SendableBuilder& builder) {
builder.SetSmartDashboardType("Nidec Brushless");
builder.SetActuator(true);
builder.SetSafeState([=]() { StopMotor(); });
builder.AddDoubleProperty("Value", [=]() { return Get(); },
[=](double value) { Set(value); });

View File

@@ -184,6 +184,7 @@ int PWM::GetChannel() const { return m_channel; }
void PWM::InitSendable(SendableBuilder& builder) {
builder.SetSmartDashboardType("PWM");
builder.SetActuator(true);
builder.SetSafeState([=]() { SetDisabled(); });
builder.AddDoubleProperty("Value", [=]() { return GetRaw(); },
[=](double value) { SetRaw(value); });

View File

@@ -33,6 +33,7 @@ PWMSpeedController::PWMSpeedController(int channel) : SafePWM(channel) {}
void PWMSpeedController::InitSendable(SendableBuilder& builder) {
builder.SetSmartDashboardType("Speed Controller");
builder.SetActuator(true);
builder.SetSafeState([=]() { SetDisabled(); });
builder.AddDoubleProperty("Value", [=]() { return GetSpeed(); },
[=](double value) { SetSpeed(value); });

View File

@@ -201,6 +201,7 @@ void Relay::GetDescription(wpi::raw_ostream& desc) const {
void Relay::InitSendable(SendableBuilder& builder) {
builder.SetSmartDashboardType("Relay");
builder.SetActuator(true);
builder.SetSafeState([=]() { Set(kOff); });
builder.AddSmallStringProperty(
"Value",

View File

@@ -87,6 +87,7 @@ void Solenoid::StartPulse() {
void Solenoid::InitSendable(SendableBuilder& builder) {
builder.SetSmartDashboardType("Solenoid");
builder.SetActuator(true);
builder.SetSafeState([=]() { Set(false); });
builder.AddBooleanProperty("Value", [=]() { return Get(); },
[=](bool value) { Set(value); });

View File

@@ -46,6 +46,7 @@ void SpeedControllerGroup::PIDWrite(double output) { Set(output); }
void SpeedControllerGroup::InitSendable(SendableBuilder& builder) {
builder.SetSmartDashboardType("Speed Controller");
builder.SetActuator(true);
builder.SetSafeState([=]() { StopMotor(); });
builder.AddDoubleProperty("Value", [=]() { return Get(); },
[=](double value) { Set(value); });

View File

@@ -211,6 +211,8 @@ void DifferentialDrive::GetDescription(wpi::raw_ostream& desc) const {
void DifferentialDrive::InitSendable(SendableBuilder& builder) {
builder.SetSmartDashboardType("DifferentialDrive");
builder.SetActuator(true);
builder.SetSafeState([=] { StopMotor(); });
builder.AddDoubleProperty("Left Motor Speed",
[=]() { return m_leftMotor.Get(); },
[=](double value) { m_leftMotor.Set(value); });

View File

@@ -101,6 +101,8 @@ void KilloughDrive::GetDescription(wpi::raw_ostream& desc) const {
void KilloughDrive::InitSendable(SendableBuilder& builder) {
builder.SetSmartDashboardType("KilloughDrive");
builder.SetActuator(true);
builder.SetSafeState([=] { StopMotor(); });
builder.AddDoubleProperty("Left Motor Speed",
[=]() { return m_leftMotor.Get(); },
[=](double value) { m_leftMotor.Set(value); });

View File

@@ -107,6 +107,8 @@ void MecanumDrive::GetDescription(wpi::raw_ostream& desc) const {
void MecanumDrive::InitSendable(SendableBuilder& builder) {
builder.SetSmartDashboardType("MecanumDrive");
builder.SetActuator(true);
builder.SetSafeState([=] { StopMotor(); });
builder.AddDoubleProperty("Front Left Motor Speed",
[=]() { return m_frontLeftMotor.Get(); },
[=](double value) { m_frontLeftMotor.Set(value); });

View File

@@ -21,6 +21,8 @@ std::shared_ptr<nt::NetworkTable> SendableBuilderImpl::GetTable() {
return m_table;
}
bool SendableBuilderImpl::IsActuator() const { return m_actuator; }
void SendableBuilderImpl::UpdateTable() {
uint64_t time = nt::Now();
for (auto& property : m_properties) {
@@ -53,6 +55,11 @@ void SendableBuilderImpl::SetSmartDashboardType(const wpi::Twine& type) {
m_table->GetEntry(".type").SetString(type);
}
void SendableBuilderImpl::SetActuator(bool value) {
m_table->GetEntry(".actuator").SetBoolean(value);
m_actuator = value;
}
void SendableBuilderImpl::SetSafeState(std::function<void()> func) {
m_safeState = func;
}

View File

@@ -32,6 +32,14 @@ class SendableBuilder {
*/
virtual void SetSmartDashboardType(const wpi::Twine& type) = 0;
/**
* Set a flag indicating if this sendable should be treated as an actuator.
* By default this flag is false.
*
* @param value true if actuator, false if not
*/
virtual void SetActuator(bool value) = 0;
/**
* Set the function that should be called to set the Sendable into a safe
* state. This is called when entering and exiting Live Window mode.

View File

@@ -46,6 +46,12 @@ class SendableBuilderImpl : public SendableBuilder {
*/
std::shared_ptr<nt::NetworkTable> GetTable();
/**
* Return whether this sendable should be treated as an actuator.
* @return True if actuator, false if not.
*/
bool IsActuator() const;
/**
* Update the network table values by calling the getters for all properties.
*/
@@ -74,6 +80,7 @@ class SendableBuilderImpl : public SendableBuilder {
void StopLiveWindowMode();
void SetSmartDashboardType(const wpi::Twine& type) override;
void SetActuator(bool value) override;
void SetSafeState(std::function<void()> func) override;
void SetUpdateTable(std::function<void()> func) override;
nt::NetworkTableEntry GetEntry(const wpi::Twine& key) override;
@@ -188,6 +195,7 @@ class SendableBuilderImpl : public SendableBuilder {
std::function<void()> m_updateTable;
std::shared_ptr<nt::NetworkTable> m_table;
nt::NetworkTableEntry m_controllableEntry;
bool m_actuator = false;
};
} // namespace frc