检索数据

与” SmartDashboard . getNumber “和朋友不同,从Shuffleboard检索数据也是通过我们在前一篇文章中提到的NetworkTableEntries完成的。

class DriveBase extends Subsystem {
   private ShuffleboardTab tab = Shuffleboard.getTab("Drive");
   private GenericEntry maxSpeed =
      tab.add("Max Speed", 1)
         .getEntry();

   private DifferentialDrive robotDrive = ...;

   public void drive(double left, double right) {
   // Retrieve the maximum speed from the dashboard
   double max = maxSpeed.getDouble(1.0);
   robotDrive.tankDrive(left * max, right * max);
   }
}
import commands2
import wpilib.drive
from wpilib.shuffleboard import Shuffleboard

class DriveSubsystem(commands2.SubsystemBase):
   def __init__(self) -> None:
      super().__init__()

      tab = Shuffleboard.getTab("Drive")
      self.maxSpeed = tab.add("Max Speed", 1).getEntry()

      this.robotDrive = ...

   def drive(self, left: float, right: float):
      # Retrieve the maximum speed from the dashboard
      max = self.maxSpeed.getDouble(1.0)
      self.robotDrive.tankDrive(left * max, right * max)

这个基本示例有一个明显的缺陷:可以在仪表板上将最大速度设置为[0,1]之外的值-这可能导致输入饱和(始终以最大速度),甚至颠倒!幸运的是,有一种方法可以避免此问题-下一篇文章将对此进行介绍。