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

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

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.

Direction

Provides the current direction of a servo.

Key points:

  • Return value: A string value of “FORWARD” or “REVERSE”.

  • 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

Provides the current position of a servo.

Key points:

  • Return Value: A floating point value in ticks.

  • Usage: Crucial for precise servo control, closed-loop control, and position-based actions.

scaleRange

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.