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”
I beleive this should contain what you’re looking for. It’s what I could find in the Log Viewer.
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
There’s also this but it looks like more of the same. It’s all that seems to be in there.
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)
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).
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.
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.