ev3dev-lang-python icon indicating copy to clipboard operation
ev3dev-lang-python copied to clipboard

Implement way to read motor speed in various SpeedValue units

Open WasabiFan opened this issue 7 years ago • 1 comments

Right now, we have a speed property which returns the value in native units. We should implement a way of consuming that value in other units; off the top of my head it would probably be best to either A) add properties like speed_rpm which return appropriate values or B) add static methods like from_native_units to each speed class (as well as some public way to get a number out) so you can do SpeedRPM.from_native_units(motor.speed). I think the former would make the most sense.

WasabiFan avatar Sep 09 '18 08:09 WasabiFan

Just brainstorming: with an overloaded __index__ method we could do something like motor.speed['RPM'] or motor.speed['DPS']. Another (but very similar) option is providing a method taking the units as a string: motor.speed('RPM'), motor.speed('DPS'), motor.speed('native'). The latter could be the default, so that motor.speed() returns native units.

Another option: if we make motor.speed return a SpeedNativeUnits instead of int, then we can provide methods like '.RPM' for all the speed classes: motor.speed.RPM.

ddemidov avatar Sep 09 '18 08:09 ddemidov