-
Notifications
You must be signed in to change notification settings - Fork 40
Check fraction range; add post-constructor access to actuation_range and pulse widths. #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two minor things and then good to go! Thanks!
adafruit_motor/servo.py
Outdated
self._pwm_out = pwm_out | ||
self.set_pulse_widths(min_pulse, max_pulse) | ||
|
||
def set_pulse_widths(self, min_pulse=750, max_pulse=2250): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like set_pulse_width_range
more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dropped the s
too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it shouldn't have default values for the args, so you have to give both? I'm vacillating on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having default values was what motivated the original choice of name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like defaults because it allows one to use the name in the call. aka servo.set_pulse_width_range(min_pulse=700, max_pulse=2000)
You could even force it with: def set_pulse_widths(self, *, min_pulse=750, max_pulse=2250):
@@ -83,19 +96,19 @@ class Servo(_BaseServo): | |||
""" | |||
def __init__(self, pwm_out, *, actuation_range=180, min_pulse=750, max_pulse=2250): | |||
super().__init__(pwm_out, min_pulse=min_pulse, max_pulse=max_pulse) | |||
self._actuation_range = actuation_range | |||
self.actuation_range = actuation_range |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a triple quoted doc string here so it is included in RTD.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the Servo
class has a docstring, it's already in RTD. See https://circuitpython.readthedocs.io/projects/motor/en/latest/api.html#adafruit_motor.servo.Servo.
Alphabetically ContinuousServo
came first -- maybe that was confusing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does for the argument but not the object attribute (like angle
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused. Here is the angle
doc: https://circuitpython.readthedocs.io/projects/motor/en/latest/api.html#adafruit_motor.servo.Servo.angle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. actuation_angle
should look like angle
too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was impressively difficult to do this. I can add a docstring after the self.actuation_range = actuation_range
, but then it shows up in the RTD as "actuation_range = None". After some Googling, found a hack to add to conf.py
to fix it.
The other alternative is to document actuation_range
as an :ivar
, but then it shows up with the parameters. The current new way looks better.
In
That will also accidentally fix #11. |
@dhalbert I'm ok removing it. |
… throttle property.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Updating https://github.com/adafruit/Adafruit_CircuitPython_AM2320 to 1.1.1 from 1.1.0: > add setup.py, add pypi to .travis.yml, misc. tweaks for pypi > add build artifacts to .gitignore Updating https://github.com/adafruit/Adafruit_CircuitPython_APDS to 1.1.1 from 1.1.0: > Update apds9960_proximity_simpletest.py > Update apds9960_color_simpletest.py > setup.py: add adafruit-circuitpython-register to dependencies > add setup.py, add pypi to .travis.yml, misc. tweaks for pypi, .gitignore > Merge pull request adafruit/Adafruit_CircuitPython_APDS#8 from tannewt/fix_register_in_docs > Merge pull request adafruit/Adafruit_CircuitPython_APDS#7 from sommersoft/new_docs > Merge pull request adafruit/Adafruit_CircuitPython_APDS#6 from sommersoft/new_docs Updating https://github.com/adafruit/Adafruit_CircuitPython_AS726x to 1.0.2 from 1.0.1: > .travis.yml: add missing `pip` invocation > add setup.py, add pypi to .travis.yml, misc. tweaks for pypi, .gitignore Updating https://github.com/adafruit/Adafruit_CircuitPython_Crickit to 2.0.1 from 1.0.2: > change pypi to know it's a single-file library > Merge pull request adafruit/Adafruit_CircuitPython_Crickit#7 from dhalbert/rework_api > Merge pull request adafruit/Adafruit_CircuitPython_Crickit#6 from dhalbert/rework_api > Merge pull request adafruit/Adafruit_CircuitPython_Crickit#5 from dhalbert/rework_api Updating https://github.com/adafruit/Adafruit_CircuitPython_Se to 1.2.2 from 1.2.1: > Merge pull request adafruit/Adafruit_CircuitPython_Se#17 from dhalbert/fix-pin-mapping-AGAIN Updating https://github.com/adafruit/Adafruit_CircuitPython_Motor to 1.2.0 from 1.1.2: > Merge pull request adafruit/Adafruit_CircuitPython_Motor#10 from dhalbert/check_fraction_range > Merge pull request adafruit/Adafruit_CircuitPython_Motor#9 from dhalbert/better_servo_limits
The latest Crickit library API doesn't provide explicit constructors for servos, so
actuation_range
andmin_pulse
andmax_pulse
need to be settable after construction.I just made
actuation_range
a visible attribute (it was previously hidden).For pulse widths I added a function to set both, instead of property access. They are not currently saved, but just used to compute duty cycle values Setting one pulse width at a time via a property would require extra code for computation or saving the values, and usually one wants to set both anyway. If you disagree I can make it property access.