So our code builds successfully and deploys successfully but when we pull up our drive station, communications are solid but the robot code light stays red. We also get this message in our RioLog:
“Robot should not quit, but yours did!
at frc.robot.Robot.robotInit(Robot.java:114)
The startCompetition() method (or methods called by it) should have handled the exception above.”
You should have a much more detailed exception message that should tell you exactly what threw an exception. If that line is the only message you got. Then you likely have an issue at like 114 in Robot.java where you are calling object that hasn’t been initialized correctly or something else of that nature.
It helps to upload your code to a website like GitHub and then link it here for more specific help.
The startCompetition() method (or methods called by it) should have handled the exception above.
at edu.wpi.first.hal.PWMJNI.initializePWMPort(Native Method)
at edu.wpi.first.wpilibj.PWM.(PWM.java:62)
at edu.wpi.first.wpilibj.PWMSpeedController.(PWMSpeedController.java:25)
at edu.wpi.first.wpilibj.Spark.(Spark.java:52)
at frc.robot.Robot.robotInit(Robot.java:114)
at edu.wpi.first.wpilibj.TimedRobot.startCompetition(TimedRobot.java:64)
at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:276)
at edu.wpi.first.wpilibj.RobotBase.startRobot(RobotBase.java:348)
at frc.robot.Main.main(Main.java:27)
Warning at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:291): Robots should not quit, but yours did!
Error at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:293): The startCompetition() method (or methods called by it) should have handled the exception above.
NT: server: client CONNECTED: 10.65.69.177 port 50763
This is what I am assuming is one run though of the error message.Here is the link to the code:
are called in programming parlance, Magic Numbers, and are considered poor practice - it’s hard to spot conflicts like the duplicates here, and to find constants buried in the code.
The preferred practice is to declare all the constants in one place:
final int intakePWM2value = 1;
final int shooter1PWMvalue = 2;
and when the speed controllers are instantiated:
Spark intakePWM2 = new Spark(intakePWM2value);
Spark shooter1 = new Spark(shooter1PWMvalue);
This has a couple advantages - first, it’s easier to spot duplicates, and it’s easier and safer to find and, if necessary, change a value if they’re all declared in one place, rather than look for a “1” buried in the code.
Larger programs often put all these constants in their own Class, named “Constants” or “RobotMap”, along with joystick and button numbers, etc.