mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Update LiveWindow to provide continuous telemetry. (#771)
LiveWindow.updateValues() is now called from IterativeRobotBase on every loop iteration. Telemetry for all WPILib classes is enabled by default; it can be disabled for specific classes using LiveWindow.disableTelemetry(), or all telemetry can be disabled using LiveWindow.disableAllTelemetry(). This necessitated changing the hook methodology into other classes to be more property-based rather than each class providing multiple functions. This had the benefit of reducing boilerplate and increasing consistency. - Remove NamedSendable, add name to Sendable. - Provide SendableBase abstract class. - Deprecate LiveWindow addSensor/addActuator interfaces. - Add LiveWindow support to drive classes. - Add addChild() helper functions to Subsystem. - Fix inheritance hierarchy. Now only sensors inherit from SensorBase. Other devices inherit from some combination of SendableBase, ErrorBase, or nothing.
This commit is contained in:
@@ -24,6 +24,7 @@ import java.util.logging.Logger;
|
||||
import edu.wpi.first.networktables.NetworkTable;
|
||||
import edu.wpi.first.networktables.NetworkTableInstance;
|
||||
import edu.wpi.first.wpilibj.fixtures.MotorEncoderFixture;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilderImpl;
|
||||
import edu.wpi.first.wpilibj.test.AbstractComsSetup;
|
||||
import edu.wpi.first.wpilibj.test.TestBench;
|
||||
|
||||
@@ -43,6 +44,7 @@ import static org.junit.Assert.assertTrue;
|
||||
public class PIDTest extends AbstractComsSetup {
|
||||
private static final Logger logger = Logger.getLogger(PIDTest.class.getName());
|
||||
private NetworkTable m_table;
|
||||
private SendableBuilderImpl m_builder;
|
||||
|
||||
private static final double absoluteTolerance = 50;
|
||||
private static final double outputRange = 0.25;
|
||||
@@ -104,8 +106,10 @@ public class PIDTest extends AbstractComsSetup {
|
||||
logger.fine("Setup: " + me.getType());
|
||||
me.setup();
|
||||
m_table = NetworkTableInstance.getDefault().getTable("TEST_PID");
|
||||
m_builder = new SendableBuilderImpl();
|
||||
m_builder.setTable(m_table);
|
||||
m_controller = new PIDController(k_p, k_i, k_d, me.getEncoder(), me.getMotor());
|
||||
m_controller.initTable(m_table);
|
||||
m_controller.initSendable(m_builder);
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -134,6 +138,7 @@ public class PIDTest extends AbstractComsSetup {
|
||||
assertFalse("PID did not begin disabled", m_controller.isEnabled());
|
||||
assertEquals("PID.getError() did not start at " + setpoint, setpoint,
|
||||
m_controller.getError(), 0);
|
||||
m_builder.updateTable();
|
||||
assertEquals(k_p, m_table.getEntry("p").getDouble(9999999), 0);
|
||||
assertEquals(k_i, m_table.getEntry("i").getDouble(9999999), 0);
|
||||
assertEquals(k_d, m_table.getEntry("d").getDouble(9999999), 0);
|
||||
@@ -148,11 +153,12 @@ public class PIDTest extends AbstractComsSetup {
|
||||
double setpoint = 2500.0;
|
||||
m_controller.setSetpoint(setpoint);
|
||||
m_controller.enable();
|
||||
Timer.delay(.5);
|
||||
m_builder.updateTable();
|
||||
assertTrue(m_table.getEntry("enabled").getBoolean(false));
|
||||
assertTrue(m_controller.isEnabled());
|
||||
assertThat(0.0, is(not(me.getMotor().get())));
|
||||
m_controller.reset();
|
||||
m_builder.updateTable();
|
||||
assertFalse(m_table.getEntry("enabled").getBoolean(true));
|
||||
assertFalse(m_controller.isEnabled());
|
||||
assertEquals(0, me.getMotor().get(), 0);
|
||||
|
||||
@@ -19,6 +19,7 @@ import edu.wpi.first.wpilibj.Relay.Direction;
|
||||
import edu.wpi.first.wpilibj.Relay.InvalidValueException;
|
||||
import edu.wpi.first.wpilibj.Relay.Value;
|
||||
import edu.wpi.first.wpilibj.fixtures.RelayCrossConnectFixture;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilderImpl;
|
||||
import edu.wpi.first.wpilibj.test.AbstractComsSetup;
|
||||
import edu.wpi.first.wpilibj.test.TestBench;
|
||||
|
||||
@@ -34,13 +35,16 @@ public class RelayCrossConnectTest extends AbstractComsSetup {
|
||||
private static final NetworkTable table =
|
||||
NetworkTableInstance.getDefault().getTable("_RELAY_CROSS_CONNECT_TEST_");
|
||||
private RelayCrossConnectFixture m_relayFixture;
|
||||
private SendableBuilderImpl m_builder;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
m_relayFixture = TestBench.getRelayCrossConnectFixture();
|
||||
m_relayFixture.setup();
|
||||
m_relayFixture.getRelay().initTable(table);
|
||||
m_builder = new SendableBuilderImpl();
|
||||
m_builder.setTable(table);
|
||||
m_relayFixture.getRelay().initSendable(m_builder);
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -53,7 +57,7 @@ public class RelayCrossConnectTest extends AbstractComsSetup {
|
||||
public void testBothHigh() {
|
||||
m_relayFixture.getRelay().setDirection(Direction.kBoth);
|
||||
m_relayFixture.getRelay().set(Value.kOn);
|
||||
m_relayFixture.getRelay().updateTable();
|
||||
m_builder.updateTable();
|
||||
assertTrue("Input one was not high when relay set both high", m_relayFixture.getInputOne()
|
||||
.get());
|
||||
assertTrue("Input two was not high when relay set both high", m_relayFixture.getInputTwo()
|
||||
@@ -66,7 +70,7 @@ public class RelayCrossConnectTest extends AbstractComsSetup {
|
||||
public void testFirstHigh() {
|
||||
m_relayFixture.getRelay().setDirection(Direction.kBoth);
|
||||
m_relayFixture.getRelay().set(Value.kForward);
|
||||
m_relayFixture.getRelay().updateTable();
|
||||
m_builder.updateTable();
|
||||
assertFalse("Input one was not low when relay set Value.kForward", m_relayFixture.getInputOne()
|
||||
.get());
|
||||
assertTrue("Input two was not high when relay set Value.kForward", m_relayFixture
|
||||
@@ -80,7 +84,7 @@ public class RelayCrossConnectTest extends AbstractComsSetup {
|
||||
public void testSecondHigh() {
|
||||
m_relayFixture.getRelay().setDirection(Direction.kBoth);
|
||||
m_relayFixture.getRelay().set(Value.kReverse);
|
||||
m_relayFixture.getRelay().updateTable();
|
||||
m_builder.updateTable();
|
||||
assertTrue("Input one was not high when relay set Value.kReverse", m_relayFixture.getInputOne()
|
||||
.get());
|
||||
assertFalse("Input two was not low when relay set Value.kReverse", m_relayFixture
|
||||
@@ -94,7 +98,7 @@ public class RelayCrossConnectTest extends AbstractComsSetup {
|
||||
public void testForwardDirection() {
|
||||
m_relayFixture.getRelay().setDirection(Direction.kForward);
|
||||
m_relayFixture.getRelay().set(Value.kOn);
|
||||
m_relayFixture.getRelay().updateTable();
|
||||
m_builder.updateTable();
|
||||
assertFalse("Input one was not low when relay set Value.kOn in kForward Direction",
|
||||
m_relayFixture.getInputOne().get());
|
||||
assertTrue("Input two was not high when relay set Value.kOn in kForward Direction",
|
||||
@@ -107,7 +111,7 @@ public class RelayCrossConnectTest extends AbstractComsSetup {
|
||||
public void testReverseDirection() {
|
||||
m_relayFixture.getRelay().setDirection(Direction.kReverse);
|
||||
m_relayFixture.getRelay().set(Value.kOn);
|
||||
m_relayFixture.getRelay().updateTable();
|
||||
m_builder.updateTable();
|
||||
assertTrue("Input one was not high when relay set Value.kOn in kReverse Direction",
|
||||
m_relayFixture.getInputOne().get());
|
||||
assertFalse("Input two was not low when relay set Value.kOn in kReverse Direction",
|
||||
@@ -130,6 +134,7 @@ public class RelayCrossConnectTest extends AbstractComsSetup {
|
||||
|
||||
@Test
|
||||
public void testInitialSettings() {
|
||||
m_builder.updateTable();
|
||||
assertEquals(Value.kOff, m_relayFixture.getRelay().get());
|
||||
// Initially both outputs should be off
|
||||
assertFalse(m_relayFixture.getInputOne().get());
|
||||
|
||||
Reference in New Issue
Block a user