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

Advantagekit implementation v2 #27

Open
wants to merge 17 commits into
base: rev4
Choose a base branch
from

Conversation

arghunter
Copy link
Contributor

Implementation of advantagekit with minor code changes Logs most of what we need.

Copy link

@adias408 adias408 left a comment

Choose a reason for hiding this comment

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

Looks like it's headed in the right direction. I think there are some cleanups we can make to avoid creating unnecessary garbage and we also ought to define a naming convention, particularly since this will be used as a template for next year

@@ -43,7 +44,7 @@ def deployArtifact = deploy.targets.roborio.artifacts.frcJava
wpi.java.debugJni = false

// Set this to true to enable desktop support.
def includeDesktopSupport = false
def includeDesktopSupport = true

Choose a reason for hiding this comment

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

just curious: why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was changed to enable robot simulation on desktop. Doesn't really impact the robot, however, our code isn't formatted for simulation yet. I'll change to back to false .

@@ -15,20 +16,20 @@
import frc.team670.robot.commands.arm.MoveToTarget;
import frc.team670.robot.commands.claw.ClawEject;
import frc.team670.robot.commands.claw.ClawInstantIntake;
import frc.team670.robot.commands.cubeintake.CubeIntakeEject;
import frc.team670.robot.commands.cubeintake.CubeIntakeIntake;
import frc.team670.robot.commands.cubeintake.CubeIntakeToggle;

Choose a reason for hiding this comment

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

this looks like just some reordering of imports. Which doesn't hurt anything but is noise in the context of this PR. Let's get in the habit of not doing unrelated things

@@ -26,8 +29,8 @@ public enum GamePiece{
private Claw.Status status;
private Claw.GamePiece gamepiece=Claw.GamePiece.CONE;

private final String currentKey = "Claw motor current";
private final String clawStateKey = "Claw state";
private final String currentKey = "Claw/motor current";

Choose a reason for hiding this comment

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

Yes! :)

However: isn't the java naming convention such that this should be CURRENT_KEY?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Since we switched to Hungarian notation would be be kCurrentKey or CURRENT_KEY

Choose a reason for hiding this comment

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

About that: we haven't really switch to Hungarian notation. We currently have a mess where some things are hungarian-ish and a lot of things aren't. The only PRs I've seen using Hungarian have been yours. This isn't something that we should be doing without a conversation and general agreement. I'll tell you that in the wider world, Hungarian had a moment a couple of decades ago but has mostly gone out of style. In particular with IDEs, ask yourself what it's adding.

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 was under the impression the prior tech leads switched most parts of our codebase to Hungarian notation. I prefer the default java naming convention. What do you recommend we do?

Choose a reason for hiding this comment

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

Fair enough - I'm not sure when it started creeping in. I've just been noticing more of it. I still think most of our code uses normal java naming conventions. I'd personally prefer to stick with that but the more important thing is that we agree and then new code conforms to whatever that agreement is. Most organizations have a style guide. Or rather: most organizations refer to an existing style guide and maybe have a few local variations that they define. This is the one we had some years back: https://docs.google.com/document/d/1rrgTm2BNigiYZ8PDRLJEujGYzFkO1Sl5vrtekVEq2RY/edit#heading=h.u6ednqa8ivih (found a link here: https://github.com/HHS-Team670/2019-Robot/wiki/GitHub-Code-Review-Process). Here's another one: https://google.github.io/styleguide/javaguide.html

But really the most important thing is let's agree and then let's enforce it through code reviews so that things don't just start changing because someone starts doing things and nobody pays attention.

