we were just testing our code for the color sensor. We have two buttons that schedule the command when we press them:
@Override
public void teleopInit() {
container.initTeleopCommands();
leftStick.getButton5().whenPressed(new SpinWheelThreeTimes(), false);
leftStick.getButton6().whenPressed(new SpinToColor(), false);
}
@Override
public void teleopPeriodic() {
CommandScheduler.getInstance().run();
}
pressing button 6 will always run fine, however when we try to run button 5, the code will always crash with this exception ConcurrentModificationException. I don’t currently have the laptop with the stacktrace with me, however it was pretty similar to this thread. However the stacktrace looked something like this from the best of my memory:
Error at java.base/java.util.LinkedHashMap$LinkedHashIterator.nextNode(LinkedHashMap.java:719): Unhandled exception: java.util.ConcurrentModificationException
at java.base/java.util.LinkedHashMap$LinkedHashIterator.nextNode(LinkedHashMap.java:719)
at java.base/java.util.LinkedHashMap$LinkedKeyIterator.next(LinkedHashMap.java:741)
at edu.wpi.first.wpilibj2.command.CommandScheduler.run(CommandScheduler.java:243)
at com.rambots4571.infiniterecharge.robot.Robot.teleopPeriodic(Robot.java:49)
at edu.wpi.first.wpilibj.IterativeRobotBase.loopFunc(IterativeRobotBase.java:220)
at edu.wpi.first.wpilibj.TimedRobot.startCompetition(TimedRobot.java:82)
at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:276)
at edu.wpi.first.wpilibj.RobotBase.lambda$startRobot$0(RobotBase.java:329)
at java.base/java.lang.Thread.run(Thread.java:834)
Both commands use the same subsystem, I even tried to remove the addRequirements() from both of the commands to see fi that was the problem. But that didn’t stop it. The only way we managed to get it working is by commenting out the button 6 command, so button 5 would work:
@Override
public void teleopInit() {
container.initTeleopCommands();
leftStick.getButton5().whenPressed(new SpinWheelThreeTimes(), false);
// leftStick.getButton6().whenPressed(new SpinToColor(), false);
}
@Override
public void teleopPeriodic() {
CommandScheduler.getInstance().run();
}
We are currently running this with the WPILIB 2020.2.2 version
you can view the full project here