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

@@ -166,6 +166,7 @@ public class DoubleSolenoid extends SolenoidBase {
@Override
public void initSendable(SendableBuilder builder) {
builder.setSmartDashboardType("Double Solenoid");
builder.setActuator(true);
builder.setSafeState(() -> set(Value.kOff));
builder.addStringProperty("Value", () -> get().name().substring(1), value -> {
if ("Forward".equals(value)) {

View File

@@ -196,6 +196,7 @@ public class NidecBrushless extends SendableBase implements SpeedController, Mot
@Override
public void initSendable(SendableBuilder builder) {
builder.setSmartDashboardType("Nidec Brushless");
builder.setActuator(true);
builder.setSafeState(this::stopMotor);
builder.addDoubleProperty("Value", this::get, this::set);
}

View File

@@ -242,6 +242,7 @@ public class PWM extends SendableBase {
@Override
public void initSendable(SendableBuilder builder) {
builder.setSmartDashboardType("PWM");
builder.setActuator(true);
builder.setSafeState(this::setDisabled);
builder.addDoubleProperty("Value", this::getRaw, value -> setRaw((int) value));
}

View File

@@ -77,6 +77,7 @@ public abstract class PWMSpeedController extends SafePWM implements SpeedControl
@Override
public void initSendable(SendableBuilder builder) {
builder.setSmartDashboardType("Speed Controller");
builder.setActuator(true);
builder.setSafeState(this::setDisabled);
builder.addDoubleProperty("Value", this::getSpeed, this::setSpeed);
}

View File

@@ -334,6 +334,7 @@ public class Relay extends SendableBase implements MotorSafety {
@Override
public void initSendable(SendableBuilder builder) {
builder.setSmartDashboardType("Relay");
builder.setActuator(true);
builder.setSafeState(() -> set(Value.kOff));
builder.addStringProperty("Value", () -> get().getPrettyValue(),
value -> set(Value.getValueOf(value).orElse(Value.kOff)));

View File

@@ -115,6 +115,7 @@ public class Solenoid extends SolenoidBase {
@Override
public void initSendable(SendableBuilder builder) {
builder.setSmartDashboardType("Solenoid");
builder.setActuator(true);
builder.setSafeState(() -> set(false));
builder.addBooleanProperty("Value", this::get, this::set);
}

View File

@@ -83,6 +83,7 @@ public class SpeedControllerGroup extends SendableBase implements SpeedControlle
@Override
public void initSendable(SendableBuilder builder) {
builder.setSmartDashboardType("Speed Controller");
builder.setActuator(true);
builder.setSafeState(this::stopMotor);
builder.addDoubleProperty("Value", this::get, this::set);
}

View File

@@ -390,6 +390,8 @@ public class DifferentialDrive extends RobotDriveBase {
@Override
public void initSendable(SendableBuilder builder) {
builder.setSmartDashboardType("DifferentialDrive");
builder.setActuator(true);
builder.setSafeState(this::stopMotor);
builder.addDoubleProperty("Left Motor Speed", m_leftMotor::get, m_leftMotor::set);
builder.addDoubleProperty(
"Right Motor Speed",

View File

@@ -204,6 +204,8 @@ public class KilloughDrive extends RobotDriveBase {
@Override
public void initSendable(SendableBuilder builder) {
builder.setSmartDashboardType("KilloughDrive");
builder.setActuator(true);
builder.setSafeState(this::stopMotor);
builder.addDoubleProperty("Left Motor Speed", m_leftMotor::get, m_leftMotor::set);
builder.addDoubleProperty("Right Motor Speed", m_rightMotor::get, m_rightMotor::set);
builder.addDoubleProperty("Back Motor Speed", m_backMotor::get, m_backMotor::set);

View File

@@ -208,6 +208,8 @@ public class MecanumDrive extends RobotDriveBase {
@Override
public void initSendable(SendableBuilder builder) {
builder.setSmartDashboardType("MecanumDrive");
builder.setActuator(true);
builder.setSafeState(this::stopMotor);
builder.addDoubleProperty("Front Left Motor Speed",
m_frontLeftMotor::get,
m_frontLeftMotor::set);

View File

@@ -25,6 +25,14 @@ public interface SendableBuilder {
*/
void setSmartDashboardType(String type);
/**
* 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
*/
void setActuator(boolean value);
/**
* 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

@@ -58,6 +58,7 @@ public class SendableBuilderImpl implements SendableBuilder {
private Runnable m_updateTable;
private NetworkTable m_table;
private NetworkTableEntry m_controllableEntry;
private boolean m_actuator;
/**
* Set the network table. Must be called prior to any Add* functions being
@@ -77,6 +78,14 @@ public class SendableBuilderImpl implements SendableBuilder {
return m_table;
}
/**
* Return whether this sendable should be treated as an actuator.
* @return True if actuator, false if not.
*/
public boolean isActuator() {
return m_actuator;
}
/**
* Update the network table values by calling the getters for all properties.
*/
@@ -144,6 +153,18 @@ public class SendableBuilderImpl implements SendableBuilder {
m_table.getEntry(".type").setString(type);
}
/**
* 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
*/
@Override
public void setActuator(boolean value) {
m_table.getEntry(".actuator").setBoolean(value);
m_actuator = value;
}
/**
* 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.