Trouble with automatic alignment to notes (I'm going insane with debugging please help)

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!

Here is my code:

bigbog.zip (28.4 KB)

Github link:

I would put this in GitHub, it’s a little easier for people to read. Let me take a look to see if I can find anything wrong.

I have an idea, but I just want to see how you’re sending it between the two commands

2 Likes

Thank you!

Insert right before you call s_Swerve.drive

DataLogManager.log(“PID: “ + PIDIntake + “ rAxis: “ + rAxis);

What results does it give you?

@Hollisms
Where can I see the result?

Drivestation message box

Got it. Will check first thing tmrw morning and write back.

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.
3 Likes

I cannot stress enough how thankful I am. It worked magically!

3 Likes

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.

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