I have encountered the dreaded “Resource Already allocated” error when working with Analog ports.
Sometimes an object gets created again when you don’t expect it or whatever.
Is there any way to force reallocate an analog port on the fly?
I’m using a RobotContainer so if I want to recreate it in Robot.java I get the error. If I create a new Analog(0) I want it to override it even if it happened before. Does that make sense?
I’ve done some searching but have not found anything specific.
You can’t force a re-allocation, but you can de-allocate by calling the close() method on the original object.
I would recommend structuring your code to make sure this doesn’t happen. The typical approach is to put the resources in subsystems and make sure you only create the subsystems once.
Agreed, and thank you for the quick and accurate response.
I’m using subsystems but working through an issue where motors seem to remember they are still on when returning from a “Disable” so I was recreating the RobotContainer, which recreates the subsystems. I guess I better rethink this a little.
Thanks again,
Petrie
Going to disabled mode just disables the electrical output of the motor controller, it does not set the software value to 0. You can still make set() calls in disabled mode, and the motor will move (if the value is non-zero) as soon as the robot is enabled. If you want to force the setting to 0, set them that way in disabledInit() or disabledPeriodic().
Yes, I’m building “StopAllMotors” into my RobotContainer and “StopMotors” in applicable subsystems. Then I can make the one call in disableInit().
Thanks again.
Petrie