From 7972832f0feef18341754e0e20df83a29ca886f6 Mon Sep 17 00:00:00 2001 From: Aditya9246 Date: Tue, 18 Feb 2025 14:30:32 -0800 Subject: [PATCH 1/9] created TalonPivot, need to implement closed loop controller --- .../poplib/subsytems/pivot/TalonPivot.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/main/java/poplib/subsytems/pivot/TalonPivot.java diff --git a/src/main/java/poplib/subsytems/pivot/TalonPivot.java b/src/main/java/poplib/subsytems/pivot/TalonPivot.java new file mode 100644 index 0000000..e8458b4 --- /dev/null +++ b/src/main/java/poplib/subsytems/pivot/TalonPivot.java @@ -0,0 +1,64 @@ +import com.ctre.phoenix6.hardware.TalonFX; +import com.revrobotics.spark.ClosedLoopSlot; +import com.revrobotics.spark.SparkBase.ControlType; +import com.revrobotics.spark.SparkMax; + +import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; +import poplib.control.FFConfig; +import poplib.motor.FollowerConfig; +import poplib.motor.MotorConfig; +import poplib.sensors.absolute_encoder.AbsoluteEncoderConfig; +import poplib.smart_dashboard.PIDTuning; + +public class TalonPivot extends Pivot { + public final TalonFX leadMotor; + @SuppressWarnings("unused") + private final TalonFX followerMotor; + private final PIDTuning pid; + + public TalonPivot(MotorConfig leadConfig, FollowerConfig followerConfig, double gearRatio, FFConfig ffConfig, AbsoluteEncoderConfig absoluteConfig, boolean tuningMode, String subsytemName) { + super(ffConfig, absoluteConfig, tuningMode, subsytemName); + leadMotor = leadConfig.createTalon(); + if (followerConfig != null) { + followerMotor = followerConfig.createTalon(); + } else { + followerMotor = null; + }; + + pid = leadConfig.genPIDTuning("Pivot Motor " + subsytemName, tuningMode); + + resetToAbsolutePosition(); + } + + public boolean atSetpoint(double error, double setpoint) { + return getError(setpoint) < error; + } + + public double getError(double setpoint) { + return Math.abs(leadMotor.getPosition().getValueAsDouble() - setpoint); + } + + @Override + public void log() { + super.log(); + SmartDashboard.putNumber("Lead Position " + getName(), leadMotor.getPosition().getValueAsDouble()); + } + + @Override + public void periodic() { + pid.updatePID(leadMotor); + + // TODO: Move to mutable units + leadMotor.getClosedLoopController().setReference( + setpoint.get(), + ControlType.kPosition, + ClosedLoopSlot.kSlot0, + ff.calculate(leadMotor.getPosition().getValueAsDouble(), 0) + ); + } + + @Override + public void resetToAbsolutePosition() { + leadMotor.setPosition(getAbsolutePosition()); + } +} From b79a2ca223cb135fc880fc15b01d31610dadeba3 Mon Sep 17 00:00:00 2001 From: Aditya9246 Date: Wed, 19 Feb 2025 00:32:09 -0800 Subject: [PATCH 2/9] implemented TalonPivot --- .../poplib/subsytems/pivot/TalonPivot.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/main/java/poplib/subsytems/pivot/TalonPivot.java b/src/main/java/poplib/subsytems/pivot/TalonPivot.java index e8458b4..aaf6084 100644 --- a/src/main/java/poplib/subsytems/pivot/TalonPivot.java +++ b/src/main/java/poplib/subsytems/pivot/TalonPivot.java @@ -1,8 +1,7 @@ -import com.ctre.phoenix6.hardware.TalonFX; -import com.revrobotics.spark.ClosedLoopSlot; -import com.revrobotics.spark.SparkBase.ControlType; -import com.revrobotics.spark.SparkMax; +package poplib.subsytems.pivot; +import com.ctre.phoenix6.controls.PositionDutyCycle; +import com.ctre.phoenix6.hardware.TalonFX; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; import poplib.control.FFConfig; import poplib.motor.FollowerConfig; @@ -15,6 +14,7 @@ public class TalonPivot extends Pivot { @SuppressWarnings("unused") private final TalonFX followerMotor; private final PIDTuning pid; + private final PositionDutyCycle position; public TalonPivot(MotorConfig leadConfig, FollowerConfig followerConfig, double gearRatio, FFConfig ffConfig, AbsoluteEncoderConfig absoluteConfig, boolean tuningMode, String subsytemName) { super(ffConfig, absoluteConfig, tuningMode, subsytemName); @@ -26,6 +26,10 @@ public TalonPivot(MotorConfig leadConfig, FollowerConfig followerConfig, double }; pid = leadConfig.genPIDTuning("Pivot Motor " + subsytemName, tuningMode); + position = new PositionDutyCycle(0.0); + position.withSlot(leadMotor.getClosedLoopSlot().getValue()); + + leadMotor.setPosition(0.0); resetToAbsolutePosition(); } @@ -38,6 +42,10 @@ public double getError(double setpoint) { return Math.abs(leadMotor.getPosition().getValueAsDouble() - setpoint); } + public void updatePID() { + leadMotor.setControl(position.withPosition(super.setpoint.get()).withFeedForward(super.ff.getKg())); + } + @Override public void log() { super.log(); @@ -47,14 +55,7 @@ public void log() { @Override public void periodic() { pid.updatePID(leadMotor); - - // TODO: Move to mutable units - leadMotor.getClosedLoopController().setReference( - setpoint.get(), - ControlType.kPosition, - ClosedLoopSlot.kSlot0, - ff.calculate(leadMotor.getPosition().getValueAsDouble(), 0) - ); + leadMotor.setControl(position.withPosition(super.setpoint.get()).withFeedForward(super.ff.getKg())); } @Override From 5bc28011b049e55b5c27a5735db381c0fe6e0254 Mon Sep 17 00:00:00 2001 From: Vishruth Rao <116237865+Powerlax@users.noreply.github.com> Date: Sun, 26 Oct 2025 15:32:21 -0700 Subject: [PATCH 3/9] Update SonarCloud parameters in CI workflow --- .github/workflows/pr.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 499918f..10bb38e 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -79,7 +79,8 @@ jobs: restore-keys: ${{ runner.os }}-sonar - name: Building and Analyzing - run: ./gradlew build sonar --info + run: > + ./gradlew -Dsonar.projectKey=poplib -Dsonar.organization=packofparts -Dsonar.host.url=https://sonarcloud.io build sonar --info env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} From f5c9bae1352843dd3616285bf70c2c2c94d889ab Mon Sep 17 00:00:00 2001 From: Vishruth Rao <116237865+Powerlax@users.noreply.github.com> Date: Sun, 26 Oct 2025 16:01:44 -0700 Subject: [PATCH 4/9] Enhance build command with stacktrace option Added --stacktrace option to gradlew command for better debugging. --- .github/workflows/pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 10bb38e..19fc0e2 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -80,7 +80,7 @@ jobs: - name: Building and Analyzing run: > - ./gradlew -Dsonar.projectKey=poplib -Dsonar.organization=packofparts -Dsonar.host.url=https://sonarcloud.io build sonar --info + ./gradlew -Dsonar.projectKey=poplib -Dsonar.organization=packofparts -Dsonar.host.url=https://sonarcloud.io build sonar --info --stacktrace env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} From 25d3e370101b86781c241f1b1ed2dcd31c5bcf12 Mon Sep 17 00:00:00 2001 From: Vishruth Rao <116237865+Powerlax@users.noreply.github.com> Date: Sun, 26 Oct 2025 16:09:00 -0700 Subject: [PATCH 5/9] Enhance Sonar analysis workflow with token validation Added a step to check the presence and validity of SONAR_TOKEN before running Sonar analysis. --- .github/workflows/pr.yml | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 19fc0e2..953693e 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -39,7 +39,7 @@ jobs: uses: github/codeql-action/init@v3 with: languages: java - + - name: Building run: ./gradlew build --info env: @@ -54,6 +54,8 @@ jobs: sonar: name: Sonar Analysis runs-on: ubuntu-latest + # Only run Sonar for PRs from the same repository or when a SONAR_TOKEN secret exists. + if: ${{ github.event.pull_request.head.repo.full_name == github.repository || secrets.SONAR_TOKEN != '' }} steps: - name: Checking out Code @@ -70,7 +72,27 @@ jobs: - name: Setting up Gradle uses: gradle/actions/setup-gradle@v4 - + + - name: Check SONAR_TOKEN presence and validate + # This step never prints the token itself. It will print "found key" if the token is present and valid. + run: | + # If secret is not present, fail early. + if [ -z "${{ secrets.SONAR_TOKEN }}" ]; then + echo "SONAR_TOKEN not set" + exit 1 + fi + + # Validate token against SonarCloud authentication endpoint. + # GitHub redacts secrets in logs; we only inspect the HTTP status code. + status=$(curl -sS -u "${{ secrets.SONAR_TOKEN }}:" -o /dev/null -w "%{http_code}" "https://sonarcloud.io/api/authentication/validate" || echo "000") + + if [ "$status" = "200" ]; then + echo "found key" + else + echo "ERROR: SONAR_TOKEN appears invalid (HTTP $status)" + exit 1 + fi + - name: Caching SonarQube packages uses: actions/cache@v4 with: @@ -79,10 +101,15 @@ jobs: restore-keys: ${{ runner.os }}-sonar - name: Building and Analyzing - run: > - ./gradlew -Dsonar.projectKey=poplib -Dsonar.organization=packofparts -Dsonar.host.url=https://sonarcloud.io build sonar --info --stacktrace env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} PACKAGE_FETCH_ACTOR: ${{ github.actor }} PACKAGE_FETCH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: > + ./gradlew \ + -Dsonar.login=${{ secrets.SONAR_TOKEN }} \ + -Dsonar.projectKey=poplib \ + -Dsonar.organization=packofparts \ + -Dsonar.host.url=https://sonarcloud.io \ + build sonar --info --stacktrace -Dsonar.verbose=true From b8e69a2862b2b93dd4012ffe7105b39aba09cc14 Mon Sep 17 00:00:00 2001 From: Vishruth Rao <116237865+Powerlax@users.noreply.github.com> Date: Sun, 26 Oct 2025 16:12:05 -0700 Subject: [PATCH 6/9] Refactor Sonar analysis workflow in pr.yml Removed SONAR_TOKEN validation step and adjusted build command. --- .github/workflows/pr.yml | 37 ++++++------------------------------- 1 file changed, 6 insertions(+), 31 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 953693e..933d66e 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -39,7 +39,7 @@ jobs: uses: github/codeql-action/init@v3 with: languages: java - + - name: Building run: ./gradlew build --info env: @@ -54,8 +54,6 @@ jobs: sonar: name: Sonar Analysis runs-on: ubuntu-latest - # Only run Sonar for PRs from the same repository or when a SONAR_TOKEN secret exists. - if: ${{ github.event.pull_request.head.repo.full_name == github.repository || secrets.SONAR_TOKEN != '' }} steps: - name: Checking out Code @@ -72,27 +70,7 @@ jobs: - name: Setting up Gradle uses: gradle/actions/setup-gradle@v4 - - - name: Check SONAR_TOKEN presence and validate - # This step never prints the token itself. It will print "found key" if the token is present and valid. - run: | - # If secret is not present, fail early. - if [ -z "${{ secrets.SONAR_TOKEN }}" ]; then - echo "SONAR_TOKEN not set" - exit 1 - fi - - # Validate token against SonarCloud authentication endpoint. - # GitHub redacts secrets in logs; we only inspect the HTTP status code. - status=$(curl -sS -u "${{ secrets.SONAR_TOKEN }}:" -o /dev/null -w "%{http_code}" "https://sonarcloud.io/api/authentication/validate" || echo "000") - - if [ "$status" = "200" ]; then - echo "found key" - else - echo "ERROR: SONAR_TOKEN appears invalid (HTTP $status)" - exit 1 - fi - + - name: Caching SonarQube packages uses: actions/cache@v4 with: @@ -101,15 +79,12 @@ jobs: restore-keys: ${{ runner.os }}-sonar - name: Building and Analyzing + run: ./gradlew build sonar --info env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: https://sonarcloud.io + SONAR_PROJECT_KEY: poplib + SONAR_ORGANIZATION: packofparts PACKAGE_FETCH_ACTOR: ${{ github.actor }} PACKAGE_FETCH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: > - ./gradlew \ - -Dsonar.login=${{ secrets.SONAR_TOKEN }} \ - -Dsonar.projectKey=poplib \ - -Dsonar.organization=packofparts \ - -Dsonar.host.url=https://sonarcloud.io \ - build sonar --info --stacktrace -Dsonar.verbose=true From 85b3b4649c031e0facc7c82b01d55f5f88f32941 Mon Sep 17 00:00:00 2001 From: Vishruth Rao <116237865+Powerlax@users.noreply.github.com> Date: Sun, 26 Oct 2025 16:15:15 -0700 Subject: [PATCH 7/9] Update SONAR_PROJECT_KEY in workflow configuration --- .github/workflows/pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 933d66e..9b46c9b 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -84,7 +84,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} SONAR_HOST_URL: https://sonarcloud.io - SONAR_PROJECT_KEY: poplib + SONAR_PROJECT_KEY: packofparts_poplib SONAR_ORGANIZATION: packofparts PACKAGE_FETCH_ACTOR: ${{ github.actor }} PACKAGE_FETCH_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 710e0ebf0594d3799645ce70664dcc3d9e476f21 Mon Sep 17 00:00:00 2001 From: Vishruth Rao <116237865+Powerlax@users.noreply.github.com> Date: Sun, 26 Oct 2025 16:22:19 -0700 Subject: [PATCH 8/9] Remove SonarCloud project key and organization Removed SONAR_PROJECT_KEY and SONAR_ORGANIZATION from environment variables. --- .github/workflows/pr.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 9b46c9b..5b4f416 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -84,7 +84,5 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} SONAR_HOST_URL: https://sonarcloud.io - SONAR_PROJECT_KEY: packofparts_poplib - SONAR_ORGANIZATION: packofparts PACKAGE_FETCH_ACTOR: ${{ github.actor }} PACKAGE_FETCH_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 3072353dee179ec421250a9d4ca5f06c0fd1fba5 Mon Sep 17 00:00:00 2001 From: Vishruth Rao <116237865+Powerlax@users.noreply.github.com> Date: Mon, 3 Nov 2025 19:29:25 -0800 Subject: [PATCH 9/9] Fix formatting in pr.yml permissions section --- .github/workflows/pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 5b4f416..167c055 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -12,7 +12,7 @@ jobs: permissions: actions: read contents: write - security-events: write + security-events: write strategy: fail-fast: false