You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
motors API: passing something other than speed percentage #406
Today in on_for_rotations(), etc the user passes the speed_pct because this is how the EV3-G block works. I started updating the MINDCUBER demo to use the new API but I end up doing the following all over the place (two lines, one to cald the speed_pct and a second to call the API)
which works just fine but doesn't look super clean (side note, on_to_position() is new). What if the on_to_XYZ() methods accepted either speed_pct or (speed_type, speed_value) tuple such as the following
Maybe this is just my non-Python background, but doesn't this style feel a bit unnatural? To an experienced programmer, it seems like there would be a more direct and obvious way of specifying this value; to an inexperienced one, it would be quite easy to misinterpret the grouping and be left completely confused. Why not add other named parameters for speed_dps, speed_rpm, etc.?
but I was worried that might be confusing when comparing our API vs the EV3-G block since the speed parameter is out of order (in the block it is specified first).
For the SpeedRPS approach on_for_rotations() would need to call a function that uses isinstance to correctly convert the SpeedRPS value to speed percentage.
For the SpeedRPS approach on_for_rotations() would need to call a function that uses isinstance to correctly convert the SpeedRPS value to speed percentage.
You could also put a get_speed_sp(Motor) method on each of the "unit" classes and call that from our side. That would make it super easy to extend the behavior with custom units (e.g., rotations through gearing or feet of travel) and remove the need for a chain of ifs.
The one downside I see to this approach is that if we intend to recommend the from ev3dev.motor import Motor, OUTPUT_A, OUTPUT_B, ... approach you'll have to manually import each of the unit types, which is a pain.
Activity
WasabiFan commentedon Oct 10, 2017
Maybe this is just my non-Python background, but doesn't this style feel a bit unnatural? To an experienced programmer, it seems like there would be a more direct and obvious way of specifying this value; to an inexperienced one, it would be quite easy to misinterpret the grouping and be left completely confused. Why not add other named parameters for
speed_dps,speed_rpm, etc.?dwalton76 commentedon Oct 10, 2017
we could do
where the user would then call via
but I was worried that might be confusing when comparing our API vs the EV3-G block since the speed parameter is out of order (in the block it is specified first).
WasabiFan commentedon Oct 10, 2017
That seems cleaner to me, but I'd be interested to hear what others think.
dwalton76 commentedon Oct 10, 2017
Another option would be something like
and then the user would call via
That does look a little less hackish doesn't it
dwalton76 commentedon Oct 10, 2017
For the
SpeedRPSapproachon_for_rotations()would need to call a function that uses isinstance to correctly convert the SpeedRPS value to speed percentage.WasabiFan commentedon Oct 10, 2017
That seems like a pretty nice option as well.
You could also put a
get_speed_sp(Motor)method on each of the "unit" classes and call that from our side. That would make it super easy to extend the behavior with custom units (e.g., rotations through gearing or feet of travel) and remove the need for a chain ofifs.dwalton76 commentedon Oct 10, 2017
I like that...let me try this out and will update the PRs
WasabiFan commentedon Oct 10, 2017
The one downside I see to this approach is that if we intend to recommend the
from ev3dev.motor import Motor, OUTPUT_A, OUTPUT_B, ...approach you'll have to manually import each of the unit types, which is a pain.dwalton76 commentedon Oct 10, 2017
yeah but I bet most programs only use one speed unit so hopefully won't be bad....new code posted