Skip to content

Commit

Permalink
Add sections to swerve project customization docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jwbonner committed Nov 5, 2024
1 parent c6a89de commit 0f5dfe1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/docs/example-projects/spark-swerve-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,11 @@ tryUntilOk(turnSpark, 5, () -> turnEncoder.setPosition(customEncoder.getPosition
The `Drive` subsystem uses WPILib's [`SwerveDrivePoseEstimator`](https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/math/estimator/SwerveDrivePoseEstimator.html) class for odometry updates. The subsystem exposes the `addVisionMeasurement` method to enable vision systems to publish samples. Additional methods can be easily exposed as desired.

Alternatively, other pose estimation systems can be easily integrated in place of the WPILib solution. The `periodic` method includes a call to `poseEstimator.updateWithTime` that includes the sample timestamp, gyro rotation, and module positions. This call can be replaced to integrate with any other odometry or pose estimation system.

### Swerve Setpoint Generator

The project already includes basic mechanisms to reduce skidding, such as drive current limits and cosine optimization. Users who prefer more control over module skidding may wish to utilize Team 254's [`SwerveSetpointGenerator`](https://github.com/Team254/FRC-2023-Public/blob/main/src/main/java/com/team254/lib/swerve/SwerveSetpointGenerator.java) in the `runSetpoint` method of the `Drive` subsystem.

### Advanced Physics Simulation

The project can be easily adapted to utilize Team 5516's [maple-sim](https://github.com/Shenzhen-Robotics-Alliance/Maple-Sim) library for simulation, which provides a full rigid-body simulation of the swerve drive and its interactions with the field. Check the documentation for more details on how to install and use the library.
17 changes: 17 additions & 0 deletions docs/docs/example-projects/talonfx-swerve-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,25 @@ turnConfig.Feedback.FeedbackSensorSource = FeedbackSensorSourceValue.RotorSensor
tryUntilOk(5, () -> turnTalon.setPosition(customEncoder.getPositionRotations(), 0.25));
```

### Exponential Turning Profile

By default, the project uses a standard trapezoidal profile for turn control. Users may choose to replace the trapezoidal profile with an exponential version using the Phoenix [Motion Magic Expo](https://pro.docs.ctr-electronics.com/en/latest/docs/api-reference/device-specific/talonfx/motion-magic.html#motion-magic-expo) API. To implement this, simply replace the position request in `ModuleIOTalonFX` with the new request type, as shown below. The `kV` and `kA` constraints are already configured in the `ModuleIOTalonFX` constructor, but can be adjusted.

```java
private final MotionMagicExpoVoltage positionVoltageRequest = new MotionMagicExpoVoltage(0.0);
private final MotionMagicExpoTorqueCurrentFOC positionTorqueCurrentRequest = new MotionMagicExpoTorqueCurrentFOC(0.0);
```

### Vision Integration

The `Drive` subsystem uses WPILib's [`SwerveDrivePoseEstimator`](https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/math/estimator/SwerveDrivePoseEstimator.html) class for odometry updates. The subsystem exposes the `addVisionMeasurement` method to enable vision systems to publish samples. Additional methods can be easily exposed as desired.

Alternatively, other pose estimation systems can be easily integrated in place of the WPILib solution. The `periodic` method includes a call to `poseEstimator.updateWithTime` that includes the sample timestamp, gyro rotation, and module positions. This call can be replaced to integrate with any other odometry or pose estimation system.

### Swerve Setpoint Generator

The project already includes basic mechanisms to reduce skidding, such as drive current limits and cosine optimization. Users who prefer more control over module skidding may wish to utilize Team 254's [`SwerveSetpointGenerator`](https://github.com/Team254/FRC-2023-Public/blob/main/src/main/java/com/team254/lib/swerve/SwerveSetpointGenerator.java) in the `runSetpoint` method of the `Drive` subsystem.

### Advanced Physics Simulation

The project can be easily adapted to utilize Team 5516's [maple-sim](https://github.com/Shenzhen-Robotics-Alliance/Maple-Sim) library for simulation, which provides a full rigid-body simulation of the swerve drive and its interactions with the field. Check the documentation for more details on how to install and use the library.

0 comments on commit 0f5dfe1

Please sign in to comment.