Skip to content

Commit 4a30e8d

Browse files
committed
Improved autogen helper functions for motor control
1 parent c48fa52 commit 4a30e8d

File tree

1 file changed

+130
-2
lines changed

1 file changed

+130
-2
lines changed

ev3dev/ev3dev.py

Lines changed: 130 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,8 +531,59 @@ def __set_time_sp(self, value):
531531
#~autogen
532532
#~autogen python_generic-helper-function classes.motor>currentClass
533533

534-
def foo:
535-
pass
534+
_properties = [
535+
'command'
536+
, 'duty_cycle_sp'
537+
, 'encoder_polarity'
538+
, 'polarity'
539+
, 'position'
540+
, 'hold_pid/Kp'
541+
, 'hold_pid/Ki'
542+
, 'hold_pid/Kd'
543+
, 'position_sp'
544+
, 'speed_sp'
545+
, 'ramp_up_sp'
546+
, 'ramp_down_sp'
547+
, 'speed_regulation'
548+
, 'speed_pid/Kp'
549+
, 'speed_pid/Ki'
550+
, 'speed_pid/Kd'
551+
, 'stop_command'
552+
, 'time_sp' ]
553+
554+
def _helper( self, **kwargs ):
555+
for p,v in kwargs.iteritems():
556+
if p in self._properties:
557+
self._set_int_attribute( p, p, v )
558+
559+
def run_forever( self, **kwargs ):
560+
self._helper( **kwargs )
561+
self._set_string_attribute( 'command', 'command', 'run-forever' )
562+
563+
def run_to_abs_pos( self, **kwargs ):
564+
self._helper( **kwargs )
565+
self._set_string_attribute( 'command', 'command', 'run-to-abs-pos' )
566+
567+
def run_to_rel_pos( self, **kwargs ):
568+
self._helper( **kwargs )
569+
self._set_string_attribute( 'command', 'command', 'run-to-rel-pos' )
570+
571+
def run_timed( self, **kwargs ):
572+
self._helper( **kwargs )
573+
self._set_string_attribute( 'command', 'command', 'run-timed' )
574+
575+
def run_direct( self, **kwargs ):
576+
self._helper( **kwargs )
577+
self._set_string_attribute( 'command', 'command', 'run-direct' )
578+
579+
def stop( self, **kwargs ):
580+
self._helper( **kwargs )
581+
self._set_string_attribute( 'command', 'command', 'stop' )
582+
583+
def reset( self, **kwargs ):
584+
self._helper( **kwargs )
585+
self._set_string_attribute( 'command', 'command', 'reset' )
586+
536587

537588
#~autogen
538589
#~autogen python_generic-class classes.dcMotor>currentClass
@@ -678,6 +729,19 @@ def __get_stop_commands(self):
678729

679730
stop_commands = property( __get_stop_commands, None, None, __doc_stop_commands )
680731

732+
def __get_time_sp(self):
733+
return self._get_int_attribute( 'time_sp', 'time_sp' )
734+
735+
def __set_time_sp(self, value):
736+
self._set_int_attribute( 'time_sp', 'time_sp', value )
737+
738+
__doc_time_sp = (
739+
"Writing specifies the amount of time the motor will run when using the\n"
740+
"`run-timed` command. Reading returns the current value. Units are in\n"
741+
"milliseconds.\n" )
742+
743+
time_sp = property( __get_time_sp, __set_time_sp, None, __doc_time_sp )
744+
681745

682746
#~autogen
683747
#~autogen python_generic-property-value classes.dcMotor>currentClass
@@ -701,6 +765,42 @@ def __get_stop_commands(self):
701765
}
702766

703767
#~autogen
768+
769+
#~autogen python_generic-helper-function classes.dcMotor>currentClass
770+
771+
_properties = [
772+
'command'
773+
, 'duty_cycle_sp'
774+
, 'polarity'
775+
, 'ramp_down_sp'
776+
, 'ramp_up_sp'
777+
, 'stop_command'
778+
, 'time_sp' ]
779+
780+
def _helper( self, **kwargs ):
781+
for p,v in kwargs.iteritems():
782+
if p in self._properties:
783+
self._set_int_attribute( p, p, v )
784+
785+
def run_forever( self, **kwargs ):
786+
self._helper( **kwargs )
787+
self._set_string_attribute( 'command', 'command', 'run-forever' )
788+
789+
def run_timed( self, **kwargs ):
790+
self._helper( **kwargs )
791+
self._set_string_attribute( 'command', 'command', 'run-timed' )
792+
793+
def run_direct( self, **kwargs ):
794+
self._helper( **kwargs )
795+
self._set_string_attribute( 'command', 'command', 'run-direct' )
796+
797+
def stop( self, **kwargs ):
798+
self._helper( **kwargs )
799+
self._set_string_attribute( 'command', 'command', 'stop' )
800+
801+
802+
#~autogen
803+
704804
#~autogen python_generic-class classes.servoMotor>currentClass
705805

706806

@@ -862,6 +962,34 @@ def __get_state(self):
862962
}
863963

864964
#~autogen
965+
966+
#~autogen python_generic-helper-function classes.servoMotor>currentClass
967+
968+
_properties = [
969+
'command'
970+
, 'max_pulse_sp'
971+
, 'mid_pulse_sp'
972+
, 'min_pulse_sp'
973+
, 'polarity'
974+
, 'position_sp'
975+
, 'rate_sp' ]
976+
977+
def _helper( self, **kwargs ):
978+
for p,v in kwargs.iteritems():
979+
if p in self._properties:
980+
self._set_int_attribute( p, p, v )
981+
982+
def run( self, **kwargs ):
983+
self._helper( **kwargs )
984+
self._set_string_attribute( 'command', 'command', 'run' )
985+
986+
def float( self, **kwargs ):
987+
self._helper( **kwargs )
988+
self._set_string_attribute( 'command', 'command', 'float' )
989+
990+
991+
#~autogen
992+
865993
#~autogen python_generic-class classes.sensor>currentClass
866994

867995

0 commit comments

Comments
 (0)