pyb.Servo.rst 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. .. currentmodule:: pyb
  2. .. _pyb.Servo:
  3. class Servo -- 3-wire hobby servo driver
  4. ========================================
  5. Servo objects control standard hobby servo motors with 3-wires (ground, power,
  6. signal). There are 4 positions on the pyboard where these motors can be plugged
  7. in: pins X1 through X4 are the signal pins, and next to them are 4 sets of power
  8. and ground pins.
  9. Example usage::
  10. import pyb
  11. s1 = pyb.Servo(1) # create a servo object on position X1
  12. s2 = pyb.Servo(2) # create a servo object on position X2
  13. s1.angle(45) # move servo 1 to 45 degrees
  14. s2.angle(0) # move servo 2 to 0 degrees
  15. # move servo1 and servo2 synchronously, taking 1500ms
  16. s1.angle(-60, 1500)
  17. s2.angle(30, 1500)
  18. .. note:: The Servo objects use Timer(5) to produce the PWM output. You can
  19. use Timer(5) for Servo control, or your own purposes, but not both at the
  20. same time.
  21. Constructors
  22. ------------
  23. .. class:: pyb.Servo(id)
  24. Create a servo object. ``id`` is 1-4, and corresponds to pins X1 through X4.
  25. Methods
  26. -------
  27. .. method:: Servo.angle([angle, time=0])
  28. If no arguments are given, this function returns the current angle.
  29. If arguments are given, this function sets the angle of the servo:
  30. - ``angle`` is the angle to move to in degrees.
  31. - ``time`` is the number of milliseconds to take to get to the specified
  32. angle. If omitted, then the servo moves as quickly as possible to its
  33. new position.
  34. .. method:: Servo.speed([speed, time=0])
  35. If no arguments are given, this function returns the current speed.
  36. If arguments are given, this function sets the speed of the servo:
  37. - ``speed`` is the speed to change to, between -100 and 100.
  38. - ``time`` is the number of milliseconds to take to get to the specified
  39. speed. If omitted, then the servo accelerates as quickly as possible.
  40. .. method:: Servo.pulse_width([value])
  41. If no arguments are given, this function returns the current raw pulse-width
  42. value.
  43. If an argument is given, this function sets the raw pulse-width value.
  44. .. method:: Servo.calibration([pulse_min, pulse_max, pulse_centre, [pulse_angle_90, pulse_speed_100]])
  45. If no arguments are given, this function returns the current calibration
  46. data, as a 5-tuple.
  47. If arguments are given, this function sets the timing calibration:
  48. - ``pulse_min`` is the minimum allowed pulse width.
  49. - ``pulse_max`` is the maximum allowed pulse width.
  50. - ``pulse_centre`` is the pulse width corresponding to the centre/zero position.
  51. - ``pulse_angle_90`` is the pulse width corresponding to 90 degrees.
  52. - ``pulse_speed_100`` is the pulse width corresponding to a speed of 100.