Anyway to run teleop commands that use the same subsystem

Hey All!

Mentor on Team 904 here,

Trying to switch over to Command-Based Programming this year, running into some issues. Mostly with our shooting/intake mechanism. So, our intake and shoot mechanism are the same subsystem. But, they require different speeds/directions depending on the task at hand. We could just program it in a timed robot format, and make a combo-wombo-timed-command robot, but I’d prefer if we didn’t do that.

The issue we are running into is when we try to create multiple commands that run on the same subsystem, even if its not in use. I was hoping that we could use the WhileTrue function, and it wouldn’t cause any issues as long as neither were true at the same time. However, it very much didn’t (the code won’t even run in the simulator). What pops up in the RoboRIO log is something along the lines of "an instance already exists, cannot create a new instance of SparkMAX 13, 14, 15 ".

Is there any possible way for us to accomplish this?? eventually, I’d like to have the students program a Command sequence that and flip the shooter into place (via pneumatic cylinder), whether it be the intake position or the shooting position. and the runs the intake/shooter. but right now, we need a way to run both the intake or the shooter in the way that they are both in command format (again, i know that we could program it like a timed robot, but I’d prefer if we didn’t for the sake of keeping everything in the same format).

You could split the intake and shooter into their own subsystem, and then create a command that sets both of them.

4 Likes

This seems like you’re dual-allocating your subsystem hardware, which is a different problem entirely.

2 Likes

This. That error only pops up if you try to initialize a SPARK Max on an ID that’s already taken. Are you initializing the same subsystem class twice? That won’t work and would cause this error.

I also second the notion to split your subsystems further. Commands can take more than one subsystem. The general purpose of the subsystem structure is to prevent different commands from accessing the same actuators at the same time. If the needs of one group of actuators can change independently of another, it generally makes sense to separate them from each other, even if they do work together on some tasks.

4 Likes