Skip to content

Commit ba5895c

Browse files
committed
Merge tag 'v1.6.6' into develop
v1.6.6
2 parents 59742c8 + 1faf319 commit ba5895c

File tree

4 files changed

+77
-55
lines changed

4 files changed

+77
-55
lines changed

README.md

+59-48
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# mm-python-api
2-
MachineMotion Python API
3-
41
# How-to Guide: MachineMotion Python SDK
52

63
<div style="text-align: center;"><img src="https://s3.amazonaws.com/ventioncms/vention_images/images/000/001/021/large/cover_python_guide.png?1550698357" width="80%" /></div>
@@ -11,7 +8,21 @@ MachineMotion Python API
118

129
This guide will cover the setup and use of Vention’s MachineMotion™ Python Software Development Kit (SDK). After reading this guide, you will be ready to deploy custom motion and control applications using Vention’s MachineMotion controller. Before you begin, we recommended reading the <a href="https://www.vention.io/technical_documents/machine_motion_docs/vention_machine_motion_user_guide" target="_blank">MachineMotion Quick Start Guide</a> to get familiar with the technology.
1310

14-
## Typical System Overview
11+
## Overview
12+
13+
The MachineMotion python SDK has been designed to allow user applications to execute:
14+
15+
>- internally to MachineMotion; or
16+
>- on an external computer connected to MachineMotion via the USB or Ethernet port.
17+
18+
The Python SDK includes the following core features:
19+
20+
>- Simplied interface to all MachineMotion functionality
21+
>- Control of one or multiple MachineMotion from a single program
22+
>- Direct access to the internal motion controller via gCode
23+
24+
25+
---
1526

1627
Many systems are built by centralizing application-level software on a host computer. The software interacts with various devices (such as robotic devices, sensors, proprietary products, and data acquisition equipment) and delivers the required application behavior (see Figure 1).
1728

@@ -98,11 +109,11 @@ from _MachineMotion import *
98109

99110
# Define a callback to process controller gCode responses
100111
def templateCallback(data):
101-
print "Controller gCode responses " + data
112+
print ( "Controller gCode responses " + data )
102113

103114
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
104115

105-
print "Controller connected"
116+
print ( "Controller connected" )
106117
```
107118

108119
#### Output
@@ -143,13 +154,13 @@ from _MachineMotion import *
143154

144155
# Define a callback to process controller gCode responses (if desired)
145156
def templateCallback(data):
146-
print "Controller gCode responses " + data
157+
print ( "Controller gCode responses " + data )
147158

148159
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
149160

150161
machine_motion_example = machine_motion_example.configMachineMotionIp(NETWORK_MODE.static, "192.168.0.2", "255.255.255.0", "192.168.0.1")
151162

152-
print "--> Controller connected & ethernet interface configured (static)"
163+
print ( "--> Controller connected & ethernet interface configured (static)" )
153164
```
154165

155166
#### Output 1
@@ -170,13 +181,13 @@ from _MachineMotion import *
170181

171182
# Define a callback to process controller gCode responses (if desired)
172183
def templateCallback(data):
173-
print "Controller gCode responses " + data
184+
print ( "Controller gCode responses " + data )
174185

175186
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
176187

177188
machine_motion_example = machine_motion_example.configMachineMotionIp(NETWORK_MODE.dhcp, "", "", "")
178189

179-
print "--> Controller connected & ethernet interface configured (dhcp)"
190+
print ( "--> Controller connected & ethernet interface configured (dhcp)" )
180191
```
181192

182193
#### Output 2
@@ -213,14 +224,14 @@ from _MachineMotion import *
213224

214225
# Define a callback to process controller gCode responses (if desired)
215226
def templateCallback(data):
216-
print "Controller gCode responses " + data
227+
print ( "Controller gCode responses " + data )
217228

218229
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
219230

220231
# Configure the axis number one, 8 uSteps and 150 mm / turn for a timing belt
221232
machine_motion_example = machine_motion_example.configAxis(1, MICRO_STEPS.ustep_8, MECH_GAIN.timing_belt_150mm_turn)
222233

223-
print "--> Controller axis 1 configured"
234+
print ( "--> Controller axis 1 configured" )
224235
```
225236

