We have a Jetson on the robot this year, and I don’t want to shut it down by directly cutting its power (to avoid things such as filesystem corruption, etc). Therefore, I went ahead and added an entry in NetworkTables that when set to true, will cause the Jetson to run a shutdown -P now
. I tried to attach a command that sets the entry from the rio to the User button like this:
Trigger shutdownJetson = new Trigger() {
@Override
public boolean get() {
return RobotController.getUserButton();
}
};
shutdownJetson.whenActive(new ShutdownJetson());
I also tried to send this command to SmartDashboard. However upon testing I realized that the button on the rio as well as the SmartDashboard only work when the robot is enabled, which defeats the whole point of having those buttons. Is there a way I can make this work when the robot is disabled as well?
To allow a command to run when the robot is disabled, you need to tell the command it can run when the robot is disabled.
You can do this by
ShutdownJetson shutdown = new ShutdownJetson();
shutdown.setRunWhenDisabled(true);
shutdownJetson.whenActive(shutdown);
The only issue I see with this is that I don’t think it will create a new instance of the command every time it is run, however if you’re doing it just before a robot power down/reboot that is probably OK.
I’m also sure there is a way to do it and have it create a new instance, maybe it does already, I’ve never scheduled a command from within a trigger.
Either way, you need to call .setRunWhenDisabled(true)
on the Command object.
You should be able to call setRunWhenDisabled(true)
from your Command’s constructor and then just use:
shutdownJetson.whenActive(new ShutdownJetson());
1 Like
Ah yes, that makes sense, I’d always tried to do it from its initialize method, which of course, wouldn’t run!
Thank you all so much! This should fix it, I will test it as soon as I can.