Skip to content

Commit

Permalink
Add simulation to the TestControl
Browse files Browse the repository at this point in the history
  • Loading branch information
CoffeeCoder1 committed Oct 20, 2024
1 parent 645508b commit 0df5183
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import edu.wpi.first.networktables.DoubleSubscriber;
import edu.wpi.first.networktables.NetworkTable;

import edu.wpi.first.hal.SimDevice;
import edu.wpi.first.hal.SimDouble;

/**
* A test {@link io.github.roboblazers7617.buttonbox.Control} that outputs a float that is increased every time feedback is updated.
*/
Expand All @@ -16,6 +19,9 @@ public class TestControl extends Control {
private DoubleSubscriber valueSub;
private double value = 0;

private SimDevice simDevice;
private SimDouble valueSim;

/**
* Creates a new TestControl.
*
Expand All @@ -27,6 +33,12 @@ public TestControl(String id) {
super(id);
}

@Override
public void setupSimulation() {
simDevice = SimDevice.create(getId());
valueSim = simDevice.createDouble("Value", SimDevice.Direction.kOutput, value);
}

@Override
public void setupNetworkTables(NetworkTable table) {
valueTopic = table.getDoubleTopic("value");
Expand All @@ -38,6 +50,7 @@ public void setupNetworkTables(NetworkTable table) {
public void updateServer() {
value += 0.01;
valuePub.set(value);
valueSim.set(value);
}

@Override
Expand Down

0 comments on commit 0df5183

Please sign in to comment.