# Servo

A type of motor that can be controlled to move to a specific angle. It includes a built-in feedback mechanism that allows it to accurately position itself. This makes servos ideal for applications requiring precise control, such as robotics, RC models, and automation.

**set servo.Direction to**

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXdG8aZ6WZZKnyk1qMF8bh0cOQ07SPBhd-LnMpXxMuD6TUQpegbyJS4ApHGavnmtd071AXXRwJ-Hk7vZLR1Thj3qxp0cHGfR0g3ie0dDKReIrWOy6OxlWLQmdaAwP0PWyo2fyp2g5S2nXponoWSHgaaqPoQ?key=hRw9bBhBfp1lHBJ7rUAI2Q)

Controls the direction of the servo. The only directions are “FORWARD” or “REVERSE”.

\\

Key points:

* FORWARD: The power the servo receives is unaltered.
* REVERSE: The power the servo receives is multiplied by -1, reversing its sign.
* Usage: To make setting and controlling the power to servo easier while programming and driving.

**set servo.Position to**

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXdHc9T89H0E_NhRAT7JRa8-MfhVZMeaa1xwUY_ImBiONDU6Lu_xGUhWpoJWcCaimZsD6n8LqpaM2G2qLk4wM2AOKW6C_QEcEGeOPsf52DpV9bcGO8OXg_JtWWignP63x74kImrwMBSAakixNLbWAJNQE_Cd?key=hRw9bBhBfp1lHBJ7rUAI2Q)

Sets the target position of the servo.

Key points:

* Value: A floating-point value in ticks.
* Usage: A more precise method to control the position of the servo.&#x20;

**Direction**

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXcp5lWz97eWZboFUm_hJ2L9xGKk9psrMlq3m1CSrhtOTZl22UM5L3JJ2gWdP7o3KBP40i0pbn4pePOJkTT9oPgKgSKqfpWZEYbe9AaCWiEdOB4NMemPbQS36FtZOtMbO8FTjeYwL0-2zDJhLWzgdI1pkGe3?key=hRw9bBhBfp1lHBJ7rUAI2Q)

Provides the current direction of a servo.

Key points:

* Return value: A string value of “FORWARD” or “REVERSE”.&#x20;
* FORWARD: The power the servo receives is unaltered.
* REVERSE: The power the servo receives is multiplied by -1, reversing its sign.
* Usage: Used to check the current direction of a servo. Crucial for precise servo control and ease of programming.

**Position**

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXcm03O2ca071IluJW2Z1f0ys_B2RrNDU_NSwXGzXVj3_LtpVFR9b_7GK78My0XqCJDR-YpMZ_4qQNgPnZ_--aA8LPiiIQDEEsulrjtTP0KwcREjiMe2ydZNW8XK-jkiNvWYbxHE8kXZLYvElr913Hs_9jw?key=hRw9bBhBfp1lHBJ7rUAI2Q)

Provides the current position of a servo.&#x20;

Key points:

* Return Value: A floating point value in ticks.
* Usage: Crucial for precise servo control, closed-loop control, and position-based actions.

**scaleRange**

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXdcmbThyZVCPna1lWXy-WGYoPu-S377S5TlhON0awEaMxsh4fXnDXLTn1fkhXZtd_oOp-RV2X_BCxiDVyG5K0XWTo-V247rNA5kE43fkIae6elJDleTWMxX3todbOWtYO-LKIVUqcvWOYLccvR7uKXXZ8er?key=hRw9bBhBfp1lHBJ7rUAI2Q)

Defines a specific range of motion for a servo within its overall potential range.

Key points:

* Restricting movement: Prevents the servo from moving beyond a desired range, protecting mechanical components.
* Simplifying control: Maps desired values to a scaled range, making calculations easier.
* Optimizing performance: Focuses servo control on a specific area of its movement for better precision.
* Usage: Takes two parameters: a minimum and maximum value as a fraction of the full range (0.0 to 1.0). Subsequent set position calls will be scaled to fit within the specified range.
