I am using command based in java vscode, and I have written the drive train in a subsystem, but everything else is in robot.java (shooter, intake, etc.). I have written a working autonomous code for the drive train, but can’t figure out how to program the others components autonomously. Any help would be GREATLY appreciated!
If your other components are not in subsystems, it will be hard to organize their functionality into commands since there will be no convenient way to expose functionality to your command subclasses, or to leverage the requirement-based resource-management system. You can build an autonomous from the various inline-able commands, but will be limited in what you are able to do.
All we want to do is drive back a few feet, and shoot 3 balls. Is that possible?
Sure; you could do that even without any of the command-based machinery without too much issue. Just write a simple state machine.
If you really want to use commands, then you can probably build an inlined command group that does this using lambdas.
Could you possibly walk me through how to make a simple state machine? Sorry I’m a fairly new programmer.
It would probably look vaguely like this (I have no idea how your shooter is set up, so I’ll assume it’s open-loop for now and base everything on timing):
...
enum AutoState {
kSpinUp,
kShoot,
kBackUp,
kIdle,
}
private AutoState autoState = kIdle;
private Timer timer = new Timer();
...
public void autonomousInit() {
timer.reset();
timer.start();
autoState = kSpinUp;
shooterMotor.set(shootSpeed);
}
public void autonomousPeriodic() {
if (autoState == kSpinUp) {
if (timer.advanceIfElapsed(spinUpTime)) {
autoState = kShoot;
}
} else if (autoState == kShoot) {
feederMotor.set(1);
if (timer.advanceIfElapsed(shootTime)) {
autoState = kBackUp;
feederMotor.set(0);
shooterMotor.set(0);
}
} else if (autoState == kBackUp) {
drive.arcadeDrive(-.5, 0);
if (timer.advanceIfElapsed(backUpTime) {
autoState = kIdle;
drive.arcadeDrive(0, 0);
}
}
}
And this would be in my Auto command? (where I set up the drive train autonomous) or would I put it somewhere else?
It should be clear from the methods present that this would go directly in Robot.java
. As I mentioned before, writing a subclass of Command
is unlikely to work well if most of your robot components are not in subsystems, as you will have no way of accessing them (unless you make them all global, which is bad).
Ok I will try this. Thank you so much! This was extremely helpful.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.