How would I go about converting my shooter system to be command-based?

I have it right now so that when it’s pressed, it will set a variable to true which will then allow a if statement to be true in robot periodic which then does a collection of if elseif chains comparing the time in which the variable was set to true to the elapsed time. The problem with how I did timing here is that it doesn’t use commands at all. I want to use commands as for autonomous I want it to be so that my trajectory command and a sequential command group are ran in parallel with parallel command group, with the sequential command group controlling the intake and shooter. I want it to be so that when the encoders have traveling an absolute x distance, it will cancel the commands which never end and start the next one. This works fine with the intake because it’s just two commands, intake start and intake stop which are binded to a trigger. However, this doesn’t work for my iterative based shooter code. Any ideas on how I can convert my shooter code from being timed based to command based?

Look at our code:

You’ll see in subsystems that we have a shooter subsystem. That has a constructor that sets the motor settings, then two functions - one to set RPM (setShooterRPM) and one to set percentage.

After you see that, we have a command that is called SetShooterRPM. All that does is take in an RPM and sets the shooter subsystem’s rpm using the setShooterRPM function on the Shooter Subsytem.

Then finally, in RobotContainer, you can see how we bind buttons to commands. The right bumper sets the shooter to the high goal RPM and the left bumper the Low goal RPM

If you look in Commands/Autonomous/Modes you will see how we schedule commands, including turning the shooter on and off

I would also recommend reading through the official documentation: https://docs.wpilib.org/en/stable/docs/software/commandbased/index.html
They explain pretty well how the command scheduler works and how you are supposed to structure your code.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.