Hello, my team has been having trouble getting the April Tag auto alignment to work. We got our code from the Limelight docs. The issue is that when we press a button, the swerves angle themselves to the April Tag, but they don’t move forward and the robot doesn’t rotate. However, we are looking for the ability to press a button to have the swerves rotate the robot towards the April Tag and have the driver manually drive up to it. We are using Limelight software. Here is our code; the auto-alignment function is in RobotContainer.java. Is there something we are doing incorrectly? Thank you for the help!
We are still trying to fix this issue, any help would be greatly appreciated!
What do you overwrite your xSpeed with forward_limelight if you want the driver to keep full control on location?
I would suggest using SwerveRequest.FieldCentricFacingAngle, that was what I switched to a couple weeks ago and it works great.
That was just a test to see if we could do the auto-align without the driver strafing, but that didn’t work either. Is it as simple as using a drive function with a translation2d for the Xbox controller inputs and the limelight’s tx value for the rotation? Here is what I did if that makes sense
public void execute() {
// if(NetworkTableInstance.getDefault().getTable("limelight").getEntry("tv").getBoolean() == NetworkTableInstance.getDefault().getTable("limelight").getEntry("tx").setInteger(7))
if(LimelightHelpers.getLatestResults("limelight") != null) {
//desiredStrafe = NetworkTableInstance.getDefault().getTable("limelight").getEntry("ty").getDouble(0);
heading = -NetworkTableInstance.getDefault().getTable("limelight").getEntry("tx").getDouble(0);
//Do we divide by something here?
}else{
heading = 0;
System.out.println("Failed to see target");
}
drive.drive(new Translation2d(Math.pow(translationX.getAsDouble(), 3) * Constants.SwerveConstants.maxSwerveSpeedMS,
Math.pow(translationY.getAsDouble(), 3) * Constants.SwerveConstants.maxSwerveSpeedMS),
heading * Constants.SwerveConstants.maxSwerveSpeedMS,
false);
Look at that file: FRC2495-2024/src/main/java/frc/robot/commands/drivetrain/DrivetrainDriveUsingAprilTagCamera.java at main · FRC2495/FRC2495-2024 (github.com)
Tweak it for the Limelight, and you should be good to go.
Since the amp is 90 degrees perpendicular to where the gyro says field-oriented forward is at the start of the match, are you saying that we could auto-align by telling the robot to turn 90 degrees from the field-oriented forward direction? That would be a smart way of auto-aligning without vision
Will do, thanks! Do you know why the angle is divided by 90 here?
drivetrain.drive(
-MathUtil.applyDeadband(joystick.getY(), JOYSTICK_AXIS_THRESHOLD),
-MathUtil.applyDeadband(joystick.getX(), JOYSTICK_AXIS_THRESHOLD),
-angle/90.00,
true, true);
To normalize. Adjust as you want.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.