def drawTo(x,y,segmentLength): # Assume coords are in mm so convert to native by calling ik.getStringLengths(x,y) # ik.getStringLengths(x,y) returns a tuple with 4 items, a pair of native coords # followed by the string length in mm nativeCoords = ik.getStringLengths(x,y) # As this is a move, drop the pen first just to be sure pen("down") command = "C17," + str(nativeCoords[0]) + "," + str(nativeCoords[1]) + "," + str(segmentLength) + ",END\n" print("Debug: drawTo(%s,%s) Command to run: %s" % ( x,y,(command,))) writeCommandToPolargraph(command)
polargraphHomeYInMM = 120 # Home position Y polargraphPulleyCircumferenceInMM = 92 # Effective circumference of pulleys polargraphStepsPerRev = 200 # Number of whole steps per revolution for motors polargraphStepsMultiplier = 16 # Stepper driver multiplier polargraphMotorMaxSpeed = 1200 # Max motor speed polargraphMotorAcceleration = 800 # How quickly the motor accelerates to get to its top speed polargraphPenUpSetting = 63 # Servo 'up' position polargraphPenDownSetting = 125 # Servo 'down' position pageWidthInMM = 420 # Drawing area in mm pageHeightInMM = 594 # Drawing area in mm pageXOffsetInMM = 95 # How far (in mm) from the edge of the left pullley is the paper? pageYOffsetInMM = 240 # How far (in mm) down from the imaginary line drawn between motor spindles? # Calculate where the home position is in steps (Tested this and it revealed an error in my previously asserted home position. Updated measurements) polargraphHomeXInSteps, polargraphHomeYInSteps, len1, len2 = ik.getStringLengths(polargraphHomeXInMM, polargraphHomeYInMM) print("Debug: Calculated home position = %s, %s, lengths %s, %s" %(polargraphHomeXInSteps, polargraphHomeXInSteps, len1, len2)) # Grid dimensions # (Define the grid cell size and the grid is calculated from that and the page width. An offset is also calculated # to allow centering the grid within the page or drawing area) cellWidthInMM = 10 cellHeightInMM = 25 numberOfCols = int(math.floor(pageWidthInMM / cellWidthInMM)) numberOfRows = int(math.floor(pageHeightInMM / cellHeightInMM)) xOffSetRemainder = math.floor((pageWidthInMM - (numberOfCols * cellWidthInMM)) / 2) yOffSetRemainder = math.floor((pageHeightInMM - (numberOfRows * cellHeightInMM)) / 2) # Global variable for serial coms function # This exists to tell the next call of the comms functions