For the complete documentation index, see llms.txt. This page is also available as Markdown.
How do I use exponential profiles?
An exponential profile plans a move the way a DC motor actually moves: hard acceleration at first, then less as it nears top speed. Every SmartMotorController in YAMS supports them. This is the short version: Exponential profiles has the full explanation and the tuning steps.
The two profiles, and why the motor can follow one more easily than the other.
Use one
Add withExponentialProfile(...) instead of withTrapezoidalProfile(...). For an elevator, YAMS works out starting values from the motor, the carriage and the drum. This is a fragment of an elevator subsystem's fields; the rest of the config (feedforward, limits, telemetry) is as in the Elevator tutorial.
withGearing must come beforewithExponentialProfile, because the profile is calculated from the gearing at that moment. This form also makes the closed loop work in meters (see How do I tune my elevator in rotations instead of meters?).
There are helpers for arms, flywheels and custom limits too: see creating constraints.
When should I use one?
A simulated 12 V motor following each profile. The trapezoidal profile asks for more than the motor has left at speed.
Use one when a trapezoidal profile is hard to tune, or the mechanism falls behind it and then overshoots.
Keep the trapezoidal profile if it already works well, or the motor is always current limited.
Start from the helper's values and refine the profile live. The profile only plans the move, so it still needs a feedforward, and the profile's kV and kA are not the feedforward's.
Check it
Start the simulation, command a new height, and graph the motor's closedloop/setpoint/position against measurement/position under NetworkTables > Mechanisms. The setpoint should curve smoothly to the target, and the measurement should stay close behind it the whole way.
If it did not work
The setpoint jumps straight to the target, or the elevator does not move. The profile is missing or empty: check that withGearing comes before withExponentialProfile, and that the drum radius and carriage weight are right.
The elevator falls behind the setpoint and then overshoots. The feedforward is missing or kG is 0. See Feedforward.
private final Distance drumRadius = Inches.of(0.25).times(22).div(2 * Math.PI); // 22 tooth sprocket, #25 chain
private final Mass weight = Pounds.of(16);
private final DCMotor motors = DCMotor.getNEO(1);
private final MechanismGearing gearing = new MechanismGearing(GearBox.fromReductionStages(3, 4));
private final SmartMotorControllerConfig motorConfig = new SmartMotorControllerConfig(this)
.withControlMode(ControlMode.CLOSED_LOOP)
// Gearing first: withExponentialProfile reads it to build the profile.
.withGearing(gearing)
.withDrumRadius(drumRadius)
// PLACEHOLDER kP, in volts per meter. Tune it after the profile.
.withClosedLoopController(10, 0, 0)
// Maximum voltage during the profile, the motor, the carriage weight and the drum radius.
.withExponentialProfile(Volts.of(12), motors, weight, drumRadius);
// Copyright (c) 2026 Yet Another Software Suite
// SPDX-License-Identifier: LGPL-3.0-or-later
package first.robot.subsystems;
import static org.wpilib.units.Units.*;
import com.revrobotics.util.CANPorts;
import com.revrobotics.spark.SparkLowLevel;
import com.revrobotics.spark.SparkMax;
import org.wpilib.math.controller.ElevatorFeedforward;
import org.wpilib.math.filter.Debouncer;
import org.wpilib.math.system.DCMotor;
import org.wpilib.units.measure.*;
import org.wpilib.command2.Command;
import org.wpilib.command2.SubsystemBase;
import yams.commands2.config.SmartMotorControllerConfig;
import yams.commands2.mechanisms.Elevator;
import yams.core.gearing.GearBox;
import yams.core.gearing.MechanismGearing;
import yams.core.math.ExponentialProfilePIDController;
import yams.core.mechanisms.config.ElevatorConfig;
import yams.core.motorcontrollers.SmartMotorController;
import yams.core.motorcontrollers.enums.ControlMode;
import yams.core.motorcontrollers.enums.MotorMode;
import yams.core.motorcontrollers.local.SparkWrapper;
import yams.core.telemetry.enums.TelemetryVerbosity;
// TODO: Example with absolute encoders
/**
* Exponentially profiled elevator subsystem. The elevator represented by this class does NOT have an absolute encoder! This
* subsystem has a "self-homing" command, more details in the function description.
*/
public class ExponentiallyProfiledElevatorSubsystem extends SubsystemBase
{
private final String motorTelemetryName = "ExponentiallyProfiledElevatorMotor";
private final String mechTelemetryName = "ExponentiallyProfiledElevator";
private final SparkMax elevatorMotor = new SparkMax(CANPorts.fromBusId(1), 2, SparkLowLevel.MotorType.kBrushless);
/// Configuration Options
private final DCMotor dcMotor = DCMotor.getNEO(1);
private final Distance chainPitch = Inches.of(0.25);
private final int toothCount = 22;
private final Distance circumference = chainPitch.times(toothCount);
private final Distance radius = circumference.div(2 * Math.PI);
private final MechanismGearing gearing = new MechanismGearing(GearBox.fromReductionStages(3, 4));
private final Mass weight = Pounds.of(16);
/*
* Using a measuring tape, where 0 cm marks the elevator at its lowest point,
* you can measure the height to determine the starting position reference.
*/
private final Distance startingHeight = Meters.of(0);
/*
* To find these limits, measure the starting height relative to the elevator's lowest position using a measuring tape or ruler.
*/
private final Distance softLowerLimit = Meters.of(0);
private final Distance softUpperLimit = Meters.of(2);
/*
* These are the real "limits" of the robot shown in simulation.
*/
private final Distance hardLowerLimit = Meters.of(0);
private final Distance hardUpperLimit = Meters.of(3);
/*
* This is the STARTING Feedforward for the Elevator. If you are using a TalonFX or TalonFXS this will run on the motor controller itself.
*/
private final ElevatorFeedforward elevatorFeedforward = new ElevatorFeedforward(0, 0, 0, 0);
/**
* {@link SmartMotorControllerConfig} for the elevator motor.
*/
private final SmartMotorControllerConfig motorConfig = new SmartMotorControllerConfig(this)
/*
* Basic Configuration options for the motor
*/
.withMotorInverted(false)
.withZeroPower(MotorMode.BRAKE)
.withControlMode(ControlMode.CLOSED_LOOP)
.withMechanismCircumference(circumference)
.withGearing(new MechanismGearing(GearBox.fromReductionStages(3, 4)))
.withStatorCurrentLimit(Amps.of(40)) // Prevents our motor from continuously over-taxing itself when it is stuck.
.withClosedLoopRampRate(Seconds.of(0.25)) // Prevents our motor from rapid demand changes that could cause dramatic voltage drops, and current draw.
.withOpenLoopRampRate(Seconds.of(0.25)) // Same as above
.withTelemetry(motorTelemetryName,
TelemetryVerbosity.HIGH) // Could have more fine-grained control over what gets reported with SmartMotorControllerTelemetryConfig
/*
* Closed loop configuration options for the motor.
*/
.withClosedLoopController(1,0,0)
.withExponentialProfile(ExponentialProfilePIDController.createElevatorConstraints(
Volts.of(12),
dcMotor,
weight,
radius,
gearing))
.withFeedforward(elevatorFeedforward)
.withSoftLimits(softLowerLimit, softUpperLimit)
.withStartingPosition(softLowerLimit); // Required to simulate the elevator
/// Generic Smart Motor Controller with our options and vendor motor.
private final SmartMotorController motor = new SparkWrapper(elevatorMotor, dcMotor, motorConfig);
/// Elevator-specific options
private ElevatorConfig m_config = new ElevatorConfig()
/*
* Basic configuration options for the arm.
*/
.withCarriageWeight(weight)
.withTelemetry(mechTelemetryName, TelemetryVerbosity.HIGH)
/*
* Simulation configuration options for the arm.
*/
.withHardLimits(hardLowerLimit, hardUpperLimit);
// Arm mechanism
private final Elevator m_elevator = new Elevator(m_config, motor);
public ExponentiallyProfiledElevatorSubsystem()
{
}
public void periodic()
{
m_elevator.updateTelemetry();
}
public void simulationPeriodic()
{
m_elevator.simIterate();
}
/**
* Reset the encoder to the lowest position when the current threshold is reached. Should be used when the Elevator
* position is unreliable, like startup. Threshold is only detected if exceeded for 0.4 seconds, and the motor moves
* less than 2 degrees per second.
*
* @param threshold The current threshold held when the Elevator is at its hard limit.
* @return
*/
public Command homing(Current threshold)
{
Debouncer currentDebouncer = new Debouncer(0.4); // Current threshold is only detected if exceeded for 0.4 seconds.
Voltage runVolts = Volts.of(-2); // Volts required to run the mechanism down. Could be positive if the mechanism is inverted.
Distance limitHit = hardLowerLimit; // Limit which gets hit. Could be the lower limit if the volts makes the arm go down.
AngularVelocity velocityThreshold = DegreesPerSecond.of(2); // The maximum amount of movement for the arm to be considered "hitting the hard limit".
return startRun(motor::stopClosedLoopController, // Stop the closed loop controller, requires this subsystem
() -> motor.setVoltage(runVolts)) // Set the voltage of the motor
.until(() -> currentDebouncer.calculate(motor.getStatorCurrent().gte(threshold) &&
motor.getMechanismVelocity().abs(DegreesPerSecond) <=
velocityThreshold.in(DegreesPerSecond)))
.finallyDo(() -> {
motor.setEncoderPosition(limitHit);
motor.startClosedLoopController();
});
}
public Command elevCmd(double dutycycle)
{
return m_elevator.set(dutycycle);
}
public Command setHeight(Distance height)
{
return m_elevator.setHeight(height);
}
}