Skip to content

Instantly share code, notes, and snippets.

@tanyuan
Last active February 15, 2018 05:33
Show Gist options
  • Save tanyuan/640e970ef2da6c0b3bda560d29a7f818 to your computer and use it in GitHub Desktop.
Save tanyuan/640e970ef2da6c0b3bda560d29a7f818 to your computer and use it in GitHub Desktop.
Control MakerBot movement using Python

MakerBot s3g Protocal

https://github.com/makerbot/s3g

Dependencies

pip install pyserial makerbot_driver

Troubleshooting

Must turn off MakerBot backgound service so serial port is available.

Menu > Services > Stop Background Service
import makerbot_driver, serial, threading, time
port = '/dev/tty.usbmodem1411'
print('Connecting to serial port '+port)
r = makerbot_driver.s3g()
file = serial.Serial('/dev/tty.usbmodem1411', 115200, timeout=1)
r.writer = makerbot_driver.Writer.StreamWriter(file, threading.Condition())
print('Connected to MakerBot successfully!')
# queue_extended_point([X, Y, Z, A, B], rate, 0, 0)
# X from -10000 to +10000 (left to right)
# Y from -5000 to +5000 (front to rear)
# Z from 0 to -48000 (bottom to top, almost touch extruder)
xBegin = -10000
xEnd = 10000
xStep = 1000
yBegin = -5000
yEnd = 5000
yStep = 1000
zBegin = 0
zEnd = -10000
zStep = -1000
print('Go to initial position ...')
#r.queue_extended_point([xBegin, yBegin, zBegin, 0, 0], 400, 0, 0)
r.queue_extended_point([xBegin, yBegin, -48000, 0, 0], 400, 0, 0)
# Some time to go to initial position
time.sleep(10)
print('Start running test positions ...')
# Scanline method
for z in range(zBegin, zEnd+zStep, zStep):
for y in range(yBegin, yEnd+yStep, yStep):
for x in range(xBegin, xEnd+xStep, xStep):
print('('+str(x)+', '+str(y)+', '+str(z)+')')
r.queue_extended_point([x, y, z, 0, 0], 400, 0, 0)
if x == xBegin:
# Move time: move from xEnd to xBegin
time.sleep(10)
else:
# Move time: safe delay 1 second for 1000 steps
time.sleep(1)
print('Go to initial position ...')
r.queue_extended_point([xBegin, 0, 0, 0, 0], 400, 0, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment