File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change 28
28
FAST_DECAY = const (0 ) # Recirculation current fast decay mode (coasting)
29
29
SLOW_DECAY = const (1 ) # Recirculation current slow decay mode (braking)
30
30
31
+
31
32
class DCMotor :
32
33
"""DC motor driver. ``positive_pwm`` and ``negative_pwm`` can be swapped if the motor runs in
33
34
the opposite direction from what was expected for "forwards".
@@ -75,11 +76,11 @@ def throttle(self, value):
75
76
duty_cycle = int (0xFFFF * abs (value ))
76
77
if self ._decay_mode == SLOW_DECAY : # Slow Decay (Braking) Mode
77
78
if value < 0 :
78
- self ._positive .duty_cycle = 0xffff - duty_cycle
79
- self ._negative .duty_cycle = 0xffff
79
+ self ._positive .duty_cycle = 0xFFFF - duty_cycle
80
+ self ._negative .duty_cycle = 0xFFFF
80
81
else :
81
- self ._positive .duty_cycle = 0xffff
82
- self ._negative .duty_cycle = 0xffff - duty_cycle
82
+ self ._positive .duty_cycle = 0xFFFF
83
+ self ._negative .duty_cycle = 0xFFFF - duty_cycle
83
84
else : # Default Fast Decay (Coasting) Mode
84
85
if value < 0 :
85
86
self ._positive .duty_cycle = 0
@@ -100,7 +101,9 @@ def decay_mode(self, mode=FAST_DECAY):
100
101
if mode in (FAST_DECAY , SLOW_DECAY ):
101
102
self ._decay_mode = mode
102
103
else :
103
- raise ValueError ("Decay mode value must be either motor.FAST_DECAY or motor.SLOW_DECAY" )
104
+ raise ValueError (
105
+ "Decay mode value must be either motor.FAST_DECAY or motor.SLOW_DECAY"
106
+ )
104
107
105
108
def __enter__ (self ):
106
109
return self
You can’t perform that action at this time.
0 commit comments