Skip to content

Commit ee8b1cb

Browse files
committed
Merge branch 'release/v2.0'
2 parents 8c51d7a + e0905e2 commit ee8b1cb

File tree

2 files changed

+88
-9
lines changed

2 files changed

+88
-9
lines changed

_MachineMotion.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# File name: _MachineMotion_1_6_5.py #
2-
# Version: 1.6.5 #
1+
# File name: _MachineMotion.py #
32
# Author: Francois Giguere #
43
# Note: Information about all the g-Code #
54
# commands supported are available at #
@@ -15,8 +14,8 @@
1514
import paho.mqtt.client as mqtt
1615

1716
# Misc. Variables
18-
motion_completed = "false"
19-
waiting_motion_status = "false"
17+
motion_completed = "false"
18+
waiting_motion_status = "false"
2019
waiting_current_position = "false"
2120

2221
machineMotionRef = None

examples/_MachineMotion.py

+85-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# File name: _MachineMotion_1_6_5.py #
2-
# Version: 1.6.5 #
1+
# File name: _MachineMotion.py #
32
# Author: Francois Giguere #
43
# Note: Information about all the g-Code #
54
# commands supported are available at #
@@ -15,8 +14,9 @@
1514
import paho.mqtt.client as mqtt
1615

1716
# 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"
2020

2121
machineMotionRef = None
2222
gCodeCallbackRef = None
@@ -103,6 +103,11 @@ class GCode:
103103
lastPacket = {"data": "null", "lineNumber": "null"}
104104
gCodeErrors = {"checksum": "Error:checksum mismatch, Last Line: ", "lineNumber": "Error:Line Number is not Last Line Number+1, Last Line: "}
105105
userCallback = None
106+
currentPositions = {
107+
1 : None,
108+
2 : None,
109+
3 : None
110+
}
106111

107112
#
108113
# Class constructor
@@ -254,6 +259,7 @@ def __userCallback__(data): return
254259
def __rxCallback__(self, data):
255260

256261
global waiting_motion_status
262+
global waiting_current_position
257263
global lastSendTimeStamp
258264

259265
# print "DEBUG---Last command sent: " + str(self.lastPacket)
@@ -290,6 +296,15 @@ def __rxCallback__(self, data):
290296
elif (data.find('Resend:') != -1):
291297
self.lineNumber = self.__extractLineNumberInResend__(data)
292298

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+
293308
fastMotionStatusCallback(data, self)
294309

295310
self.__userCallback__(data)
@@ -425,7 +440,16 @@ def isEncoderIdValid(self, id):
425440
if id >= 0 and id <= 3:
426441
return True
427442
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
429453

430454
#
431455
# Function that will immediately stop all motion of all the axes
@@ -505,6 +529,31 @@ def emitAbsoluteMove(self, axis, position):
505529
self.myGCode.__emit__("G0 " + self.myGCode.__getTrueAxis__(axis) + str(position))
506530
while self.isReady() != "true": pass
507531

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+
508557
#
509558
# Function to send a relative move command to the MachineMotion controller
510559
# @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):
528577
self.myGCode.__emit__("G0 " + self.myGCode.__getTrueAxis__(axis) + str(distance))
529578
while self.isReady() != "true": pass
530579

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+
531608
#
532609
# Function to send a raw G-Code ASCII command
533610
# @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):
556633
return motion_completed
557634

558635
def waitForMotionCompletion(self):
636+
global waiting_motion_status
637+
638+
waiting_motion_status = "true"
559639
self.emitgCode("V0")
560640
while self.isMotionCompleted() != "true": pass
561641

0 commit comments

Comments
 (0)