Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SamCarlberg opened this issue Mar 26, 2024 · 2 comments
Open

Comments

@SamCarlberg
Copy link
Member

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.

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
Copy link
Member

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
Copy link
Member Author

Isn't that what getNumber etc are for?

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants