Skip to content

Stage 2 CTRE Solution Code - #175

Draft
roboteer5291 wants to merge 4 commits into
frcsoftware:mainfrom
roboteer5291:stage2-ctre-solution
Draft

Stage 2 CTRE Solution Code#175
roboteer5291 wants to merge 4 commits into
frcsoftware:mainfrom
roboteer5291:stage2-ctre-solution

Conversation

@roboteer5291

@roboteer5291 roboteer5291 commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Creates stage 2 CTRE Solution Code. Still very much a WIP

Todo:

  • Add AdvantageScope model and rig
  • Create intake and indexer mechanisms
  • Add sensor simulation (indexer and claw)
  • Add coral on reef visualization for AdvantageScope
  • Create a fully-featured coral-only teleop utilizing a state machine
  • Validate and clean up AutoAlignCommand code
  • Create a basic auto mode (no vision, assume coral is at same position on ground)
  • Evaluate whether the initial teleops (BasicScoringTeleop and FullScoringTeleop) are at the correct level or if they should be simpler
  • Lint and format
  • Setup copybara and repo
  • Final pass through all code for cleanliness, appropriate commenting, and any bad habits
  • Replace DogLog with the Telemetry API
  • Add Tunable support for setpoint tuning
  • Update to alpha 7 controllers

@roboteer5291 roboteer5291 added CTRE Anything starter code or curriculum material touching CTRE libraries Starter Code Code for students to build on - Java, WPILib, etc Stage 2 labels Aug 4, 2026
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

🌐 Preview URL: https://pr-175.frcsoftware.pages.dev

@Daniel1464 Daniel1464 left a comment

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 know this is still a draft, but left some preliminary comments since i have time

"enableCppIntellisense": false,
"currentLanguage": "java",
"projectYear": "2027_alpha5",
"teamNumber": 9999

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.

Small nitpick, but you can set this to null instead.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Set what?

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.

Sorry, the team number

static final double kI = 0;
static final double kD = 7;

static final double POSITION_TOLERANCE = 3.0/360.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.

Would this be better served using the units API? Degrees.of(3) would be a lot more clear here

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Changed to use Units.degreesToRotations instead. Since we aren't using the units API anywhere else really, I don't think it'd make sense to have it for this.

Comment thread examples/stage2/templates/ctre/src/main/java/first/robot/mechanisms/Arm.java Outdated
motor.getConfigurator().apply(leaderConfiguration);

// Set up periodic method to run every code loop
Scheduler.getDefault().addPeriodic(this::periodic);

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 previous exercises, mechanism.periodic() is called manually in robotPeriodic(). Personally I think it's slightly better because it gives you control as to when the periodic() method is run


private final FlywheelSim sim;

private final double GEAR_RATIO = (18.0 / 12.0) * (54.0 / 18.0) * (22.0 / 18.0) * (22.0 / 18.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.

It would be better to make the gear ratio a parameter of ClawSim so that users can play around with different gear ratios

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

What value does this get in terms of teaching frc programming?

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown

🌐 Preview URL: https://pr-175-frcsoftware.frcsoftware.workers.dev

* @return whether the arm is at that positoin
*/
public boolean isAtPosition(double position) {
return Math.abs(getPosition() - position) < Constants.POSITION_TOLERANCE;

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.

Why not get the closed loop error status signal?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This checks whether the arm is at a given position (ie is vertical) rather than whether it's at its setpoint. In a lot of cases they're the same thing, but I have run into cases where "at setpoint" isn't good enough. May not be necessary in this code (I'm actually thinking with state machines/v3 it won't be in general), but I guess that's just how I wrote it initially. I'll leave this open so I can come back and check it once I have more code done.

* @param voltage the voltage to apply to the motor
* @return a command
*/
public Command setVoltage(double voltage) {

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.

Why would you need open loop control on an arm?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I don't think you would in this case, but for a homing sequence or the like it may be useful. It's just something I tend to include in all mechanisms, may not be useful here

Comment on lines +168 to +173
/**
* @return the velocity of the elevator, in meters per second
*/
public double getVelocity() {
return velocitySignal.getValueAsDouble() * Constants.PULLEY_CIRCUMFERENCE;
}

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.

Is this a useful measurement to have?

public Superstructure(Elevator elevator, Arm arm) {
this.elevator = elevator;
this.arm = arm;
}

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.

How 'perfect' should this code be? As shown already, Elevator and Arm aren't really separate Mechanisms, they're just wrappers around a subset of motors in the one real Mechanism, the superstructure. The elevator and arm would never be commanded on their own, only via the superstructure to ensure proper coordination.

There are a couple of things necessary to do this 'correctly' from a software engineering pov:

  1. don't make elevator and arm implement Mechanism. They have no need, since they never interact with the scheduler (at least, they shouldn't).
  2. Make them package private, and only make the superstructure a public class, so that external classes cannot interact with them. They should always go through the superstructure, since that's the Mechanism, and Elevator and Arm are just abstractions because they mimic how we talk about the robots physical components. Software shouldn't care about whether they're elevator and arm, or a single superstructure, and hiding that abstraction prevents you from writing code that relies on this specific implementation of superstructure that is arbitrary

I understand that in this one example, having them be the way they are can work. However, the entire point of this course is to enable students/teams to write code that works all the time (or close to it). I like going out on the field and having alliance partners whose robots work really well, so I want this course to teach the best possible solution at each step that will ensure long term success.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CTRE Anything starter code or curriculum material touching CTRE libraries examples Stage 2 Starter Code Code for students to build on - Java, WPILib, etc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants