Hi -
We are trying to simply use the Digital and Analog inputs provided on the Labview Dashboard from our Java command-based robot.
We have found that the value of these controls is not read correctly in robotInit making it difficult to use these to initialize commands or OI assignments.
To demonstrate the problem I have written a simple command-based robot like this (just showing those parts that are different than the generated code):
public void robotInit() {
System.out.println(String.format("robotInit: DI0: %b"
, SmartDashboard.getBoolean("DB/Button 0", false)));
System.out.println(String.format("robotInit: AI0: %f"
, SmartDashboard.getNumber("DB/Slider 0", 0.0)));
oi = new OI();
// instantiate the command used for the autonomous period
autonomousCommand = new ExampleCommand();
}
public void autonomousInit() {
System.out.println(String.format("autonomousInit: DI0: %b"
, SmartDashboard.getBoolean("DB/Button 0", false)));
System.out.println(String.format("autonomousInit: AI0: %f"
, SmartDashboard.getNumber("DB/Slider 0", 0.0)));
// schedule the autonomous command (example)
if (autonomousCommand != null) autonomousCommand.start();
}
public void teleopInit() {
// This makes sure that the autonomous stops running when
// teleop starts running. If you want the autonomous to
// continue until interrupted by another command, remove
// this line or comment it out.
System.out.println(String.format("teleopInit: DI0: %b"
, SmartDashboard.getBoolean("DB/Button 0", false)));
System.out.println(String.format("teleopInit: AI0: %f"
, SmartDashboard.getNumber("DB/Slider 0", 0.0)));
if (autonomousCommand != null) autonomousCommand.cancel();
}
With the DI0 and AI0 set to on (true) and 2.5, respectively… We resend the code (or restart the code from the driver station) then start a match in practice mode, we get:
robotInit: DI0: false
robotInit: AI0: 0.000000
edu.wpi.first.wpilibj.networktables2.server.ServerConnectionAdapter@fe5989 entered connection state: GOT_CONNECTION_FROM_CLIENT
edu.wpi.first.wpilibj.networktables2.server.ServerConnectionAdapter@fe5989 entered connection state: CONNECTED_TO_CLIENT
autonomousInit: DI0: true
autonomousInit: AI0: 2.500000
teleopInit: DI0: true
teleopInit: AI0: 2.500000
I assume the reason they are not read correctly is because the robot is not yet connected to the “Client” (the DriverStation, I guess) and so cannot read them.
Does anyone have any suggestions about how to use the the LabView dashboard settings if we want to use them to initialize OI, subsystems, commands, etc.
We want to put the initialization in robotInit because we know that always gets run whether we are testing autonomous or teleop. So far our workaround is to do all the creation in a common function called by autonomousInit and teleopInit and to keep track if the initialization has already been done or not, but we are not happy with this solution.
mp