PWMSparkmax Resource already allocated problem

Hello, our code is having problem with our shootout and roller mechanism. We did look up the problem and from what I have learned is that it is related to duplicate of the code. However, I thoroughly looked at it and there is actually no duplicate I could find. We’re using PWMSparkmax speed controller.

our code

Output:

NT: server: client CONNECTED: 10.65.93.172 port 56901
Error at frc.robot.subsystems.ShootOut.<init>(ShootOut.java:16): Unhandled exception: edu.wpi.first.hal.util.UncleanStatusException: Code: -1029. HAL: Resource already allocated
at edu.wpi.first.hal.PWMJNI.initializePWMPort(Native Method)
at edu.wpi.first.wpilibj.PWM.<init>(PWM.java:62)
at edu.wpi.first.wpilibj.PWMSpeedController.<init>(PWMSpeedController.java:25)
at edu.wpi.first.wpilibj.PWMSparkMax.<init>(PWMSparkMax.java:37)
at frc.robot.subsystems.ShootOut.<init>(ShootOut.java:16)
at frc.robot.commands.ShootOut.ShootOutInverseRolling.<init>(ShootOutInverseRolling.java:14)
at frc.robot.RobotContainer.<init>(RobotContainer.java:71)
at frc.robot.Robot.robotInit(Robot.java:21)
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:10)
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.
Unhandled exception: edu.wpi.first.hal.util.UncleanStatusException: Code: -1029. HAL: Resource already allocated
Robots should not quit, but yours did!
The startCompetition() method (or methods called by it) should have handled the exception above.

In each of your ShootOut Commands (ShootOutInverseRolling, ShootOutStartRolling, ShootOutStop) you are initializing a new ShootOut object private ShootOut so = new ShootOut();. Each ShootOut object would then each initialize their own PWMSparkMax SO_Motor. So you are allocating the same resource 4 times (in each of 3 commands, plus in your RobotContainer).

Instead you should only be initializing a single ShootOut object in RobotContainer and passing the object to each Command through their Constructor. Which, to be fair, you have coded for, but only after each command also initializes their own ShootOut object.

EDIT: You are also doing the same thing in your commands for your IntakeRollers, but not for your TurnTable and Drive Commands.

2 Likes

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