SmartDashboard with CommandBasedRobot Template

Since all of the tweaking of our robot code with regards to its proper operation are done, I’ve been working on customizing the dashboard using SmartDashboard. However, as I’m using the CommandBasedRobot template, I’ve run into a puzzling issue. I have no idea where to put all of my SmartDashboard::PutNumber… commands.

I’ve come up with three ideas, and reasons why each of them may not work properly.

  1. Place the SmartDashboard output commands in the Subsystem functions that access the required objects.
    Problem: I end up with SmartDashboard code everywhere and that seems a bit messy.

  2. Create a SmartDashboardOutput Command. (This is what I was doing before posting this topic.)
    Problem: It ‘Requires’ every Subsystem that I want output from and I’m worried that those requirements (and the interrupts that they will cause) will stop the robot from functioning correctly.

  3. Put copies of all the SmartDashboard commands in the appropriate functions (DisabledPeriodic, AutonomousPeriodic, and TeleopPeriodic) of the CommandBasedRobot.cpp file.
    Problem: This seems to make the most sense but I’m not sure that this is where these things should go. Also, I’d end up with three copies of each output line.

I’ve read the SmartDashboard guide but all of its code examples seem to use the SimpleRobot template so I haven’t been able to use that as a reference for this purpose.

Normally, if I couldn’t figure something like this out, I’d just write it all three ways and test by trial-and-error but, we only have so many ‘Robot Access Period’ hours before this weekend and I’d rather not waste any driver practice time with unnecessary flashing.

Thanks for any help you can provide :slight_smile:

We created a function to hold all the SmartDashboard calls in the robot class. It is hooked to a GetRawButton on the joystick inside each of the appropriate functions. That way we aren’t sending all the data when we don’t have to have it.

We just have it in our TeleopPeriodic() loop running at whatever interval we set it to from the Dashboard. Personally, I would just make a function and put it in a vxWorks task instead of thinking about it too hard. But then again, that would defeat the purpose of Command-based robot, which is to eliminate any reason why you would worry about relatively complex things like threading.

Alex Brinister

You don’t have to “require” the subsystems. If all you are doing is reading from them, it is fine. Because the Command extends CommandBase, you have access to the subsystem. the only thing that requires() does is stop other commands that require the subsystem because you are ostensibly going to affect the subsystems outputs.

TL;DR: If you are using a subsystem as read-only it is probably safe not to require it, AFAIK.

1 Like

Really? If that’s true then I should be good. Thanks :slight_smile:

I have not been able to get commands to run in disabled. If you are able to, I’d like to know how.

In Java, there is a setRunWhileDisabled method, that you can call in the constructor of the command. You also need to call the scheduler in the disabledPeriodic. I assume it’s similar in C++.

Ah. Probably. I was running the scheduler, but didnt know about the setRunWhileDisabled option. I’ll check it out tonight.


Yup, in C++ it works like this:

	virtual void RobotInit() {
		lw = LiveWindow::GetInstance();
	virtual void DisabledPeriodic() {