2702 Recipes

Hard Stops

Why every mechanism with limited travel needs solid hard stops, how to place soft limits inside them, and how to zero against them, either at a known starting position or with a stall-detection homing routine.

A hard stop is a solid part that physically ends a mechanism's travel: a block the carriage lands on, a bolt the arm rests against. It is the simplest and most important part of any homing strategy. In short:

  1. Every mechanism with limited travel needs hard stops. Code has bugs and sensors fail. The hard stop is what keeps a mistake from breaking the robot.
  2. A hard stop is also a free zero. A mechanism resting on its stop is at a known position. Many teams zero this way, with no sensor at all.
  3. Keep soft limits inside the hard stops. Software limits stop the motor a little before the stop, so the mechanism rarely hits it at speed.
  4. Home gently. To find the stop, drive slowly toward it with a low stator current limit. It has arrived when its speed stays near zero while it pushes.

2.1 Why hard stops matter

  • They protect the mechanism. A wrong zero, a bad setpoint, or a runaway loop can drive a mechanism past the end of its travel. Without a stop, an elevator can pull its carriage off the rails, and an arm can swing into the drivetrain. With one, the mechanism stops in a known place.
  • They are a reference. A hard stop is in the same place every time. A mechanism resting on it is at a known position, which is all a zero needs.
  • They hold the starting configuration. The robot has to start each match inside its starting size limits. A hard stop holds each mechanism in its starting position, and gravity or brake mode keeps it there.

Not every mechanism has hard stops. Flywheels and rollers spin freely and need no zero at all. Swerve steering turns forever. Many turrets have none either: their travel is limited by cables, not a stop, and they may turn past the same angle more than once. These mechanisms use sensors or absolute encoders instead (Choosing a Strategy).

2.2 What makes a good hard stop

RuleWhy
Stop the output, not the motor. Put the stop where it touches the mechanism itself: the carriage, the arm, the turret ring.Belts, chain, and hubs between the motor and the stop can slip or stretch. A stop on the output marks where the mechanism really is.
Make it rigid. A metal or hard plastic block, bolted to the structure.A soft stop squashes by a different amount each time, so the zero moves.
Make contact the same way every time. Flat face to flat face, square to the motion.A mechanism that can land on different spots of the stop, or slide along it, rests in a slightly different place each time.
Pad it thinly, if at all. A thin layer of rubber or polyurethane takes the shock of a hard hit.A thick pad squashes too much and moves the zero.
Make it strong enough for a full-speed hit.Sooner or later, it will take one.

2.3 Soft limits

SetpointsHard stopHard stopSoft limitSoft limitRoom to coastRoom to overshootRoom to coastRoom to overshoot
Layers of limits along the travel. Setpoints stay inside the soft limits, so an overshoot doesn't trip them. Soft limits stay inside the hard stops, so the mechanism can coast to a stop before it hits metal. The zero is often the lower hard stop itself.

A soft limit is a position limit in software. Phoenix 6 has them built in: set ForwardSoftLimitEnable and ReverseSoftLimitEnable, with their ForwardSoftLimitThreshold and ReverseSoftLimitThreshold, in SoftwareLimitSwitchConfigs. Past a threshold, the motor controller stops driving further in that direction, whatever the robot code asks for.

Soft limits are measured from the zero, so they are only as good as the zero. Two rules:

  1. Leave margins. Setpoints a little inside the soft limits, so an overshoot doesn't trip them. Soft limits a little inside the hard stops, so the mechanism can coast to a stop before it hits metal. A few millimetres or about 0.5 to 1° each is typical (Linear Deployment pitfalls).
  2. Turn the soft limit off while homing. Before homing, the position is unknown, and so is where the soft limit really is. A homing routine that drives toward the stop needs the soft limit in that direction turned off. Turn it back on once the zero is set.

2.4 Zero at a known starting position

Most mechanisms start every match in the same place: folded inside the frame, resting on a hard stop. If the code knows that, it can set the position at the right moment, with no sensor and no homing motion. The motors' built-in encoders do the rest.

This works especially well for arms, pivots, and elevators. Every sensor is extra work and one more thing that can fail, so leave it off when a hard stop does the job.

To do it well:

  1. Design the starting pose onto the hard stops. In its starting configuration, each mechanism should rest against a stop, held there by gravity, a spring, or brake mode.
  2. Set the position at boot. Call setPosition() with the stop's value in the subsystem's constructor. The motor keeps counting while the robot is disabled, so a nudge after boot is tracked.
  3. Set it again at the start of autonomous, once. In a match, the robot is in its starting configuration when autonomous starts, so this fixes a mechanism that was off its stop at boot. Do it only on the first enable after boot. Running autonomous again in practice, with an elevator raised, would set the wrong zero.
  4. Check it before the match. Add "every mechanism on its stop" to the pre-match checklist.
  5. Have a backup. A homing routine or a manual re-zero button recovers from a zero that was set wrong, or lost to a motor controller reboot (§1.5).

2.5 Home against a hard stop

When a mechanism can't be trusted to start on its stop, drive it there and detect when it arrives. This is stall homing, also called sensorless homing: the motor's own readings are the sensor.

A motor is stalled when it pushes but doesn't turn. At the hard stop:

  • the velocity drops to about zero, and
  • the stator current (the current in the motor's windings) rises to whatever limits it.

Limit the push. In voltage mode, only the winding resistance limits stator current at a stall. A Kraken X60 (FOC) has a resistance of about 0.0248 Ω (Motor Constants), so just 1 V at a stall drives about 40 A of stator current, while the supply current is only about 3.4 A. Take an elevator with an 8 kg carriage, a 10:1 gearbox, and a drum radius of 0.02 m (the default elevator in the calculator in the torque-current guide). There, 40 A pushes the carriage into its stop with about 390 N, five times its weight. Set a low StatorCurrentLimit while homing: 15 A pushes with about 145 N.

Home in voltage mode. The voltage sets a top speed, because back-EMF grows with speed. The stator current limit sets how hard the mechanism pushes on the stop. A torque-current request sets the push, not the speed. The mechanism keeps speeding up until it hits the stop or runs out of supply voltage, unless the request's MaxAbsDutyCycle caps its output. With gravity helping, 1 V lowers the example elevator at about 0.12 m/s (ignoring friction).

2.5.1 The routine

  1. Lower the stator current limit. Use a little more than it takes to move the mechanism: kS, plus kG if homing against gravity (both in Amps, as in torque-current mode). The example elevator homes downward, with gravity helping, so it needs only kS to move, and 15 A leaves plenty of margin. Homing upward would add the 8 A or so it takes to hold the carriage.
  2. Turn off the soft limit in the homing direction.
  3. Drive slowly toward the stop. A fixed low voltage, around 1 V, or a slow velocity request.
  4. Wait until it moves. Every move starts from rest, so for an instant at the start the motor looks stalled. A mechanism stuck on friction never moves at all. Count a stall only after the mechanism has moved faster than some small speed.
  5. Detect the stall. The speed stays below a small threshold and the stator current stays above most of the homing limit, both for 0.1 to 0.25 s.
  6. Set the position to the stop's value. Restore the current limit and the soft limit, and set the homed flag.
  7. Give up after a timeout. If it hasn't stalled within two or three times the normal homing time, stop and report a failure. A broken belt shouldn't let the motor spin forever.

A sketch of the routine as a WPILib command:

private final Timer stallTimer = new Timer();
private boolean moved;

/** Drives the elevator gently down onto its bottom hard stop, then sets its position to zero. */
public Command home() {
  return startRun(
          () -> {
            homed = false;
            moved = false;
            // Low stator current limit, reverse soft limit off. Applying configs blocks briefly, so do it once.
            motor.getConfigurator().apply(homingCurrentLimits);
            motor.getConfigurator().apply(homingSoftLimits);
            stallTimer.restart();
          },
          () -> {
            motor.setControl(homingVoltage); // A VoltageOut of -1 V: down, slowly.
            double speed = Math.abs(motor.getVelocity().getValueAsDouble());
            moved |= speed > MOVING_SPEED;
            // Stalled: it has moved, it is now almost still, and it is pushing hard.
            boolean stalled = moved
                && speed < STALL_SPEED
                && Math.abs(motor.getStatorCurrent().getValueAsDouble()) > STALL_CURRENT;
            if (!stalled) stallTimer.restart();
          })
      .until(() -> stallTimer.hasElapsed(STALL_TIME))
      .andThen(runOnce(() -> {
        motor.setPosition(0);
        homed = true;
      }))
      .withTimeout(HOMING_TIMEOUT)
      .finallyDo(() -> {
        motor.setControl(neutral); // A NeutralOut: stop pushing before the normal limits come back.
        motor.getConfigurator().apply(normalCurrentLimits);
        motor.getConfigurator().apply(normalSoftLimits);
      });
}

The field names are illustrative. If the timeout ends the command, homed stays false. The command ends with a neutral request because a Talon FX keeps running its last request until it gets a new one. Without it, the motor would keep pushing on the stop, now with its normal stator current limit.

2.5.2 Choosing the numbers

SettingStart withWhy
Homing voltageAbout 1 V, more if gravity or friction works against the motionSlow enough that hitting the stop does no harm
Stator current limit while homingA little above kS + kG, in AmpsSets how hard the mechanism pushes on the stop
Moving speed (to arm the check)About half the homing speedProves the mechanism moved before it stalled
Stall speedAbout a tenth of the homing speed"Almost still", with room for noise
Stall currentAbout 80% of the homing current limitPushing at the limit, not just rolling
Stall time0.1 to 0.25 sLonger than a bounce or a sticky spot
TimeoutTwo to three times a normal homing runCatches a jam or a broken belt

2.5.3 When it goes wrong

SymptomLikely causeFix
Homes instantly, in the wrong placeThe check doesn't wait for motion, so the stall at the start counts. Or the mechanism is stuck.Require motion first. Check the mechanism for binding.
Never finishesThe stall current threshold is above the homing current limit, or the voltage is too low to move the mechanism.Set the threshold below the limit. Raise the voltage a little.
The zero moves from run to runHoming too fast, so it bounces. A soft stop. A push hard enough to stretch a belt.Home slower, with a lower current limit. Make the stop rigid.
Homes partwayA tight spot in the travel stalls the mechanism before it reaches the stop.Fix the binding. A higher current limit only hides it.

2.6 Re-zero during the match

An elevator comes back to its bottom stop many times in a match. Each time is a chance to re-zero:

  1. Finish each stow with a gentle push. When the elevator reaches its bottom position, switch to the homing voltage and current limit, with the reverse soft limit off, and push into the stop.
  2. When it stalls, set the position to zero. Use the same stall check as the homing routine.
  3. Log the size of each correction. Tiny corrections are normal drift. A large one means something slipped, such as a skipped belt tooth, and the pit crew should look.

The same idea works for any mechanism that rests on a stop in normal use, such as an intake that retracts against its stop. A limit switch or hall effect sensor at the stop does the same job without the push (§4.3).

On this page