Skip to content

Commit 8874b00

Browse files
authored
Add named getters to check "state" of motor (#310)
See #297
1 parent 1e5c835 commit 8874b00

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

ev3dev/core.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,40 @@ def reset(self, **kwargs):
845845
self.command = self.COMMAND_RESET
846846

847847

848+
# ~autogen
849+
# ~autogen motor_states classes.motor>currentClass
850+
851+
@property
852+
def is_running(self):
853+
"""Power is being sent to the motor.
854+
"""
855+
return self.STATE_RUNNING in self.state
856+
857+
@property
858+
def is_ramping(self):
859+
"""The motor is ramping up or down and has not yet reached a constant output level.
860+
"""
861+
return self.STATE_RAMPING in self.state
862+
863+
@property
864+
def is_holding(self):
865+
"""The motor is not turning, but rather attempting to hold a fixed position.
866+
"""
867+
return self.STATE_HOLDING in self.state
868+
869+
@property
870+
def is_overloaded(self):
871+
"""The motor is turning, but cannot reach its `speed_sp`.
872+
"""
873+
return self.STATE_OVERLOADED in self.state
874+
875+
@property
876+
def is_stalled(self):
877+
"""The motor is not turning when it should be.
878+
"""
879+
return self.STATE_STALLED in self.state
880+
881+
848882
# ~autogen
849883

850884
def wait(self, cond, timeout=None):

templates/motor_states.liquid

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{% assign class_name = currentClass.friendlyName | camel_case | capitalize %}{%
2+
for prop in currentClass.propertyValues %}{%
3+
if prop.propertyName == "State" %}{%
4+
for state in prop.values %}
5+
@property
6+
def is_{{ state.name }}(self):
7+
"""{%
8+
for line in state.description %}{{line}}
9+
{% endfor %}"""
10+
return self.STATE_{{ state.name | upcase }} in self.state
11+
{% endfor %}{%
12+
endif %}{%
13+
endfor %}

0 commit comments

Comments
 (0)