def printTempTable(printer, temp, tempTable): of = open("/tmp/temptable_printer.txt", "w") of.write("# xxx mat, nozzle, settings...\n") of.write("# basetemp: %d, autoTempFactor: %f\n" % (temp, 0)) of.write("# temp rate steprate timer\n") print "TempTable (basetemp: %d):" % temp mmpermm3 = 1 / MatProfile.getMatArea() spm = PrinterProfile.getStepsPerMM(A_AXIS) for timerValue in tempTable: steprate = fTimer / timerValue speed = (steprate / spm) / mmpermm3 print " Temp: %d, max extrusion: %.1f mm³/s, steps/s: %d, timervalue: %d" % (temp, speed, int(steprate), timerValue) of.write("%d %4.1f %d %d\n" % (temp, speed, int(steprate), timerValue)) temp += 2 of.close()
def __init__(self, comment, displacement_vector, displacement_vector_steps, feedrate, # mm/s maxAccelV, ): RealMove.__init__(self, comment) # # Move distance in XYZ plane # self.distance3 = displacement_vector.length(3) self.advanceData = AdvanceData(self) self.e_steps_per_mm = PrinterProfile.getStepsPerMM(A_AXIS) self.displacement_vector_raw3 = Vector(displacement_vector[:3]) self.displacement_vector_steps_raw3 = displacement_vector_steps[:3] self.direction3 = self.displacement_vector_raw3.normalized() ### Apply extrusion adjust ### if UseExtrusionAdjust: direction5 = displacement_vector.normalized() self.eDistance = displacement_vector[A_AXIS] # xxx todo: add override self.eSteps = displacement_vector_steps[A_AXIS] self.eDirection = self.eDistance / self.distance3 # Compute nominal eSpeed v = VelocityVector32(feedrate*self.eDirection, feedrate = feedrate, direction = self.direction3) self.startSpeed = VelocityOverride(v) self.topSpeed = VelocityOverride(v) self.endSpeed = VelocityOverride(v) # self.__direction5 = displacement_vector.normalized() # av = self.__getMaxAllowedAccelVector5(maxAccelV) accelVector = direction5.scale(_MAX_ACCELERATION) av = accelVector.constrain(maxAccelV) or accelVector # xxx rework accel, store default xyz and eaccel, make start- and eaccel overridable self.startAccel = AccelOverride([av[:3], av[A_AXIS]], self.direction3) self.endAccel = AccelOverride([av[:3], av[A_AXIS]], self.direction3)
def genTempTable(printer): baseTemp = MatProfile.getHotendBaseTemp() area04 = pow(0.4, 2)*math.pi/4 extrusionLow = MatProfile.getBaseExtrusionRate() * (NozzleProfile.getArea() / area04) f = MatProfile.getAutoTempFactor() mmpermm3 = 1 / MatProfile.getMatArea() spm = PrinterProfile.getStepsPerMM(A_AXIS) of = open("/tmp/temptable0.txt", "w") of.write("# xxx mat, nozzle, settings...\n") of.write("# basetemp: %d, autoTempFactor: %f\n" % (baseTemp, f)) of.write("# temp rate steprate timer\n") print "TempTable (basetemp: %d):" % baseTemp table = [] for i in range(NExtrusionLimit): t = baseTemp + i*2 dspeed = i*2 / f speed = extrusionLow + dspeed steprate = speed * mmpermm3 * spm tvs = 1.0/steprate timerValue = int(fTimer / steprate) print " Temp: %d, max extrusion: %.1f mm³/s, steps/s: %d, steprate: %d us, timervalue: %d" % (t, speed, int(steprate), int(tvs*1000000), timerValue) table.append(timerValue) of.write("%d %4.1f %d %d\n" % (t, speed, int(steprate), timerValue)) of.close() return (baseTemp, table)
def planTravelSteps(self, move): if debugMoves: print "***** Start planTravelSteps() *****" move.pprint("planTravelSTeps:") move.state = 3 move.initStepData(StepDataTypeBresenham) # Round step values dispF = move.displacement_vector_steps_raw5 dispS = self.stepRounders.round(dispF) if dispS == emptyVector5: if debugMoves: print "Empty move..." print "***** End planTravelSteps() *****" self.stepRounders.rollback() return move.isStartMove = True self.stepRounders.commit() abs_displacement_vector_steps = vectorAbs(dispS) # Determine the 'lead axis' - the axis with the most steps leadAxis = move.leadAxis(disp=dispS) leadAxis_steps = abs_displacement_vector_steps[leadAxis] dirBits = util.directionBits(dispS, self.printer.curDirBits) if dirBits != self.printer.curDirBits: move.stepData.setDirBits = True move.stepData.dirBits = dirBits self.printer.curDirBits = dirBits steps_per_mm = PrinterProfile.getStepsPerMM(leadAxis) # # Bresenham's variables # move.stepData.setBresenhamParameters(leadAxis, abs_displacement_vector_steps) # # Create a list of stepper pulses # nominalSpeed = abs(move.topSpeed.speed().vv()[leadAxis]) # [mm/s] allowedAccel = move.getMaxAllowedAccelVectorNoAdv5()[leadAxis] v0 = abs(move.startSpeed.speed()[leadAxis]) # [mm/s] nominalSpeed = abs(move.topSpeed.speed()[leadAxis]) # [mm/s] v1 = abs(move.endSpeed.speed()[leadAxis]) # [mm/s] nAccel = 0 if move.accelTime(): accelClocks = util.accelRamp( leadAxis, v0, nominalSpeed, allowedAccel, leadAxis_steps) # maximum number of steps move.stepData.addAccelPulsees(accelClocks) nAccel = len(accelClocks) nDecel = 0 if move.decelTime(): decelClocks = util.decelRamp( leadAxis, nominalSpeed, v1, allowedAccel, leadAxis_steps) # maximum number of steps move.stepData.addDecelPulsees(decelClocks) nDecel = len(decelClocks) # # Linear phase # nLin = leadAxis_steps - (nAccel + nDecel) # print "# linear steps:", nLin if nLin > 0: steps_per_second_nominal = nominalSpeed * steps_per_mm timerValue = fTimer / steps_per_second_nominal move.stepData.setLinTimer(timerValue) else: if nLin < 0: if nAccel and nDecel: # Überschüssige steps im verhältnis von nAccel zu nDecel abschneiden cd = int(-nLin / ((float(nAccel) / nDecel) + 1)) ca = -nLin - cd if ca: del move.stepData.accelPulses[:ca] if cd: del move.stepData.accelPulses[-cd:] assert (len(move.stepData.accelPulses) + len(move.stepData.decelPulses) == leadAxis_steps) elif nAccel: del move.stepData.accelPulses[:-nLin] assert (len(move.stepData.accelPulses) == leadAxis_steps) else: del move.stepData.decelPulses[nLin:] assert (len(move.stepData.decelPulses) == leadAxis_steps) move.stepData.setLinTimer(0xffff) # timerValue = fTimer / steps_per_second_nominal # move.stepData.setLinTimer(timerValue) if debugMoves: print "# of steps for move: ", leadAxis_steps move.pprint("move:") print move.stepData.checkLen(leadAxis_steps) if debugMoves: print "***** End planTravelSteps() *****"
def planSteps(self, move): if debugMoves: print "***** Start planSteps() *****" move.pprint("PlanSTeps:") move.state = 3 dirBits = 0 abs_displacement_vector_steps = [] leadAxis = 0 leadAxis_value = 0 for i in range(5): dirBits += (move.displacement_vector_steps_raw()[i] >= 0) << i adjustedDisplacement = move.displacement_vector_steps_adjusted(NozzleProfile, MatProfile, PrinterProfile) s = abs(adjustedDisplacement[i]) if s > leadAxis_value: leadAxis = i leadAxis_value = s abs_displacement_vector_steps.append(s) if dirBits != self.printer.curDirBits: move.stepData.setDirBits = True move.stepData.dirBits = dirBits self.printer.curDirBits = dirBits steps_per_mm = PrinterProfile.getStepsPerMM(leadAxis) # # Bresenham's variables # deltaLead = abs_displacement_vector_steps[leadAxis] move.stepData.setBresenhamParameters(leadAxis, abs_displacement_vector_steps) # # Create a list of stepper pulses # # debnegtimer nominalSpeed = abs( move.getReachedSpeedV()[leadAxis] ) # [mm/s] reachedSpeedV = move.getReachedSpeedV() reachedSpeedFr = reachedSpeedV.len5() # debnegtimer accel = abs(move.getAllowedAccelVector()[leadAxis]) accel_steps_per_square_second = accel * steps_per_mm # startSpeed = move.getStartFr() # debnegtimer v0 = abs(move.getFeedrateV(move.getStartFr())[leadAxis]) # [mm/s] # endSpeed = move.getEndFr() # debnegtimer v1 = abs(move.getFeedrateV(move.getEndFr())[leadAxis]) # [mm/s] # debnegtimer steps_per_second_0 = steps_per_second_accel = v0 * steps_per_mm steps_per_second_1 = steps_per_second_deccel = v1 * steps_per_mm steps_per_second_nominal = nominalSpeed * steps_per_mm # # Acceleration variables # # tAccel = 0 # [s], sum of all acceeration steptimes # tAccel mit der initialen zeitspanne vorbelegen, da wir bereits im # ersten schleifendurchlauf (d.h. ab t=0) eine beschleunigung haben wollen. tAccel = 1.0 / steps_per_second_0 # [s], sum of all acceeration steptimes tDeccel = 1.0 / steps_per_second_1 stepNr = 0 if debugPlot: accelPlotData = [] deccelPlotData = [] if not circaf(move.getStartFr(), reachedSpeedFr, 0.1) and not circaf(move.getEndFr(), reachedSpeedFr, 0.1): # # Acceleration ramp on both sides. # # Ramp up both sides in parallel to not exeed available steps # done = False while not done and stepNr < deltaLead: done = True # # Compute acceleration timer values # if steps_per_second_accel < steps_per_second_nominal: # # Compute timer value # steps_per_second_accel = min(steps_per_second_0 + tAccel * accel_steps_per_square_second, steps_per_second_nominal) dt = 1.0 / steps_per_second_accel timerValue = int(fTimer / steps_per_second_accel) # print "dt: ", dt*1000000, "[uS]", steps_per_second_accel, "[steps/s], timerValue: ", timerValue if debugPlot: if move.eOnly: accelPlotData.append((steps_per_second_accel/steps_per_mm, 2, dt)) else: accelPlotData.append((steps_per_second_accel/steps_per_mm, 1, dt)) tAccel += dt if timerValue > maxTimerValue24: move.pprint("PlanSTeps:") print "v0: ", dt*1000000, "[uS]", steps_per_second_accel, "[steps/s], timerValue: ", timerValue print "dt: ", dt*1000000, "[uS]", steps_per_second_accel, "[steps/s], timerValue: ", timerValue assert(0) move.stepData.addAccelPulse(timerValue) stepNr += 1 done = False if stepNr == deltaLead: break # # Compute ramp down (in reverse), decceleration # if steps_per_second_deccel < steps_per_second_nominal: # # Compute timer value # steps_per_second_deccel = min(steps_per_second_1 + tDeccel * accel_steps_per_square_second, steps_per_second_nominal) dt = 1.0 / steps_per_second_deccel timerValue = int(fTimer / steps_per_second_deccel) # print "dt: ", dt*1000000, "[uS]", steps_per_second_deccel, "[steps/s], timerValue: ", timerValue, ", v: ", steps_per_second_deccel/steps_per_mm if debugPlot: if move.eOnly: deccelPlotData.append((steps_per_second_deccel/steps_per_mm, 2, dt)) else: deccelPlotData.append((steps_per_second_deccel/steps_per_mm, 1, dt)) tDeccel += dt if timerValue > maxTimerValue24: move.pprint("PlanSTeps:") print "v0: ", dt*1000000, "[uS]", steps_per_second_deccel, "[steps/s], timerValue: ", timerValue print "dt: ", dt*1000000, "[uS]", steps_per_second_deccel, "[steps/s], timerValue: ", timerValue assert(0) move.stepData.addDeccelPulse(timerValue) stepNr += 1 done = False elif not circaf(move.getStartFr(), reachedSpeedFr, 0.1): # # Acceleration only # # # Compute acceleration timer values # while steps_per_second_accel < steps_per_second_nominal and stepNr < deltaLead: # # Compute timer value # steps_per_second_accel = min(steps_per_second_0 + tAccel * accel_steps_per_square_second, steps_per_second_nominal) dt = 1.0 / steps_per_second_accel timerValue = int(fTimer / steps_per_second_accel) # print "dt: ", dt*1000000, "[uS]", steps_per_second_accel, "[steps/s], timerValue: ", timerValue if debugPlot: if move.eOnly: accelPlotData.append((steps_per_second_accel/steps_per_mm, 2, dt)) else: accelPlotData.append((steps_per_second_accel/steps_per_mm, 1, dt)) tAccel += dt if timerValue > maxTimerValue24: move.pprint("PlanSTeps:") print "v0: ", dt*1000000, "[uS]", steps_per_second_accel, "[steps/s], timerValue: ", timerValue print "dt: ", dt*1000000, "[uS]", steps_per_second_accel, "[steps/s], timerValue: ", timerValue assert(0) move.stepData.addAccelPulse(timerValue) stepNr += 1 else: # # Decceleration only # # # Compute ramp down (in reverse), decceleration # while steps_per_second_deccel < steps_per_second_nominal and stepNr < deltaLead: # # Compute timer value # steps_per_second_deccel = min(steps_per_second_1 + tDeccel * accel_steps_per_square_second, steps_per_second_nominal) dt = 1.0 / steps_per_second_deccel timerValue = int(fTimer / steps_per_second_deccel) # print "dt: ", dt*1000000, "[uS]", steps_per_second_deccel, "[steps/s], timerValue: ", timerValue, ", v: ", steps_per_second_deccel/steps_per_mm if debugPlot: if move.eOnly: deccelPlotData.append((steps_per_second_deccel/steps_per_mm, 2, dt)) else: deccelPlotData.append((steps_per_second_deccel/steps_per_mm, 1, dt)) tDeccel += dt if timerValue > maxTimerValue24: move.pprint("PlanSTeps:") print "v0: ", dt*1000000, "[uS]", steps_per_second_deccel, "[steps/s], timerValue: ", timerValue print "dt: ", dt*1000000, "[uS]", steps_per_second_deccel, "[steps/s], timerValue: ", timerValue assert(0) move.stepData.addDeccelPulse(timerValue) stepNr += 1 # # Linear phase # timerValue = fTimer / steps_per_second_nominal move.stepData.setLinTimer(timerValue) if debugPlot: self.plotfile.write("# Acceleration:\n") for (speed, color, dt) in accelPlotData: self.plotfile.write("%f %f %d\n" % (self.plottime, speed, color)) self.plottime += dt self.plotfile.write("# Linear top:\n") self.plotfile.write("%f %f 0\n" % (self.plottime, steps_per_second_nominal/steps_per_mm)) self.plottime += timerValue / fTimer self.plotfile.write("# Decceleration:\n") deccelPlotData.reverse() for (speed, color, dt) in deccelPlotData: self.plotfile.write("%f %f %d\n" % (self.plottime, speed, color)) self.plottime += dt if debugMoves: print "# of steps for move: ", deltaLead move.pprint("move:") print move.stepData.checkLen(deltaLead) if debugMoves: print "***** End planSteps() *****" return # XXXXXXXXXXXXXX old, unused ........... # # Compute acceleration timer values # # while v0 and steps_per_second < steps_per_second_nominal: # lastTimer = None while steps_per_second < steps_per_second_nominal: # and stepNr < deltaLead: assert(stepNr < deltaLead) # # Compute timer value # steps_per_second = min(steps_per_second_0 + tAccel * accel_steps_per_square_second, steps_per_second_nominal) dt = 1.0 / steps_per_second timerValue = int(fTimer / steps_per_second) # print "dt: ", dt*1000000, "[uS]", steps_per_second, "[steps/s], timerValue: ", timerValue if debugPlot: if move.eOnly: self.plotfile.write("%f %f 2\n" % (self.plottime, steps_per_second/steps_per_mm)) else: self.plotfile.write("%f %f 1\n" % (self.plottime, steps_per_second/steps_per_mm)) self.plottime += dt tAccel += dt # debnegtimer # if timerValue <= 0: # print "dt: ", dt*1000000, "[uS]", steps_per_second, "[steps/s], timerValue: ", timerValue # assert(0) # debtimeroverflow if timerValue > maxTimerValue24: move.pprint("PlanSTeps:") print "v0: ", dt*1000000, "[uS]", steps_per_second, "[steps/s], timerValue: ", timerValue print "dt: ", dt*1000000, "[uS]", steps_per_second, "[steps/s], timerValue: ", timerValue assert(0) move.stepData.addAccelPulse(timerValue) stepNr += 1 # if lastTimer: # assert((lastTimer - timerValue) < maxTimerValue16) # lastTimer = timerValue # Benutze als timer wert für die lineare phase den letzen timerwert der # beschleunigungsphase falls es diese gab. Sonst: # berechne timervalue ausgehend von linear feedrate: # if not timerValue: # timerValue = fTimer / steps_per_second # dt = 1.0 / steps_per_second # print "dt: ", dt*1000000, "[uS]", steps_per_second, "[steps/s], timerValue: ", timerValue timerValue = fTimer / steps_per_second_nominal move.stepData.setLinTimer(timerValue) if debugPlot: self.plotfile.write("# Linear top:\n") self.plotfile.write("%f %f 0\n" % (self.plottime, steps_per_second/steps_per_mm)) self.plottime += timerValue / fTimer self.plotfile.write("# Decceleration:\n") # # Compute ramp down (in reverse), decceleration # tDeccel = 1.0 / steps_per_second_nominal steps_per_second = steps_per_second_nominal steps_per_second_1 = v1 * steps_per_mm # lastTimer = None while steps_per_second > steps_per_second_1: # and stepNr < deltaLead: if stepNr >= deltaLead: print "stepNr, deltaLead:", stepNr, deltaLead assert(stepNr < deltaLead) # # Compute timer value # steps_per_second = max(steps_per_second_nominal - tDeccel * accel_steps_per_square_second, steps_per_second_1) dt = 1.0 / steps_per_second timerValue = int(fTimer / steps_per_second) # print "dt: ", dt*1000000, "[uS]", steps_per_second, "[steps/s], timerValue: ", timerValue, ", v: ", steps_per_second/steps_per_mm if debugPlot: if move.eOnly: self.plotfile.write("%f %f 2\n" % (self.plottime, steps_per_second/steps_per_mm)) else: self.plotfile.write("%f %f 1\n" % (self.plottime, steps_per_second/steps_per_mm)) self.plottime += dt tDeccel += dt # debnegtimer # assert(timerValue > 0) if timerValue > maxTimerValue24: move.pprint("PlanSTeps:") print "v0: ", dt*1000000, "[uS]", steps_per_second, "[steps/s], timerValue: ", timerValue print "dt: ", dt*1000000, "[uS]", steps_per_second, "[steps/s], timerValue: ", timerValue assert(0) move.stepData.addDeccelPulse(timerValue) stepNr += 1 # if lastTimer: # assert((timerValue - lastTimer) < maxTimerValue16) # lastTimer = timerValue if debugMoves: print "# of steps for move: ", deltaLead move.pprint("move:") print move.stepData.checkLen(deltaLead) if debugMoves: print "***** End planSteps() *****"
def __init__(self, args, gui=None): if Planner.__single: raise RuntimeError('A Planner already exists') Planner.__single = self if gui: self.gui = gui else: self.gui = dddumbui.DumbGui() self.args = args self.printer = Printer.get() # self.parser = UM2GcodeParser.get() jerk = [] for dim in dimNames: jerk.append(PrinterProfile.getValues()['axes'][dim]['jerk']) self.jerk = VVector(jerk) self.gui.log("Jerk vector: ", self.jerk) self.zeroPos = util.MyPoint() # Lowest allowed speed in mm/s for every dimension self.min_speeds = 5 * [0] for dim in range(5): # vmin = (fTimer / maxTimerValue) / steps_per_mm if PrinterProfile.getStepsPerMM(dim): self.min_speeds[dim] = float(fTimer) / (maxTimerValue24 * PrinterProfile.getStepsPerMM(dim)) self.gui.log( "min speeds: ", self.min_speeds) # # Constants, xxx todo: query from printer and/or profile # self.HOMING_FEEDRATE = [100, 100, 40] # set the homing speeds (mm/s) self.HOME_RETRACT_MM = 7 # [mm] # ENDSTOP SETTINGS: # Sets direction of endstops when homing; 1=MAX, -1=MIN self.X_HOME_DIR = -1 self.Y_HOME_DIR = 1 self.Z_HOME_DIR = 1 self.HOME_DIR = (self.X_HOME_DIR, self.Y_HOME_DIR, self.Z_HOME_DIR) # XXX defined in profile !!! # Travel limits after homing self.X_MIN_POS = 0 self.X_MAX_POS = 225.0 # 230.0 # X_MIN_POS = 0 self.Y_MAX_POS = 225.0 # 230.0 # Y_MIN_POS = 0 # self.Z_MAX_POS = 229.0 # 230.0 // Dauerdruckplatte hat 5mm im vergleich zur glassplatte 4mm self.Z_MAX_POS = 212.25 # solex nozzle # Z_MIN_POS = 0 self.MAX_POS = (self.X_MAX_POS, self.Y_MAX_POS, self.Z_MAX_POS) # Bed leveling constants self.LEVELING_OFFSET = 0.1 # Assumed thickness of feeler gauge/paper used in leveling (mm) # self.HEAD_HEIGHT = 35.0 # Let enough room for the head, XXX UM2 specific !!! self.HEAD_HEIGHT = 15.0 # Let enough room for the head, XXX UM2 specific !!! # Homing self.X_HOME_POS = self.X_MIN_POS self.Y_HOME_POS = self.Y_MAX_POS self.Z_HOME_POS = self.Z_MAX_POS # XXX + add_homeing_z # # End Constants # self.plotfile = None # Headspeed/extrusionspeed where autotemp increase starts self.ExtrusionAmountLow = 30 # [mm/s] for a 1mm nozzle if UseExtrusionAutoTemp: # self.ExtrusionAmountLow = 7.5 # [mm³/s] for a 1mm nozzle area04 = pow(0.4, 2)*math.pi/4 self.ExtrusionAmountLow = MatProfile.getBaseExtrusionRate() * (NozzleProfile.getArea() / area04) self.reset()