I’ve been trying to use the limelight tx value (angle from center of limelight projection to center of note) to define a PID in order to rotate towards the note. I want to be able to align while moving with the xbox controller towards the note, so I didn’t create a completely separate command, but instead added onto the teleop swerve command.
While the AlignIntake command is on, (when X is pressed) it takes the angle value, calculates the PID and sets the vision subsystem instance variable rotationPID to it. The teleopswerve controls our drive method in our swerve from the xbox triggers. The drive rotation parameter for angular velocity in the teleop command also has a portion (rotation = … + VisionSubsystem.getRotationPID()), which adds the PID to the rotation when it is non-zero. This effectively should make it so that when alignintake is not called, this value is 0, and when it is called, the PID value takes on the PID we want for rotating to the note.
I’ve tested and debugged for 15+ hours, and found that it sets the rotationPID value correctly, but then when it is called in the Teleopswerve class it always returns 0. I’m not sure if this might also be an issue, but I’ve also noticed that the periodic in the vision subsystem times out a lot.
Any help as to why it is not working as intended would be so greatly appreciated!
Both AlignIntake and TeleopSwerve require the VisionSubsystem, which means they can’t run at the same time. I suggest you take vision out of the requirements of TeleopSwerve.
A couple of general principles:
Don’t require subsystems that you are merely reading, only those you are changing.
Never require a second subsystem in a default command.
Also keep in mind that vision is a sensor, not a mechanism. It can’t run any actions, only provide data, so it doesn’t make sense to model as a Subsystem.
While that’s true in general, in this case the class is also being used to store a state that is being updated by a command. If we had two different commands updating the same state (which we don’t), then it would make sense to prevent them from running at the same time.