1
- # File name: _MachineMotion_1_6_5.py #
2
- # Version: 1.6.5 #
1
+ # File name: _MachineMotion.py #
3
2
# Author: Francois Giguere #
4
3
# Note: Information about all the g-Code #
5
4
# commands supported are available at #
15
14
import paho .mqtt .client as mqtt
16
15
17
16
# Misc. Variables
18
- motion_completed = "false"
19
- waiting_motion_status = "false"
17
+ motion_completed = "false"
18
+ waiting_motion_status = "false"
19
+ waiting_current_position = "false"
20
20
21
21
machineMotionRef = None
22
22
gCodeCallbackRef = None
@@ -103,6 +103,11 @@ class GCode:
103
103
lastPacket = {"data" : "null" , "lineNumber" : "null" }
104
104
gCodeErrors = {"checksum" : "Error:checksum mismatch, Last Line: " , "lineNumber" : "Error:Line Number is not Last Line Number+1, Last Line: " }
105
105
userCallback = None
106
+ currentPositions = {
107
+ 1 : None ,
108
+ 2 : None ,
109
+ 3 : None
110
+ }
106
111
107
112
#
108
113
# Class constructor
@@ -254,6 +259,7 @@ def __userCallback__(data): return
254
259
def __rxCallback__ (self , data ):
255
260
256
261
global waiting_motion_status
262
+ global waiting_current_position
257
263
global lastSendTimeStamp
258
264
259
265
# print "DEBUG---Last command sent: " + str(self.lastPacket)
@@ -290,6 +296,15 @@ def __rxCallback__(self, data):
290
296
elif (data .find ('Resend:' ) != - 1 ):
291
297
self .lineNumber = self .__extractLineNumberInResend__ (data )
292
298
299
+ if data .find ('Count X:' ) != - 1 :
300
+ # print 'Current position : ' + data
301
+
302
+ self .currentPositions [1 ] = float (data [data .find ('X' )+ 2 :(data .find ('Y' )- 1 )])
303
+ self .currentPositions [2 ] = float (data [data .find ('Y' )+ 2 :(data .find ('Z' )- 1 )])
304
+ self .currentPositions [3 ] = float (data [data .find ('Z' )+ 2 :(data .find ('E' )- 1 )])
305
+
306
+ waiting_current_position = "false"
307
+
293
308
fastMotionStatusCallback (data , self )
294
309
295
310
self .__userCallback__ (data )
@@ -425,7 +440,16 @@ def isEncoderIdValid(self, id):
425
440
if id >= 0 and id <= 3 :
426
441
return True
427
442
return False
428
-
443
+
444
+
445
+ def getCurrentPositions (self ):
446
+ global waiting_current_position
447
+
448
+ waiting_current_position = "true"
449
+ self .myGCode .__emit__ ("M114" )
450
+ while self .isReady () != "true" and waiting_current_position == "true" : pass
451
+
452
+ return self .myGCode .currentPositions
429
453
430
454
#
431
455
# Function that will immediately stop all motion of all the axes
@@ -505,6 +529,31 @@ def emitAbsoluteMove(self, axis, position):
505
529
self .myGCode .__emit__ ("G0 " + self .myGCode .__getTrueAxis__ (axis ) + str (position ))
506
530
while self .isReady () != "true" : pass
507
531
532
+ #
533
+ # Function to send an absolute move command to the MachineMotion controller. This command can move more than one axis simultaneously
534
+ # @param axes --- Description: axes are the axes on which the command will be applied. Example : [1, 2, 3] --- Type: list of strings or numbers.
535
+ # @param positions --- Description: positions are the positions from their home location where the axes will go. --- Type: list of strings or numbers.
536
+ # @status
537
+ #
538
+ def emitCombinedAxesAbsoluteMove (self , axes , positions ):
539
+ if (not isinstance (axes , list ) or not isinstance (positions , list )):
540
+ raise TypeError ("Axes and Postions must be lists" )
541
+
542
+ global motion_completed
543
+
544
+ motion_completed = "false"
545
+
546
+ # Set to absolute motion mode
547
+ self .myGCode .__emit__ ("G90" )
548
+ while self .isReady () != "true" : pass
549
+
550
+ # Transmit move command
551
+ command = "G0 "
552
+ for axis , position in zip (axes , positions ):
553
+ command += self .myGCode .__getTrueAxis__ (axis ) + str (position ) + " "
554
+ self .myGCode .__emit__ (command )
555
+ while self .isReady () != "true" : pass
556
+
508
557
#
509
558
# Function to send a relative move command to the MachineMotion controller
510
559
# @param axis --- Description: axis is the axis on which the command will be applied. --- Type: int or string.
@@ -528,6 +577,34 @@ def emitRelativeMove(self, axis, direction, distance):
528
577
self .myGCode .__emit__ ("G0 " + self .myGCode .__getTrueAxis__ (axis ) + str (distance ))
529
578
while self .isReady () != "true" : pass
530
579
580
+ #
581
+ # Function to send a relative move command to the MachineMotion controller
582
+ # @param axes --- Description: axes are the axes on which the command will be applied. Example : [1, 2, 3] --- Type: list of strings or numbers.
583
+ # @param directions --- Description: direction are the directions in which the relative moves will be conducted. --- Type: list of strings of value equal to "positive" or "negative"
584
+ # @param distances are the distances of the relative moves --- Type: list of strings or numbers.
585
+ # @status
586
+ #
587
+ def emitCombinedAxisRelativeMove (self , axes , directions , distances ):
588
+ if (not isinstance (axes , list ) or not isinstance (directions , list ) or isinstance (distances , list )):
589
+ raise TypeError ("Axes and Postions must be lists" )
590
+
591
+ global motion_completed
592
+
593
+ motion_completed = "false"
594
+
595
+ # Set to relative motion mode
596
+ self .myGCode .__emit__ ("G91" )
597
+ while self .isReady () != "true" : pass
598
+
599
+ # Transmit move command
600
+ command = "G0 "
601
+ for axis , direction , distance in zip (axes , directions , distances ):
602
+ if direction == "positive" : distance = "" + str (distance )
603
+ elif direction == "negative" : distance = "-" + str (distance )
604
+ command += self .myGCode .__getTrueAxis__ (axis ) + str (distance ) + " "
605
+ self .myGCode .__emit__ (command )
606
+ while self .isReady () != "true" : pass
607
+
531
608
#
532
609
# Function to send a raw G-Code ASCII command
533
610
# @param gCode --- Description: gCode is string representing the G-Code command to send to the controller. Type: string.
@@ -556,6 +633,9 @@ def isMotionCompleted(self):
556
633
return motion_completed
557
634
558
635
def waitForMotionCompletion (self ):
636
+ global waiting_motion_status
637
+
638
+ waiting_motion_status = "true"
559
639
self .emitgCode ("V0" )
560
640
while self .isMotionCompleted () != "true" : pass
561
641
0 commit comments