Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limelight megatag2 #73

Merged
merged 12 commits into from
Jun 14, 2024
Merged

Limelight megatag2 #73

merged 12 commits into from
Jun 14, 2024

Conversation

stwiggy
Copy link
Contributor

@stwiggy stwiggy commented Jun 12, 2024

created megatag2 alternatives to existing shooter limelight methods and commands

@stwiggy stwiggy requested a review from a team as a code owner June 12, 2024 17:10
Copy link
Contributor

@ProfessorAtomicManiac ProfessorAtomicManiac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very epic, but there are a few issues

@@ -201,7 +201,7 @@ private void setBindingsDriver() {
.onTrue(new RotateToFieldRelativeAngle(Rotation2d.fromDegrees(90), drivetrain));
}
private void setBindingsManipulatorNEO() {
new JoystickButton(manipulatorController, EJECT_BUTTON).onTrue(new Eject(intakeShooter));
new JoystickButton(manipulatorController, EJECT_BUTTON).whileTrue(new AlignToNote(drivetrain)); // test

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't ever add a binding for the new AimArmSpeaker commands. Before that though, you should probably discuss with manipulator + driver on how they want to be able to auto-aim. IMO, if I was driver, it would be convenient to have a single button that can be held down that simultaneously aims the robot while moving the arm, then LEDs flash to tell me the shooter is ready to shoot, and I press another button.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it turns out that megatags work just fine, I highly recommend getting rid of old methods to reduce clutter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do after testing

src/main/java/org/carlmontrobotics/Constants.java Outdated Show resolved Hide resolved
double targetX = targetPoseRobotSpace.getX(); // the forward offset between the center of the robot and target
double targetY = targetPoseRobotSpace.getY(); // the sideways offset

double targetOffsetRads = Math.atan2(targetY, targetX);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double check that the signs are correct (to be clear, idk if they are correct, but people not understanding the coordinate system has caused bugs in the past)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what signs?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on the robot, left and right and forward and backward are sometimes swapped and rotated. Not that I remember which way the signs are, off the top of my head. Ask Big Brettle for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'll flip signs if necessary after testing 🤷

Copy link
Member

@CoolSpy3 CoolSpy3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Just a couple of minor notes.

src/main/java/org/carlmontrobotics/Constants.java Outdated Show resolved Hide resolved
Comment on lines +112 to 116
public double getRotateAngleRad() {
double cameraLensHorizontalOffset = getTXDeg(SHOOTER_LL_NAME) / getDistanceToSpeakerMeters();
double realHorizontalOffset = Math.atan(cameraLensHorizontalOffset / getDistanceToSpeakerMeters());
return Math.atan(realHorizontalOffset / getDistanceToSpeakerMeters());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this falls under the scope of this PR, but something's weird with this math.

double cameraLensHorizontalOffset = Deg / Meters;
double realHorizontalOffset = atan(deg/m^2); // Arguments passed to atan should almost always be unitless
return atan(rad/m); // Arguments passed to atan should almost always be unitless

If this is something that would be better addressed in a different PR, feel free to ignore this comment, and I can just open an issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, seems like the second involvement of meters should be outside a normal tangent, not an arctan?
Something like that, I second this possible issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if megatags work though, you don't have to do all this math. I'd say we see if megatags work and if so, we can probably scrap the math.

Comment on lines +112 to 116
public double getRotateAngleRad() {
double cameraLensHorizontalOffset = getTXDeg(SHOOTER_LL_NAME) / getDistanceToSpeakerMeters();
double realHorizontalOffset = Math.atan(cameraLensHorizontalOffset / getDistanceToSpeakerMeters());
return Math.atan(realHorizontalOffset / getDistanceToSpeakerMeters());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, seems like the second involvement of meters should be outside a normal tangent, not an arctan?
Something like that, I second this possible issue.

double targetX = targetPoseRobotSpace.getX(); // the forward offset between the center of the robot and target
double targetY = targetPoseRobotSpace.getY(); // the sideways offset

double targetOffsetRads = Math.atan2(targetY, targetX);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on the robot, left and right and forward and backward are sometimes swapped and rotated. Not that I remember which way the signs are, off the top of my head. Ask Big Brettle for that.

Copy link
Contributor

@ProfessorAtomicManiac ProfessorAtomicManiac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will double check the math in a bit but overall looks good to me

public static final double HEIGHT_FROM_GROUND_METERS_INTAKE = Units.inchesToMeters(52); // 16.6
public static final double ARM_TO_OUTTAKE_OFFSET_DEG = 115;
public static final double NOTE_HEIGHT = Units.inchesToMeters(0);
public static final int[] VALID_IDS = { 4, 7 };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make it clearer, instead of writing 4 use RED_SPEAKER_CENTER_TAG_ID and similarly for 7

double x = targetPoseRobotSpace.getX();
double y = targetPoseRobotSpace.getY();

return Math.sqrt(x * x + y * y);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wanted to mention Math.hypot exists. It's probably the same either way

else {
// SmartDashboard.putNumber("limelight distance", -1);
return -1;
}
}


public double getDistanceToNoteMeters() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is within the context of this PR, but I'm pretty sure this only calculates the distance between the note and camera in the y direction relative to the robot, it doesn't account for the tx measurement from Limelight.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly for getDistanceToSpeakerMeters. However if it turns out Megatags work just fine, you can probably just get rid of these methods except for the note one (you could make the note method use Megatags)

Comment on lines +112 to 116
public double getRotateAngleRad() {
double cameraLensHorizontalOffset = getTXDeg(SHOOTER_LL_NAME) / getDistanceToSpeakerMeters();
double realHorizontalOffset = Math.atan(cameraLensHorizontalOffset / getDistanceToSpeakerMeters());
return Math.atan(realHorizontalOffset / getDistanceToSpeakerMeters());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if megatags work though, you don't have to do all this math. I'd say we see if megatags work and if so, we can probably scrap the math.

Copy link
Member

@CoolSpy3 CoolSpy3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving on behalf of @ProfessorAtomicManiac .

@CoolSpy3 CoolSpy3 dismissed ProfessorAtomicManiac’s stale review June 14, 2024 01:28

@ProfessorAtomicManiac has approved these changes and requested that I merge this on his behalf

@CoolSpy3 CoolSpy3 merged commit 336ca7c into master Jun 14, 2024
1 check passed
@CoolSpy3 CoolSpy3 deleted the limelight-megatag2 branch June 14, 2024 01:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants