> For the complete documentation index, see [llms.txt](https://docs-origin.anvil.bot/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-origin.anvil.bot/reference/technical-reference/tuning-gains-for-high-precision-motion.md).

# Tuning gains for high-precision motion

Adjusting your settings to get the most precision out of your robot

## Gains tuning

Anvil's robots use the MIT-mode control law to implement joint-space impedance control. The default parameters ensure safe and compliant robot motion, but by adjusting these based on your task and preferences, you can significantly change the behavior of the robot to suit your needs.

### Stiffness

The `kp` term determines the "stiffness" of the robot. Increasing it means the robot tracks and holds its commanded position more exactly, making it easier to perform tasks that require high precision. Decreasing it makes the robot movement more compliant, making it safer and gentler when responding to external forces.

### Damping

The `kd` term determines the "damping" of the robot, which roughly determines how much the robot decelerates as it approaches its commanded position. Increasing it generally reduces the speed the arm moves with. Importantly, increasing it can eliminate oscillations that can occur when using high `kp`.

## How to tune them

Every robot config inside `~/anvil-loader/config` has stiffness and damping exposed per-arm as  `teleop_kp` ([example](https://github.com/anvil-robotics/anvil-loader/blob/main/config/openarm_quest_teleop.yaml#L22)) and `teleop_kd` ([example](https://github.com/anvil-robotics/anvil-loader/blob/main/config/openarm_quest_teleop.yaml#L23)) respectively. The ordering of the array corresponds to the ordering of the joints (first value is J1, second value is J2, etc.) which are settable per-arm. Edit these values in the config, and then restart the stack for these changes to take effect.

The most common use case of gains tuning is to increase precision. An easy way to start is to increase the `kp` values on all joints by 25%, then 50%, then so on, trying out each new set of values to determine what feels best. As you increase these, you should increase `kd` roughly in proportion, to prevent oscillations. You can go so far as doubling (or even sometimes tripling in extreme cases) these values to get the precision you need.

{% hint style="info" %}
You might notice the last values in the `teleop_kp` and `teleop_kd` arrays are extremely small, these are for the gripper and this is by design. To adjust gripper behavior, see [Controlling the Customizable Gripper](https://docs-origin.anvil.bot/reference/technical-reference/controlling-the-customizable-gripper.md#advanced-tuning) instead of changing these values.
{% endhint %}
