3.7. Servo

servo_ctrl.get_angle(servo_id)
Description:Obtains the rotation angle of the servo
参数:servo_id (uint8) – The number of the servo, whose range is [1:3]
返回:The angle of the servo, with an accuracy of 0.1°
返回类型: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

参数:
  • servo_id (uint8) – The number of the servo, whose range is [1:3]
  • 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.
返回:

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

参数:
  • servo_id (uint8) – The number of the servo, whose range is [1:3]
  • wait_for_complete (bool) – Whether to wait for execution to be completed. The default value is True.
返回:

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

参数:
  • servo_id (uint8) – The number of the servo, whose range is [1:3]
  • speed (int32) – The rotation speed, with an accuracy of 1 °/second. A positive number indicates clockwise rotation, and a negative number indicates counterclockwise rotation.
返回:

None

Example:

servo_ctrl.set_speed(1, 5)

Example description:
 

Set servo 1 to rotate clockwise at a rotation speed of 5 °/second

提示

For the description of the module, refer to Servo.