226237
#### Output
@@ -256,14 +267,14 @@ from _MachineMotion import *
256267

257268
# Define a callback to process controller gCode responses (if desired)
258269
def templateCallback(data):
259-
print "Controller gCode responses " + data
270+
print ( "Controller gCode responses " + data )
260271

261272
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
262273

263274
# Saving a string on the controller
264275
machine_motion_example = machine_motion_example.saveData("data_1", "save_this_string_on_the_controller")
265276

266-
print "--> Data sent on controller"
277+
print ( "--> Data sent on controller" )
267278
```
268279

269280
---
@@ -285,11 +296,11 @@ from _MachineMotion import *
285296

286297
# Define a callback to process controller gCode responses (if desired)
287298
def templateCallback(data):
288-
print "Controller gCode responses " + data
299+
print ( "Controller gCode responses " + data )
289300

290301
# Define a callback to print the data retrieved using the getData function
291302
def printGetDataResult(data):
292-
print "--> Retrieved data = " + data
303+
print ( "--> Retrieved data = " + data )
293304

294305
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
295306

@@ -328,7 +339,7 @@ from _MachineMotion import *
328339

329340
# Define a callback to process controller gCode responses (if desired)
330341
def templateCallback(data):
331-
print "Controller gCode responses " + data
342+
print ( "Controller gCode responses " + data )
332343

333344
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
334345

@@ -337,7 +348,7 @@ machine_motion_example.emitHome(1)
337348
# Wait for the message to be acknowledged by the motion controller
338349
while machine_motion_example.isReady() != "true": pass
339350

340-
print "--> This line executes after the motion controller has acknowledged receipt of the command."
351+
print ( "--> This line executes after the motion controller has acknowledged receipt of the command." )
341352

342353
```
343354

@@ -371,7 +382,7 @@ from _MachineMotion import *
371382

372383
# Define a callback to process controller gCode responses (if desired)
373384
def templateCallback(data):
374-
print "Controller gCode responses " + data
385+
print ( "Controller gCode responses " + data )
375386

376387
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
377388

@@ -381,7 +392,7 @@ machine_motion_example.emitHome(1)
381392
while machine_motion_example.isReady() != "true": pass
382393
machine_motion_example.waitForMotionCompletion()
383394

384-
print "--> This line executes after the motion controller has acknowledged the reception of the command."
395+
print ( "--> This line executes after the motion controller has acknowledged the reception of the command." )
385396

386397
```
387398

@@ -425,14 +436,14 @@ from _MachineMotion import *
425436

426437
# Define a callback to process controller gCode responses (if desired)
427438
def templateCallback(data):
428-
print "Controller gCode responses " + data
439+
print ( "Controller gCode responses " + data )
429440

430441
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
431442

432443
# Send a stop command to the machine (this works even if the machine has not started moving yet)
433444
machine_motion_example.emitStop()
434445

435-
print "--> Machine Stopped"
446+
print ( "--> Machine Stopped" )
436447

437448
```
438449

@@ -464,15 +475,15 @@ from _MachineMotion import *
464475

465476
# Define a callback to process controller gCode responses (if desired)
466477
def templateCallback(data):
467-
print "Controller gCode responses " + data
478+
print ( "Controller gCode responses " + data )
468479

469480
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
470481

471482
# Homing all the axes of the controller sequentially
472483
machine_motion_example.emitHomeAll()
473484
machine_motion_example.waitForMotionCompletion()
474485

475-
print "--> All axes are now at home position."
486+
print ( "--> All axes are now at home position." )
476487

