3.7. Servo¶
-
servo_ctrl.
get_angle
(servo_id)¶ Description: Obtains the rotation angle of the servo Parameters: servo_id (uint8) – The number of the servo, whose range is [1:4] Returns: The angle of the servo, with an accuracy of 0.1° Return type: int32 Example: angle = servo_ctrl.get_angle(1)
Example description: Obtain the rotation angle of servo 1
-
servo_ctrl.
set_angle
(servo_id, angle, wait_for_complete=True)¶ Description: Set the rotation angle of the servo
Parameters: - servo_id (uint8) – The number of the servo, whose range is [1:4]
- angle (int32) – The rotation angle, with an accuracy of 0.1°. A positive number indicates clockwise rotation, and a negative number indicates counterclockwise rotation.
- wait_for_complete (bool) – Whether to wait for execution to be completed. The default value is True.
Returns: None
Example: servo_ctrl.set_angle(1, 900, True)
Example description: Set servo 1 to rotate 90° clockwise and wait for execution to be completed
-
servo_ctrl.
recenter
(servo_id, wait_for_complete=True)¶ Description: Sets the servo back to normal
Parameters: - servo_id (uint8) – The number of the servo, whose range is [1:4]
- wait_for_complete (bool) – Whether to wait for execution to be completed. The default value is True.
Returns: None
Example: servo_ctrl.recenter(1, True)
Example description: Set servo 1 back to normal and wait for execution to be completed
-
servo_ctrl.
set_speed
(servo_id, speed)¶ Description: Sets the rotation speed of the servo
Parameters: - servo_id (uint8) – The number of the servo, whose range is [1:4]
- speed (int32) – The rotation speed, with an accuracy of 1 °/second. A positive number indicates clockwise rotation, and a negative number indicates counterclockwise rotation.
Returns: None
Example: servo_ctrl.set_speed(1, 5)
Example description: Set servo 1 to rotate clockwise at a rotation speed of 5 °/second
Hint
For the description of the module, refer to Servo.