wpilibsuite / frc-docs

Official FRC Documentation powered by Read the Docs
https://docs.wpilib.org
Other
144 stars 257 forks source link

Shuffleboard API docs do not mention sending data with lambda functions #2617

Open SamCarlberg opened 5 months ago

SamCarlberg commented 5 months ago

The docs currently recommend using NT entries directly:

If data needs to be updated (for example, the output of some calculation done on the robot), call getEntry() after defining the value, then update it when needed or in a periodic function


class VisionCalculator {
private ShuffleboardTab tab = Shuffleboard.getTab("Vision");
private GenericEntry distanceEntry =
tab.add("Distance to target", 0)
.getEntry();

public void calculate() { double distance = ...; distanceEntry.setDouble(distance); } }


This should instead recommend `addNumber` with a lambda function to read a cached `distanceToTarget` field.

```java
class VisionCalculator {
   private ShuffleboardTab tab = Shuffleboard.getTab("Vision");
   private double distanceToTarget = 0;

   public VisionCalculator() {
     tab.addNumber("Distance to target", () -> distanceToTarget);
   }

   public void calculate() {
     double distanceToTarget = /* expensive calculation*/;
   }
}

The NT entry API should only be used for reading data from the dashboard, such as from a slider, button, or text field

Starlight220 commented 5 months ago

The NT entry API should only be used for reading data from the dashboard, such as from a slider, button, or text field

Isn't that what getNumber etc are for?

SamCarlberg commented 5 months ago

Isn't that what getNumber etc are for?

Are you thinking of the smartdashboard API? Shuffleboard doesn't have those functions.