477488
```
478489

@@ -495,15 +506,15 @@ from _MachineMotion import *
495506

496507
# Define a callback to process controller gCode responses (if desired)
497508
def templateCallback(data):
498-
print "Controller gCode responses " + data
509+
print ( "Controller gCode responses " + data )
499510

500511
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
501512

502513
# Homing axis 1
503514
machine_motion_example.emitHome(1)
504515
machine_motion_example.waitForMotionCompletion()
505516

506-
print "--> Axis 1 is now at home position."
517+
print ( "--> Axis 1 is now at home position." )
507518

508519
```
509520

@@ -549,14 +560,14 @@ from _MachineMotion import *
549560

550561
# Define a callback to process controller gCode responses (if desired)
551562
def templateCallback(data):
552-
print "Controller gCode responses " + data
563+
print ( "Controller gCode responses " + data )
553564

554565
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
555566

556567
# Configuring the travel speed to 10,000 mm / min
557568
machine_motion_example.emitSpeed(10000)
558569

559-
print "--> Machine moves are not set to 10 000 mm / min"
570+
print ( "--> Machine moves are not set to 10 000 mm / min" )
560571

561572
```
562573

@@ -578,14 +589,14 @@ from _MachineMotion import *
578589

579590
# Define a callback to process controller gCode responses (if desired)
580591
def templateCallback(data):
581-
print "Controller gCode responses " + data
592+
print ( "Controller gCode responses " + data )
582593

583594
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
584595

585596
# Configuring the travel speed to 1000 mm / second^2
586597
machine_motion_example.emitAcceleration(1000)
587598

588-
print "--> Machine moves are not set to accelerate @ 1000 mm / second^2"
599+
print ( "--> Machine moves are not set to accelerate @ 1000 mm / second^2" )
589600

590601
```
591602

@@ -642,7 +653,7 @@ machine_motion_example.waitForMotionCompletion()
642653
machine_motion_example.emitAbsoluteMove(1, 100)
643654
machine_motion_example.waitForMotionCompletion()
644655

645-
print "--> Example completed."
656+
print ( "--> Example completed." )
646657

647658
```
648659

@@ -694,7 +705,7 @@ from _MachineMotion import *
694705

695706
# Define a callback to process controller gCode responses (if desired)
696707
def templateCallback(data):
697-
print "Controller gCode responses " + data
708+
print ( "Controller gCode responses " + data )
698709

699710
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
700711

@@ -715,7 +726,7 @@ machine_motion_example.waitForMotionCompletion()
715726
machine_motion_example.emitRelativeMove(1, "negative", 100)
716727
machine_motion_example.waitForMotionCompletion()
717728

718-
print "--> Example completed."
729+
print ( "--> Example completed." )
719730

720731
```
721732

@@ -764,7 +775,7 @@ from _MachineMotion import *
764775

765776
# Define a callback to process controller gCode responses (if desired)
766777
def templateCallback(data):
767-
print "Controller gCode responses " + data
778+
print ( "Controller gCode responses " + data )
768779

769780
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
770781

@@ -782,7 +793,7 @@ machine_motion_example.waitForMotionCompletion()
782793
machine_motion_example.emitgCode("G0 X500 Y500 F10000")
783794
machine_motion_example.waitForMotionCompletion()
784795

785-
print "--> Example completed."
796+
print ( "--> Example completed." )
786797

