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

Added Implementation of SparkMaxUtils.initWithRetry() #33

Merged
merged 7 commits into from
Nov 2, 2023

Conversation

avakimc
Copy link
Contributor

@avakimc avakimc commented Oct 21, 2023

No description provided.

- added errors += SparkMaxUtils.check() stuff to the initSparks() method in Arm, Grabber, SwerveModule
- added SparkMaxUtils.initWithRetry() line to each constructor in Arm, Grabber, SwerveModule
@@ -57,7 +60,7 @@ public enum ArmPosition {
ArmCal.ARM_MAX_ACCELERATION_DEG_PER_SECOND_SQUARED));

public Arm(ScoringLocationUtil scoreLoc) {

SparkMaxUtils.initWithRetry(this::initSparks, Calibrations.SPARK_INIT_RETRY_ATTEMPTS);
Copy link

Choose a reason for hiding this comment

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

Call in initialize

@@ -45,6 +46,8 @@ public SwerveModule(int drivingCanId, int turningCanId, double chassisAngularOff
turningSparkMax = new CANSparkMax(turningCanId, MotorType.kBrushless);
chassisAngularOffsetRadians = chassisAngularOffset;

SparkMaxUtils.initWithRetry(this::initDriveSpark, Calibrations.SPARK_INIT_RETRY_ATTEMPTS);
Copy link

Choose a reason for hiding this comment

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

Make an initialize function and call in there. Also call for the turnspark

Copy link

Choose a reason for hiding this comment

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

Also add a swerve system initialize function that call the initialize for all our modules

@@ -57,7 +60,7 @@ public enum ArmPosition {
ArmCal.ARM_MAX_ACCELERATION_DEG_PER_SECOND_SQUARED));

public Arm(ScoringLocationUtil scoreLoc) {

SparkMaxUtils.initWithRetry(this::initSparks, Calibrations.SPARK_INIT_RETRY_ATTEMPTS);
Copy link

Choose a reason for hiding this comment

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

Can you set SPARK_INIT_RETRY_ATTEMPTS to like 5 or something

@@ -57,7 +60,7 @@ public enum ArmPosition {
ArmCal.ARM_MAX_ACCELERATION_DEG_PER_SECOND_SQUARED));

public Arm(ScoringLocationUtil scoreLoc) {

this.initialize();
Copy link

Choose a reason for hiding this comment

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

These should not be called yet until a later point, called in robot container


// inverting stuff
armAbsoluteEncoder.setInverted(true);
errors += SparkMaxUtils.check(armEncoder.setInverted(true));
armMotor.setInverted(false);

// Get positions and degrees of elevator through encoder in inches
setDegreesFromGearRatioRelativeEncoder(armEncoder, ArmConstants.ARM_MOTOR_GEAR_RATIO);
Copy link

Choose a reason for hiding this comment

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

Do these return errors internally? Should be checked too

@@ -87,13 +87,21 @@ public class DriveSubsystem extends SubsystemBase {

/** Creates a new DriveSubsystem. */
public DriveSubsystem(Lights lightsSubsystem, BooleanSupplier isTimedMatchFunc) {
this.initialize();
Copy link

Choose a reason for hiding this comment

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

As before call in robot container

@@ -45,6 +46,8 @@ public SwerveModule(int drivingCanId, int turningCanId, double chassisAngularOff
turningSparkMax = new CANSparkMax(turningCanId, MotorType.kBrushless);
chassisAngularOffsetRadians = chassisAngularOffset;

this.initialize();
Copy link

Choose a reason for hiding this comment

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

This gets called by swerve subsystem

/** Does all the initialization for the spark */
void initTurnSpark() {
boolean initTurnSpark() {
int errors = 0;

turningSparkMax.restoreFactoryDefaults();
Copy link

Choose a reason for hiding this comment

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

check?

@@ -29,6 +31,11 @@ public class Grabber extends SubsystemBase {

public Grabber(Command rumbleBrieflyCmd) {
this.rumbleBriefly = rumbleBrieflyCmd;
this.initialize();
Copy link

Choose a reason for hiding this comment

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

Call in robot containe

int errors = 0;
errors += SparkMaxUtils.check(frontMotor.restoreFactoryDefaults());
errors += SparkMaxUtils.check(backMotor.restoreFactoryDefaults());
// backMotor.follow(frontMotor);
Copy link

Choose a reason for hiding this comment

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

Is this needed, why is it commented out

}

public static void setDegreesFromGearRatioRelativeEncoder(
RelativeEncoder sparkMaxEncoder, double ratio) {
public static int setDegreesFromGearRatioRelativeEncoder(
Copy link

Choose a reason for hiding this comment

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

Add comment what the return values are that you changed?

@avakimc
Copy link
Contributor Author

avakimc commented Nov 2, 2023

/format

@balghane balghane merged commit 0821b43 into main Nov 2, 2023
@avakimc avakimc deleted the minibot-testing branch November 9, 2023 00:29
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