Skip to content

Pivot#3

Open
barbute wants to merge 28 commits intoproductionfrom
pivot
Open

Pivot#3
barbute wants to merge 28 commits intoproductionfrom
pivot

Conversation

@barbute
Copy link
Copy Markdown
Contributor

@barbute barbute commented Oct 28, 2024

Pivot code to review

@barbute barbute requested a review from mduffor October 28, 2024 23:49
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Generally one should avoid checking in editor preferences/settings into code repos.

// NOTE The configuration only needs to be applied to the leader-motor. The
// follower-motor MUST obey the configuration of the leader-motor.
public static final KrakenConfiguration kMotorConfiguration =
new KrakenConfiguration(true, true, 0.0, 0.0, NeutralModeValue.Brake, false, 0.0, 0.0);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When you have a lot of settings like this (and below with PivotGains) it is useful to line them up vertically, and place an end-of-line comment after each entry telling what the setting is.

configureBindings();
}

private void configureBindings() {}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In the trunk we'll want to put the code block brackets on their own lines so that the templates can insert their lines between the curly brackets.

import frc.robot.subsystems.pivot.PivotKrakenHardware;

public class RobotContainer {
private final Pivot kPivot =
Copy link
Copy Markdown
Contributor

@mduffor mduffor Nov 2, 2024

Choose a reason for hiding this comment

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

We wouldn't use the name "kPivot" because this isn't a constant. We can call it just "pivot", or perhaps "mPivot" if you like the m == instance variable naming scheme.

m - Instance (method) variable
k - Constant (Konstant :-) )
s - Static variable
g - Global variable

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This still needs to be addressed

supplyCurrentAmps = List.of(kLeadMotor.getSupplyCurrent(), kFollowMotor.getSupplyCurrent());
temperatureCelsius = List.of(kLeadMotor.getDeviceTemp(), kFollowMotor.getDeviceTemp());

BaseStatusSignal.setUpdateFrequencyForAll(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think I understand what this is doing, but it's a bit obtuse. We probably need a quick description of Status Signals above, or perhaps a link to the docs. This is also the only place in the code I've seen the use of an ellipsis method signature, and rookie coders will likely be thrown off by it.

}

// Hardware is where we interact with the motors and sensors directly
private final PivotKrakenHardware kPivotHardware;
Copy link
Copy Markdown
Contributor

@mduffor mduffor Nov 5, 2024

Choose a reason for hiding this comment

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

This would have an 'm' prefix, not 'k', since its state can change. Same with kPivotInputs.
So we'd have mPivotHardware, mPivotInputs, mCurrentPivotGoal, and mCurrentPivotGoalPosition.

private PivotGoal currentPivotGoal = null;

@AutoLogOutput(key = "Pivot/CurrentGoalPosition")
private Rotation2d currentPivotGoalPosition = new Rotation2d();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would this variable be better named with Rotation instead of Position?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Typically any set point for control over a "position" has the suffix "position" regardless of it being for linear or angular movement (or at least that should be a team standard).

@@ -0,0 +1,123 @@
// Copyright (c) 2024 FRC 6328
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When we pull a class in from another repo, we should include a link back to the original file. This will allow us to find the file in case there are bug fixes or we need to track down better documentation.

@@ -0,0 +1,26 @@
// Copyright (c) FIRST and other WPILib contributors.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here, we should give a link to the original file. I've added comments to Anshul's use of this file, and I've rolled it into the BaseCode, so I won't repeat those comments here.

setPosition(currentPivotGoalPosition.getRadians());
}

// Update feedback, feedforward, and motion magic gains if we change them from network tables
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is another place where an ellipsed method signature is used, so the role of this function isn't immediately evident to someone new to the code. A comment to guide readers would help.

temperatureCelsius.get(1));

// Optimize the CANBus utilization by explicitly telling all CAN signals we
// are not using to simply not be sent over the CANBus
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You should describe why you are passing 0 and 1, or at least use comments to give an idea of what is being passed. I assume this is the call?
https://api.ctr-electronics.com/phoenix6/release/java/com/ctre/phoenix6/hardware/ParentDevice.html#optimizeBusUtilization()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Since this code is meant to work with an arm design similar to Redux (where there are two motors working together to move a mass) some of the telemetry data will be the same. Status signals are how we get that telemetry data from a TalonFX motor controller - and it's more convenient to store them in objects that can be accessed throughout the class.

Knowing this, the internal position and velocity of the two motors must be the same (since they are mechanically linked to the arm) however the applied volts, supply current draw, and temperature would be different for the motors. So to log them more conveniently, I store them in a list where index 0 is the leader motor and index 1 is the follower motor. When setting the update frequency at which telemetry to be set, every status signal that I wish to modify must be passed into the method so I call both the leader's (0) and the follower's (1) status signals. I can add documentation if it's not clear in the code that this was just a way of conveniently storing the status signals.

* @param v The new voltage gain
* @param a The new acceleration gain
* @param g The new gravity gain
*/
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Eventually we'll need docs or links on how to solve for kS, kV, kA, and kG.

@mduffor mduffor self-requested a review November 5, 2024 00:48
@mduffor
Copy link
Copy Markdown
Contributor

mduffor commented Nov 24, 2024

@barbute , have you looked over and addressed all the comments in this review yet?

import frc.robot.subsystems.pivot.PivotKrakenHardware;

public class RobotContainer {
private final Pivot kPivot =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This still needs to be addressed

Add custom setpoint

Fully tuned arm

Add soft limits for voltage control
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.

2 participants