diff --git a/dexarm.py b/dexarm.py index a3cc2e6..12f6d5e 100644 --- a/dexarm.py +++ b/dexarm.py @@ -13,7 +13,8 @@ def __init__(self, name, port): #self.ser1 = serial.Serial(port, 115200, timeout=None) #self.is_open = self.ser1.isOpen() - self.stop = False + self.name = name + self.stopped = False self.ser1 = Runtime.start(name,"Serial") self.ser1.connect(port, 115200, 8, 1, 0) self.is_open = self.ser1.isConnected() @@ -23,7 +24,8 @@ def __init__(self, name, port): print('failed to connect to serial port') def stop(self): - self.stop = True + print('dexarm', self.name, 'stopping') + self.stopped = True def _send_cmd1(self, data, wait=True): @@ -77,7 +79,7 @@ def strip_gcode1(self): def process_letter(self, letter): print('opening letter ' + letter) f = open(letter,'r') - for line in f and not self.stop: + for line in f and not self.stopped: if (line.isspace()==False and len(line)>0) : self._send_cmd1(line+'\n') print ('Dexarm1 gcode line: ' + line) diff --git a/joystick.py b/joystick.py index b432b59..30f520c 100644 --- a/joystick.py +++ b/joystick.py @@ -22,6 +22,9 @@ down_dexarm2 = "Left" up_dexarm2 = "Right" stop = "Space" +# stop = "A" +# move_to = "C" +# runtime.setVirtual(True) # start 2 dexarms dexarm1 = Dexarm('serial1', dexarmPort1) @@ -42,6 +45,7 @@ #this is the method in python which receive the data from joystick service #it is triggered only when new data arrive, it's not a loop ! def onJoystickInput(data): + global dexarm1, dexarm2 #this print the name of the key/button you pressed (it's a String) #this print the value of the key/button (it's a Float) print (data) @@ -53,8 +57,11 @@ def onJoystickInput(data): print('moved dexarm1 to 50, 300, 0') #print('moved dexarm1 to test1.gcode') elif (data.id == stop): + print('stopping dexarm1') dexarm1.stop() + print('stopping dexarm2') dexarm2.stop() + print('stopped both arms') elif (data.id == exec_action2): if (data.value == 1): print("executing action2", data.value) @@ -115,4 +122,4 @@ def onJoystickInput(data): print("Moving up dexarm1", data.value) dexarm1.set_relativeUp1() ''' -print('example script loaded') +print('joystick.py loaded')