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

Add TorqueCurrent Example #51

Merged
merged 1 commit into from
Feb 3, 2025
Merged

Add TorqueCurrent Example #51

merged 1 commit into from
Feb 3, 2025

Conversation

JosephTLockwood
Copy link
Contributor

@JosephTLockwood JosephTLockwood commented Feb 3, 2025

Add TorqueCurrent example

Summary by CodeRabbit

  • New Features
    • Introduced advanced routines for torque characterization that enhance tuning of the drive system.
    • Enabled configurable torque control for both translation and steering components, offering more precise calibration and improved overall performance.

Copy link
Contributor

coderabbitai bot commented Feb 3, 2025

📝 Walkthrough

Walkthrough

The pull request adds torque characterization capabilities to the drive subsystem by introducing a new SysId routine in the Drive class and two new request classes. The Drive class now holds member variables for torque translation characterization that are configured with specific parameters and integrated with a logging mechanism. In addition, new classes implementing the SwerveRequest interface are added to apply torque current to both steer and translation modules through overloaded methods and an apply function.

Changes

File(s) Change Summary
src/.../drive/Drive.java Added new private members m_translationTorqueCharacterization and m_sysIdRoutineTorqueTranslation for torque current characterization in the drive subsystem. Configured routine with parameters (ramp rate, dynamic step voltage, timeout) and integrated logging via SignalLogger.
src/.../drive/requests/SysIdSwerveSteerGains_Torque.java,
src/.../drive/requests/SysIdSwerveTranslation_Torque.java
Introduced two new classes implementing SwerveRequest. Each class provides a public TorqueCurrentToApply, an apply method to iterate over swerve modules, and overloaded withTorqueCurrent methods to set torque current using a double value or a Current object.

Sequence Diagram(s)

sequenceDiagram
    participant Operator
    participant Drive as Drive Subsystem
    participant TorqueTranslation as SysIdSwerveTranslation_Torque
    participant Logger as SignalLogger
    participant Module as SwerveModule

    Operator->>Drive: Trigger torque translation characterization
    Drive->>TorqueTranslation: Initialize with configuration (ramp rate, step voltage, timeout)
    TorqueTranslation->>Logger: Log start of torque characterization
    TorqueTranslation->>Module: Apply torque current (via withTorqueCurrent)
    Module-->>TorqueTranslation: Acknowledge application
    TorqueTranslation-->>Drive: Return StatusCode
Loading
sequenceDiagram
    participant Operator
    participant SteerGains as SysIdSwerveSteerGains_Torque
    participant Module as SwerveModule

    Operator->>SteerGains: Set torque current (withTorqueCurrent)
    SteerGains->>Module: Apply drive (CoastOut) and steer (TorqueCurrentFOC) requests
    Module-->>SteerGains: Acknowledge application
    SteerGains-->>Operator: Return StatusCode
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/main/java/frc/robot/subsystems/drive/requests/SysIdSwerveSteerGains_Torque.java (1)

19-19: Follow Java naming conventions for public variables.

The variable TorqueCurrentToApply should be renamed to torqueCurrentToApply to follow Java naming conventions.

-  public double TorqueCurrentToApply = 0;
+  public double torqueCurrentToApply = 0;
src/main/java/frc/robot/subsystems/drive/requests/SysIdSwerveTranslation_Torque.java (2)

19-19: Follow Java naming conventions for public variables.

The variable TorqueCurrentToApply should be renamed to torqueCurrentToApply to follow Java naming conventions.

-  public double TorqueCurrentToApply = 0;
+  public double torqueCurrentToApply = 0;

24-26: Document the selection criteria for steer closed-loop type.

While the comment indicates there are two options, it would be helpful to document the criteria for selecting between PositionVoltage and PositionTorqueCurrentFOC.

-  // Select one of the two below based on which type of steer closed-loop you are using
+  // Select the appropriate steer closed-loop type:
+  // - Use PositionVoltage for voltage-based position control
+  // - Use PositionTorqueCurrentFOC for torque-based position control with field-oriented control
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f918c26 and 8c5d89d.

📒 Files selected for processing (3)
  • src/main/java/frc/robot/subsystems/drive/Drive.java (3 hunks)
  • src/main/java/frc/robot/subsystems/drive/requests/SysIdSwerveSteerGains_Torque.java (1 hunks)
  • src/main/java/frc/robot/subsystems/drive/requests/SysIdSwerveTranslation_Torque.java (1 hunks)
🔇 Additional comments (6)
src/main/java/frc/robot/subsystems/drive/requests/SysIdSwerveSteerGains_Torque.java (2)

26-32: LGTM! Clean implementation of the apply method.

The implementation correctly applies coast to drive motors while applying torque current to steer motors.


40-53: LGTM! Well-structured method overloading.

Good use of method overloading to support both primitive double and Current unit types.

src/main/java/frc/robot/subsystems/drive/requests/SysIdSwerveTranslation_Torque.java (1)

28-35: LGTM! Clean implementation of the apply method.

The implementation correctly applies torque current to drive motors while maintaining steer position at 0.

src/main/java/frc/robot/subsystems/drive/Drive.java (3)

93-96: LGTM! Clear initialization of torque characterization.

Good addition of the torque characterization request with clear comment indicating it's an example.


97-113: LGTM! Well-configured SysId routine for torque characterization.

The configuration is well-structured with:

  • Appropriate ramp rate of 5 A/s
  • Reasonable dynamic step of 10 A
  • Safe timeout of 5 seconds
  • Proper logging integration

164-164: Consider updating default SysId routine.

The default routine is set to translation characterization. Consider if torque characterization should be the default for better initial characterization.

Would you like me to help determine the most appropriate default characterization routine based on the codebase usage?

@JosephTLockwood JosephTLockwood merged commit f64a8f4 into main Feb 3, 2025
3 checks passed
@JosephTLockwood JosephTLockwood deleted the TorqueCurrent branch February 3, 2025 17:57
@JosephTLockwood
Copy link
Contributor Author

Closed #51

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.

1 participant