Skip to content

Conversation

jasondaming
Copy link
Member

Adds snippets demonstrating ProfiledPIDController usage with SimpleMotorFeedforward using the two-parameter calculate(currentVelocity, nextVelocity) method.

Changes

  • Added Java snippet: wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/snippets/profiledpidfeedforward/Robot.java
  • Added C++ snippet: wpilibcExamples/src/main/cpp/snippets/ProfiledPIDFeedforward/cpp/Robot.cpp

Purpose

These snippets will be used in frc-docs (wpilibsuite/frc-docs#3117) to document the recommended feedforward pattern with ProfiledPIDController, replacing deprecated inline code examples.

The snippets demonstrate:

  • Using ProfiledPIDController to control motor position
  • Tracking previous velocity with a member variable
  • Using feedforward.calculate(lastSpeed, controller.getSetpoint().velocity) pattern
  • Complete, compilable robot code

Related

Adds snippets demonstrating ProfiledPIDController usage with
SimpleMotorFeedforward using the two-parameter calculate() method
(currentVelocity, nextVelocity).

These snippets will be used in frc-docs to document the recommended
feedforward pattern with ProfiledPIDController.
@jasondaming jasondaming requested review from a team as code owners October 8, 2025 02:35
jasondaming added a commit to jasondaming/frc-docs that referenced this pull request Oct 8, 2025
Replace inline code blocks with RLIs to snippets from allwpilib.
Java and C++ examples now reference compilable snippet code that
will be tested in every allwpilib build.

Python remains as inline code block since Python snippets are
maintained in robotpy repository.

Related: wpilibsuite/allwpilib#8280
@sciencewhiz
Copy link
Contributor

There's a list of valid tags here:

def tagList = [
/* --- Categories --- */
// On-RIO image processing
"Vision",
// Command-based
"Command-based",
// Romi
"Romi",
// XRP
"XRP",
// Extremely simple programs showcasing a single hardware API
"Hardware",
// Full robot, with multiple mechanisms
"Complete Robot",
// A single mechanism in the Robot class
"Basic Robot",
/* --- Mechanisms --- */
"Intake", "Flywheel", "Elevator", "Arm", "Differential Drive", "Mecanum Drive",
"Swerve Drive",
/* --- Telemetry --- */
"SmartDashboard", "Shuffleboard", "Sendable", "DataLog",
/* --- Controls --- */
"Exponential Profile", "PID", "State-Space", "LTVUnicycleController", "Path Following",
"Trajectory", "SysId", "Simulation", "Trapezoid Profile", "Profiled PID", "Odometry",
"LQR", "Pose Estimator",
/* --- Hardware --- */
"Analog", "Ultrasonic", "Gyro", "Pneumatics", "I2C", "Duty Cycle", "PDP", "DMA", "Relay",
"AddressableLEDs", "HAL", "Encoder", "Smart Motor Controller", "Digital Input",
"Digital Output", "Accelerometer",
/* --- HID --- */
"XboxController", "PS4Controller", "PS5Controller", "Joystick",
/* --- Misc --- */
/* (try to keep this section minimal) */
"EventLoop", "AprilTags", "Mechanism2d", "Preferences",
]

@Gold856
Copy link
Contributor

Gold856 commented Oct 8, 2025

How long is this expected to last? Last I checked, we're trying to axe ProfiledPIDController in favor of just using TrapezoidProfile and PIDController.

… acceleration)

Per the SimpleMotorFeedforward API, the two-parameter calculate method
that takes velocity and acceleration is deprecated. This updates the
snippet to use calculateWithVelocities(currentVelocity, nextVelocity)
which is the recommended approach.

Addresses wpilibsuite#8280
- Add Javadoc comment for goToPosition method
- Split long line to stay under 100 character limit
- Remove redundant field initializer for m_lastSpeed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants