Soft Limits

Soft limits are positions on the motor's encoder that the motor will not pass. This allows you to constrain motion between two points, helpful in many mechanisms where overrotation or overextension are dangerous.

Examples

First you must set the soft limits, the following constrains the motor between -18 and 24 encoder ticks.

motor.setSoftLimits(-18, 24); 

This example constrains the motor between 3 and 9 encoder ticks.

motor.setSoftLimits(3, 9); 

Then one must physically enable the soft limits to take effect.

motor.enableSoftLimits(true); 

You can also turn off soft limts, but still leave the limits configured on the motor controller.

motor.enableSoftLimits(false); 

API Details

Set Soft Limits

Sets the soft limits that the motor will not cross if soft limits are enabled.

setSoftLimits(double revLimit, double fwdLimit)

Parameters:

  • revLimit The reverse position the motor will not go past.

  • fwdLimit The forward position the motor will not go past.

Enable Soft Limits

Enable / disable soft limits.

enableSoftLimits(boolean enable)

Parameters:

  • enable If soft limits should be enabled.

Soft limits tell your motor controller how many revolutions your motor can safely turn before it needs to stop. Unlike hard limit switches that physically cut power at the end of travel, soft limits use the motor's built-in encoder to count rotations. You set these in your controller to match your mechanism's actual range of motion - for example, if your arm can only rotate 3.5 times before it hits its mechanical stop, you'd set your soft limit to something like 3.4 rotations. This prevents your mechanism from binding up or damaging itself by trying to push past its mechanical limits. Since these are programmed into the controller itself using encoder counts, they're always enforced - you can't override them, and they'll work consistently every time.

Last updated