Arduino Drawing Robot
I wrote a Pythons script that will take in a NURBS curve motion path from Maya and prints out the Turtle Code to draw the NURBS curve IRL.
This project is based on 3D printed, Arduino powered Drawbot I found on Instructables.
Here is the final video of the drawbot creating the Open Hardware Logo with the Turtle Code generated from my Python script.
This is the Python script running inside Maya and printing out the Turtle Code:
The first field tests were a bit off.
I added a few more decimal places to the turn commands and that got the result much closer to the desired output.
This is the first boot up test before the batteries were installed. It’s running the 4 square calibration code, though the motor steps are incorrect.
Here is Python Script that will print out the Turtle Code.
Import your path into Maya (or draw it with the pencil tool) and attach the drawbot to it with the “attach to motion path” command (Animate>Motion Paths>Attach to Motion Path). Here is an example Maya scene to get you started: drawbot_master
Make sure your scene is scaled correctly. I also found baking the drawbot trans and rotation channels before running this script gave better results.
#Be sure to bake the motion path before running this script
import maya.cmds as cmds
from pymel.all import *
import pymel.core.datatypes as dt
import maya.mel as mel
startFrame = cmds.playbackOptions(query=True, minTime=True)
endFrame = cmds.playbackOptions(query=True, maxTime=True)
mel.eval('cycleCheck -e off')
for x in xrange(int(startFrame),int(endFrame + 1)):
#advance frame before each iteration
#Find Rotation Change
if x == 1:
currentRot = 0
previousRot = cmds.getAttr('drawbot.rotateY')
angleDelta = math.floor(currentRot - previousRot)
currentRot = previousRot
if angleDelta < 0 :
print 'left(%.3f);' % abs(angleDelta)
if angleDelta > 0 :
print 'right(%.3f);' % angleDelta
#Find Position Change
if x == 1:
currentPos = dt.Vector(0, 0, 0)
previousPos = dt.Vector(cmds.getAttr('drawbot.translate'))
distanceTraveled = currentPos.distanceTo(previousPos)
currentPos = previousPos
if distanceTraveled != 0:
print 'forward(%.3f);' % distanceTraveled
#set current frame back to 1