Add speed/direction motor#1147
Conversation
| self.backward_device.off() | ||
| self.forward_device.on() | ||
| self.speed_device.value = speed |
There was a problem hiding this comment.
As a safety-measure, I wonder if this should first set self.speed_device.value to 0 before turning the forward_device on? I.e. if you do
my_speed_motor.backward(1)
time.sleep(1)
my_speed_motor.forward(0.2)you probably don't want a momentary blip where the motor is running forwards at full speed?
|
Hrmmm, looking at my comments in #366 (specifically this one ), I wonder if this could be shoe-horned into the existing And I'm too tired right now to think of a better name than |
|
I thought this felt familiar. Does it not work the same if you just use the enable pin on the |
Yeah, that makes sense. How about |
That wouldn't work because the enable pin is a |
I did consider that, but thought that people might confuse
I think @bennuttall was suggesting that rather than having |
|
Yes I'm pretty sure that's where we ended up last time |
I'm using the L298N motor driver, which while it does work with PWM on the forward & backward pins, is better with PWM on the enable pin (see #366 (comment)):
Also see page 4 of https://www.st.com/resource/en/application_note/CD00003776-.pdf:
|
| stopped. | ||
| """ | ||
| if hasattr(self, "enable_device"): | ||
| return (self.forward_device.value - self.backward_device.value) * self.enable_device.value |
|
Should the if isinstance(self.enable_device, PWMOutputDevice):
self.enable_device.value = 1after turning off the forward and backward pins, in order to activate the 'Fast Stop' feature you mentioned? Thanks for adding such comprehensive tests 👍 |
Good point, I did that. |
| 'backward speed must be 0 or 1 with non-PWM Motors') | ||
| self.forward_device.off() | ||
| if isinstance(self.enable_device, PWMOutputDevice): | ||
| if hasattr(self, "enable_device") and isinstance(self.enable_device, PWMOutputDevice): |
There was a problem hiding this comment.
I wonder if it'd be worth having a self.enable_is_pwm boolean attribute and checking that, rather than all of these hasattr(...) and isinstance(...) tests? 🤷♂️
There was a problem hiding this comment.
how about self.control_type, an enum that can be NO_PWM, PWM, NO_PWM_WITH_ENABLE, PWM_WITH_ENABLE, or ENABLE_IS_PWM? that way no isinstance checks have to be done at all?
There was a problem hiding this comment.
Sounds good. But I wonder if DIGITAL, PWM, DIGITAL_WITH_DIGITAL_ENABLE, PWM_WITH_DIGITAL_ENABLE, DIGITAL_WITH_PWM_ENABLE is a slightly clearer set of names?
There was a problem hiding this comment.
I've done this and run unit tests. Thanks for all the feedback.
See #300 and #330. Add support for a motor driven by three pins: one that's speed and the other two like the two forward and backward pins on the regular
Motorclass. I couldn't think of a better name thanSpeedDirectionMotor.