787798
```
788799

@@ -863,11 +874,11 @@ from _MachineMotion import *
863874

864875
# Define a callback to process controller gCode responses (if desired)
865876
def templateCallback(data):
866-
print "Controller gCode responses " + data
877+
print ( "Controller gCode responses " + data )
867878

868879
# Define a callback to invoke when a control device is attached to the controller
869880
def attachControlDeviceCallback(data):
870-
print "Attach control device callback: " + data
881+
print ( "Attach control device callback: " + data )
871882

872883
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
873884

@@ -900,11 +911,11 @@ from _MachineMotion import *
900911

901912
# Define a callback to process controller gCode responses (if desired)
902913
def templateCallback(data):
903-
print "Controller gCode responses " + data
914+
print ( "Controller gCode responses " + data )
904915

905916
# Define a callback to invoke when a control device is attached to the controller
906917
def attachControlDeviceCallback(data):
907-
print "Attach control device callback: " + data
918+
print ( "Attach control device callback: " + data )
908919

909920
# Define a callback to invoke when a control device is detached from the controller
910921
def detachControlDeviceCallback(data):
@@ -952,19 +963,19 @@ from _MachineMotion import *
952963

953964
# Define a callback to process controller gCode responses (if desired)
954965
def templateCallback(data):
955-
print "Controller gCode responses " + data
966+
print ( "Controller gCode responses " + data )
956967

957968
# Define a callback to invoke when a control device is attached to the controller
958969
def attachControlDeviceCallback(data):
959-
print "Attach control device callback: " + data
970+
print ( "Attach control device callback: " + data )
960971

961972
# Define a callback to invoke when a control device is detached from the controller
962973
def detachControlDeviceCallback(data):
963-
print "Detach control device callback: " + data
974+
print ( "Detach control device callback: " + data )
964975

965976
# Define a callback to invoke when a control device is read
966977
def readControlDeviceCallback(data):
967-
print "Read control device callback: " + data
978+
print ( "Read control device callback: " + data )
968979

969980
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
970981

@@ -1009,23 +1020,23 @@ from _MachineMotion import *
10091020

10101021
# Define a callback to process controller gCode responses (if desired)
10111022
def templateCallback(data):
1012-
print "Controller gCode responses " + data
1023+
print ( "Controller gCode responses " + data )
10131024

10141025
# Define a callback to invoke when a control device is attached to the controller
10151026
def attachControlDeviceCallback(data):
1016-
print "Attach control device callback: " + data
1027+
print ( "Attach control device callback: " + data )
10171028

10181029
# Define a callback to invoke when a control device is detached from the controller
10191030
def detachControlDeviceCallback(data):
1020-
print "Detach control device callback: " + data
1031+
print ( "Detach control device callback: " + data )
10211032

10221033
# Define a callback to invoke when a control device is read
10231034
def readControlDeviceCallback(data):
1024-
print "Read control device callback: " + data
1035+
print ( "Read control device callback: " + data )
10251036

10261037
# Define a callback to invoke when a control device is written
10271038
def writeControlDeviceCallback(data):
1028-
print "Write control device callback: " + data
1039+
print ( "Write control device callback: " + data )
10291040

10301041
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
10311042

_MachineMotion.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ def writeControlDevice(self, port, signal, value, callback):
682682
if port not in self.attachedDevices.keys() or self.attachedDevices[port] == "IO_EXPANDER_GENERIC":
683683
portNumber = self.validPorts.index(port) + 1
684684
signalNumber = self.validSignals.index(signal) - 4
685-
self.myMqttClient.publish('digitalOutput/' + str(portNumber) + '/' + str(signalNumber), '1' if value else '0')
685+
self.myMqttClient.publish('devices/io-expander/' + str(portNumber) + '/digitalOutput/' + str(signalNumber), '1' if value else '0')
686686
callback("true" if value else "false")
687687
# Legacy devices
688688
else :
@@ -700,13 +700,13 @@ def writeControlDevice(self, port, signal, value, callback):
700700

701701
def __onConnect(self, client, userData, flags, rc):
702702
if rc == 0:
703-
self.myMqttClient.subscribe('digitalInput/#')
703+
self.myMqttClient.subscribe('devices/io-expander/+/digitalInput')
704704

705705
def __onMessage(self, client, userData, msg):
706-
port = int(msg.topic.replace('digitalInput/', '')) - 1
706+
device = int(msg.topic.replace('devices/io-expander/', '').replace('/digitalInput', '')) - 1
707707
values = int(msg.payload, 16)
708-
if(port >= 0 and port < len(self.validPorts)) :
709-
self.portInputs[self.validPorts[port]] = values
708+
if(device >= 0 and device < len(self.validPorts)) :
709+
self.portInputs[self.validPorts[device]] = values
710710

711711
def __onDisconnect(self, client, userData, rc):
712712
print("Disconnected with rtn code [%d]"% (rc) )

0 commit comments

Comments
 (0)