Running two commands in parallel causing weird issues

Hey all, I’m currently working on speeding up our auton, and seem to be running into a weird issue.
I’m attempting to run two commands together with the .alongWith() method, but every time it goes to run the program crashes and states that “Multiple commands in a parallel composition cannot require the same subsystems” Now, the two commands it’s trying to run use seperate subsystems, so I’m not sure where this error is coming from.

The code in question is in our RobotContainer.java file at line number #143.

Am I missing something here? Or is this just not meant to do what I thought it was meant to do?

Github is down below so you can feel free to take a look at the code. Thanks! It will be in branch “2-subsystem-request-arm”

Can u paste the stack trace?

1 Like

I beleive this should contain what you’re looking for. It’s what I could find in the Log Viewer.

9:43:13.096 AM
ERROR  1  The startCompetition() method (or methods called by it) should have handled the exception above.  edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:365)    See https://wpilib.org/stacktrace for more information.    The above stacktrace can help determine where the error occurred.  Warning at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:358): The robot program quit unexpectedly. This is usually due to a code error.    	at frc.robot.Main.main(Main.java:23)  	at edu.wpi.first.wpilibj.RobotBase.startRobot(RobotBase.java:433)  	at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:343)  	at edu.wpi.first.wpilibj.TimedRobot.startCompetition(TimedRobot.java:130)  	at edu.wpi.first.wpilibj.IterativeRobotBase.loopFunc(IterativeRobotBase.java:320)  	at frc.robot.Robot.autonomousInit(Robot.java:59)  	at frc.robot.RobotContainer.getAutonomousCommand(RobotContainer.java:148)  	at edu.wpi.first.wpilibj2.command.Command.alongWith(Command.java:226)  	at edu.wpi.first.wpilibj2.command.ParallelCommandGroup.addCommands(ParallelCommandGroup.java:49) Warning  1  The robot program quit unexpectedly. This is usually due to a code error.
  The above stacktrace can help determine where the error occurred.
  See https://wpilib.org/stacktrace for more information.  edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:358)  Error at frc.robot.RobotContainer.getAutonomousCommand(RobotContainer.java:148): Unhandled exception: java.lang.IllegalArgumentException: Multiple commands in a parallel composition cannot require the same subsystems 

I don’t see a line 143 in your RobotContainer it only has 122 lines. did you not commit and push your changes?

There’s also this but it looks like more of the same. It’s all that seems to be in there.

9:43:13.058 AM
ERROR  1  Unhandled exception: java.lang.IllegalArgumentException: Multiple commands in a parallel composition cannot require the same subsystems  frc.robot.RobotContainer.getAutonomousCommand(RobotContainer.java:148) 

My bad, it’s in the branch “2-subsystem-request-arm”

The error is a java.lang.IllegalArgumentException

It happened on line 148 in file RobotContainer.java

The exception states that Multiple commands in a parallel composition cannot require the same subsystems.

It would appear that, by the time your code is on line 148, you’ve created a parallel composition of commands, but multiple of those require the same subsystem. This is not supported.

You’ll want to rework your subsystem & command architecture to avoid this. Whatever you change needs to impact code functionality in a way that prevents the situation on 148 that triggered the error.

See https://wpilib.org/stacktrace for more information.

Would 100% recommend clicking the link and going through the info there for more info.

Alright, I’ll read through it again. The main thing is that in order for it to hit that code, the first part of it should have completed by then. It is chained in a .andThen() afterwards.

While this isn’t an exact answer to your problem, in the future I would definitely suggest taking a look at Command Groups . It will allow you to better organize all your commands together for autonomous action (which may happen in autonomous or teleop mode).

There’s an inconsistency in how the parenthesis line up right around that line. I’m not great at following command based logic, but it might be something to look at.

Yes that looks like the culprit. The .alongWith needs to be within the .andThen or else it’s in parallel with everything above it which would be the conflict.

1 Like

TiltToPoint and ExtendToPoint both require the arm extension subsystem, so you can’t do them alongWith each other.

EDIT: Misread that command, rest of the post still stands though.

In general when composing commands like this, it helps to make intermediate variables for any parallel actions, just to give it some logical groupings. So if you had an auto that wanted to drive while extending an arm, and then place a cone, you would do

var driveAndExtend = new DriveDistanceCommand().alongWith(new ExtendArmCommand());
var autoCommand = driveAndExtend.andThen(new PlaceConeCommand());

rather than the big one liner:

var autoCommand = new DriveDistanceCommand().alongWith(new ExtendArmCommand()).andThen(new PlaceConeCommand());

It makes it more obvious which parts are supposed to run in parallel.

I can try that and see if it fixes it. That makes total sense to me. I’d love to test it now, but I just accidently broke the wire that pulls back the extension. Whoops :smiley:

Those two commands do not run the same subsystem. While named simallarly, one uses “Arm” which is the tilt mech, and one uses “ArmExt” which is the arm extension. They were origionally combined into the one “Arm” subsystem. But were seperated once I started working on this issue.

1 Like

I’ll follow up and mark this as the solution once I can test that all is right. Thank you so much for your help!

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