@@ -32,18 +32,22 @@ class _BaseServo: # pylint: disable-msg=too-few-public-methods
32
32
:param int min_pulse: The minimum pulse length of the servo in microseconds.
33
33
:param int max_pulse: The maximum pulse length of the servo in microseconds."""
34
34
35
- def __init__ (self , pwm_out : PWMOut , * , min_pulse : int = 750 , max_pulse : int = 2250 ):
35
+ def __init__ (
36
+ self , pwm_out : PWMOut , * , min_pulse : int = 750 , max_pulse : int = 2250
37
+ ) -> None :
36
38
self ._pwm_out = pwm_out
37
39
self .set_pulse_width_range (min_pulse , max_pulse )
38
40
39
- def set_pulse_width_range (self , min_pulse : int = 750 , max_pulse : int = 2250 ):
41
+ def set_pulse_width_range (
42
+ self , min_pulse : int = 750 , max_pulse : int = 2250
43
+ ) -> None :
40
44
"""Change min and max pulse widths."""
41
45
self ._min_duty = int ((min_pulse * self ._pwm_out .frequency ) / 1000000 * 0xFFFF )
42
46
max_duty = (max_pulse * self ._pwm_out .frequency ) / 1000000 * 0xFFFF
43
47
self ._duty_range = int (max_duty - self ._min_duty )
44
48
45
49
@property
46
- def fraction (self ):
50
+ def fraction (self ) -> Optional [ float ] :
47
51
"""Pulse width expressed as fraction between 0.0 (`min_pulse`) and 1.0 (`max_pulse`).
48
52
For conventional servos, corresponds to the servo position as a fraction
49
53
of the actuation range. Is None when servo is diabled (pulsewidth of 0ms).
@@ -53,7 +57,7 @@ def fraction(self):
53
57
return (self ._pwm_out .duty_cycle - self ._min_duty ) / self ._duty_range
54
58
55
59
@fraction .setter
56
- def fraction (self , value : Optional [float ]):
60
+ def fraction (self , value : Optional [float ]) -> None :
57
61
if value is None :
58
62
self ._pwm_out .duty_cycle = 0 # disable the motor
59
63
return
@@ -100,22 +104,22 @@ def __init__(
100
104
actuation_range : int = 180 ,
101
105
min_pulse : int = 750 ,
102
106
max_pulse : int = 2250
103
- ):
107
+ ) -> None :
104
108
super ().__init__ (pwm_out , min_pulse = min_pulse , max_pulse = max_pulse )
105
109
self .actuation_range = actuation_range
106
110
"""The physical range of motion of the servo in degrees."""
107
111
self ._pwm = pwm_out
108
112
109
113
@property
110
- def angle (self ):
114
+ def angle (self ) -> Optional [ float ] :
111
115
"""The servo angle in degrees. Must be in the range ``0`` to ``actuation_range``.
112
116
Is None when servo is disabled."""
113
117
if self .fraction is None : # special case for disabled servos
114
118
return None
115
119
return self .actuation_range * self .fraction
116
120
117
121
@angle .setter
118
- def angle (self , new_angle : Optional [int ]):
122
+ def angle (self , new_angle : Optional [int ]) -> None :
119
123
if new_angle is None : # disable the servo by sending 0 signal
120
124
self .fraction = None
121
125
return
@@ -131,27 +135,27 @@ class ContinuousServo(_BaseServo):
131
135
:param int max_pulse: The maximum pulse width of the servo in microseconds."""
132
136
133
137
@property
134
- def throttle (self ):
138
+ def throttle (self ) -> float :
135
139
"""How much power is being delivered to the motor. Values range from ``-1.0`` (full
136
140
throttle reverse) to ``1.0`` (full throttle forwards.) ``0`` will stop the motor from
137
141
spinning."""
138
142
return self .fraction * 2 - 1
139
143
140
144
@throttle .setter
141
- def throttle (self , value : float ):
145
+ def throttle (self , value : float ) -> None :
142
146
if value > 1.0 or value < - 1.0 :
143
147
raise ValueError ("Throttle must be between -1.0 and 1.0" )
144
148
if value is None :
145
149
raise ValueError ("Continuous servos cannot spin freely" )
146
150
self .fraction = (value + 1 ) / 2
147
151
148
- def __enter__ (self ):
152
+ def __enter__ (self ) -> "ContinuousServo" :
149
153
return self
150
154
151
155
def __exit__ (
152
156
self ,
153
157
exception_type : Optional [Type [type ]],
154
158
exception_value : Optional [BaseException ],
155
159
traceback : Optional [TracebackType ],
156
- ):
160
+ ) -> None :
157
161
self .throttle = 0
0 commit comments