@@ -200,8 +203,8 @@ public void mustangPeriodic() {

@Override
public void debugSubsystem() {
SmartDashboard.putNumber(currentKey, motor.getOutputCurrent());
SmartDashboard.putString(clawStateKey, status.toString());
Logger.getInstance().recordOutput(currentKey, motor.getOutputCurrent());

Choose a reason for hiding this comment

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

don't call getInstance() more than you need to

Choose a reason for hiding this comment

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

Have you seen the 2024 version of the library?

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 managed to find the new version of AdvantageScope but not the beta version of AdvantageKit, I'll take a look soon.

Choose a reason for hiding this comment

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

I was just mentioning it because all this getInstance() stuff will go away

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, then i'll leave it like this for now and then change it when we update to 2024 advantagekit.

double transformedShoulderAngle=getShoulder().getCurrentAngleInDegrees()-90;
double transformedElbowAngle= -(transformedShoulderAngle-getElbow().getCurrentAngleInDegrees()+90);
double transformedWristAngle= -transformedElbowAngle+getWrist().getCurrentAngleInDegrees();
MechanismLigament2d shoulderLig = m2dr.append(new MechanismLigament2d("Shoulder", 0.66,transformedShoulderAngle));

Choose a reason for hiding this comment

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

we should get a sense for how expensive this is. unclear whether it's worth it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, I'll move it into the debug subsystem method with a separate boolean for if this should be logged so that it is toggleable.

private final String current = "Elbow current";
private final String positionDeg = "Elbow/position (deg)";
private final String absEncoderPos = "Elbow/abs encoder position";
private final String positionRot = "Elbow/position (rotations)";

Choose a reason for hiding this comment

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

more of the same boilerplate comments about constant naming, calling a function repeatedly, etc.

Also: we should spend some time on naming conventions as we're likely to have a bunch of the same kinds of keys and it gets to be very annoying if they're named slightly differently. For example: above, we have "position (deg)" and then we have "abs encoder position" - two positions, one of which specifies a unit and one of which doesn't.

Usually people avoid spaces in these kinds of keys. It makes it easier to know how to read them. And they generally wouldn't use parentheses either. You generally either use snake_case or camelCase. And you always include units where appropriate and if you have units then you make sure you name them the same so it's not deg sometimes and degs other times and degrees still somewhere else. So one possibility could be something like:
motor_position_degrees
abs_encoder_rotations
motor_position_rotations

or something

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 establish a naing convention over the weekend

Choose a reason for hiding this comment

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

I never saw any followup on this. It's something the team as a whole will have to use. I'd expect to see a written proposal and then some discussion to settle on something we'll use.

@@ -92,9 +95,9 @@ public HealthState checkHealth() {
boolean followerOK = (followerRotatorError == REVLibError.kOk);

if (!leaderOK && !followerOK) {
Logger.consoleLog("Shoulder error! Leader error is " + leaderRotatorError.toString());

Choose a reason for hiding this comment

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

why do we want to get rid of this?

Choose a reason for hiding this comment

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

also: why are we not recording the errors to the new spiffy logger?

@@ -44,7 +45,7 @@ public VoltageCalculator(ArmSegment... armSegments) {
public ArrayList<Double> calculateVoltages(double... anglesRelativeToPrevious) {
// First, ensure that the number of received angles is correct
if(anglesRelativeToPrevious.length != armSegments.length) {
Logger.consoleError("VoltageCalculator received the wrong number of angles! Received " + anglesRelativeToPrevious.length + " but expected " + armSegments.length);
// Logger.consoleError("VoltageCalculator received the wrong number of angles! Received " + anglesRelativeToPrevious.length + " but expected " + armSegments.length);

Choose a reason for hiding this comment

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

this seems like a catastrophic logic error. why are we silencing it?

@@ -70,7 +71,7 @@ public ArrayList<Double> calculateVoltages(double... anglesRelativeToPrevious) {

}

SmartDashboard.putString(voltageString, voltages.toString());
Logger.getInstance().recordOutput("Arm/"+voltageString, voltages.toString());

Choose a reason for hiding this comment

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

would it be more useful if we recorded each of the voltages independently? (no idea, just asking)

@arghunter
Copy link
Contributor Author

Note to self: add swerve module logging

@arghunter
Copy link
Contributor Author

Also, this branch was well tested today at drive practice and seems to work pretty well.

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.

4 participants