+ self._wizardState = 12
+ elif self.comm.isError():
+ wx.CallAfter(self.infoBox.SetError, 'Failed to establish connection with the printer.', 'http://wiki.ultimaker.com/Cura:_Connection_problems')
+
+ def mcMessage(self, message):
+ pass
+
+ def mcProgress(self, lineNr):
+ pass
+
+ def mcZChange(self, newZ):
+ pass
+
+class headOffsetCalibrationPage(InfoPage):
+ def __init__(self, parent):
+ super(headOffsetCalibrationPage, self).__init__(parent, "Printer head offset calibration")
+
+ self.AddText('This wizard will help you in calibrating the printer head offsets of your dual extrusion machine')
+ self.AddSeperator()
+
+ self.connectButton = self.AddButton('Connect to printer')
+ self.comm = None
+
+ self.infoBox = self.AddInfoBox()
+ self.textEntry = self.AddTextCtrl('')
+ self.textEntry.Enable(False)
+ self.resumeButton = self.AddButton('Resume')
+ self.resumeButton.Enable(False)
+
+ self.Bind(wx.EVT_BUTTON, self.OnConnect, self.connectButton)
+ self.Bind(wx.EVT_BUTTON, self.OnResume, self.resumeButton)
+
+ def OnConnect(self, e = None):
+ if self.comm is not None:
+ self.comm.close()
+ del self.comm
+ self.comm = None
+ wx.CallAfter(self.OnConnect)
+ return
+ self.connectButton.Enable(False)
+ self.comm = machineCom.MachineCom(callbackObject=self)
+ self.infoBox.SetBusy('Connecting to machine.')
+ self._wizardState = 0
+
+ def OnResume(self, e):
+ if self._wizardState == 2:
+ self._wizardState = 3
+ wx.CallAfter(self.infoBox.SetBusy, 'Printing initial calibration cross')
+
+ w = profile.getMachineSettingFloat('machine_width')
+ d = profile.getMachineSettingFloat('machine_depth')
+
+ gcode = gcodeGenerator.gcodeGenerator()
+ gcode.setExtrusionRate(profile.getProfileSettingFloat('nozzle_size') * 1.5, 0.2)
+ gcode.setPrintSpeed(profile.getProfileSettingFloat('bottom_layer_speed'))
+ gcode.addCmd('T0')
+ gcode.addPrime(15)
+ gcode.addCmd('T1')
+ gcode.addPrime(15)
+
+ gcode.addCmd('T0')
+ gcode.addMove(w/2, 5)
+ gcode.addMove(z=0.2)
+ gcode.addPrime()
+ gcode.addExtrude(w/2, d-5.0)
+ gcode.addRetract()
+ gcode.addMove(5, d/2)
+ gcode.addPrime()
+ gcode.addExtrude(w-5.0, d/2)
+ gcode.addRetract(15)
+
+ gcode.addCmd('T1')
+ gcode.addMove(w/2, 5)
+ gcode.addPrime()
+ gcode.addExtrude(w/2, d-5.0)
+ gcode.addRetract()
+ gcode.addMove(5, d/2)
+ gcode.addPrime()
+ gcode.addExtrude(w-5.0, d/2)
+ gcode.addRetract(15)
+ gcode.addCmd('T0')
+
+ gcode.addMove(z=25)
+ gcode.addMove(0, 0)
+ gcode.addCmd('M400')
+
+ self.comm.printGCode(gcode.list())
+ self.resumeButton.Enable(False)
+ elif self._wizardState == 4:
+ try:
+ float(self.textEntry.GetValue())
+ except ValueError:
+ return
+ profile.putPreference('extruder_offset_x1', self.textEntry.GetValue())
+ self._wizardState = 5
+ self.infoBox.SetAttention('Please measure the distance between the horizontal lines in millimeters.')
+ self.textEntry.SetValue('0.0')
+ self.textEntry.Enable(True)
+ elif self._wizardState == 5:
+ try:
+ float(self.textEntry.GetValue())
+ except ValueError:
+ return
+ profile.putPreference('extruder_offset_y1', self.textEntry.GetValue())
+ self._wizardState = 6
+ self.infoBox.SetBusy('Printing the fine calibration lines.')
+ self.textEntry.SetValue('')
+ self.textEntry.Enable(False)
+ self.resumeButton.Enable(False)
+
+ x = profile.getMachineSettingFloat('extruder_offset_x1')
+ y = profile.getMachineSettingFloat('extruder_offset_y1')
+ gcode = gcodeGenerator.gcodeGenerator()
+ gcode.setExtrusionRate(profile.getProfileSettingFloat('nozzle_size') * 1.5, 0.2)
+ gcode.setPrintSpeed(25)
+ gcode.addHome()
+ gcode.addCmd('T0')
+ gcode.addMove(50, 40, 0.2)
+ gcode.addPrime(15)
+ for n in xrange(0, 10):
+ gcode.addExtrude(50 + n * 10, 150)
+ gcode.addExtrude(50 + n * 10 + 5, 150)
+ gcode.addExtrude(50 + n * 10 + 5, 40)
+ gcode.addExtrude(50 + n * 10 + 10, 40)
+ gcode.addMove(40, 50)
+ for n in xrange(0, 10):
+ gcode.addExtrude(150, 50 + n * 10)
+ gcode.addExtrude(150, 50 + n * 10 + 5)
+ gcode.addExtrude(40, 50 + n * 10 + 5)
+ gcode.addExtrude(40, 50 + n * 10 + 10)
+ gcode.addRetract(15)
+
+ gcode.addCmd('T1')
+ gcode.addMove(50 - x, 30 - y, 0.2)
+ gcode.addPrime(15)
+ for n in xrange(0, 10):
+ gcode.addExtrude(50 + n * 10.2 - 1.0 - x, 140 - y)
+ gcode.addExtrude(50 + n * 10.2 - 1.0 + 5.1 - x, 140 - y)
+ gcode.addExtrude(50 + n * 10.2 - 1.0 + 5.1 - x, 30 - y)
+ gcode.addExtrude(50 + n * 10.2 - 1.0 + 10 - x, 30 - y)
+ gcode.addMove(30 - x, 50 - y, 0.2)
+ for n in xrange(0, 10):
+ gcode.addExtrude(160 - x, 50 + n * 10.2 - 1.0 - y)
+ gcode.addExtrude(160 - x, 50 + n * 10.2 - 1.0 + 5.1 - y)
+ gcode.addExtrude(30 - x, 50 + n * 10.2 - 1.0 + 5.1 - y)
+ gcode.addExtrude(30 - x, 50 + n * 10.2 - 1.0 + 10 - y)
+ gcode.addRetract(15)
+ gcode.addMove(z=15)
+ gcode.addCmd('M400')
+ gcode.addCmd('M104 T0 S0')
+ gcode.addCmd('M104 T1 S0')
+ self.comm.printGCode(gcode.list())
+ elif self._wizardState == 7:
+ try:
+ n = int(self.textEntry.GetValue()) - 1
+ except:
+ return
+ x = profile.getMachineSettingFloat('extruder_offset_x1')
+ x += -1.0 + n * 0.1
+ profile.putPreference('extruder_offset_x1', '%0.2f' % (x))
+ self.infoBox.SetAttention('Which horizontal line number lays perfect on top of each other? Front most line is zero.')
+ self.textEntry.SetValue('10')
+ self._wizardState = 8
+ elif self._wizardState == 8:
+ try:
+ n = int(self.textEntry.GetValue()) - 1
+ except:
+ return
+ y = profile.getMachineSettingFloat('extruder_offset_y1')
+ y += -1.0 + n * 0.1
+ profile.putPreference('extruder_offset_y1', '%0.2f' % (y))
+ self.infoBox.SetInfo('Calibration finished. Offsets are: %s %s' % (profile.getMachineSettingFloat('extruder_offset_x1'), profile.getMachineSettingFloat('extruder_offset_y1')))
+ self.infoBox.SetReadyIndicator()
+ self._wizardState = 8
+ self.comm.close()
+ self.resumeButton.Enable(False)
+
+ def mcLog(self, message):
+ print 'Log:', message
+
+ def mcTempUpdate(self, temp, bedTemp, targetTemp, bedTargetTemp):
+ if self._wizardState == 1:
+ if temp[0] >= 210 and temp[1] >= 210:
+ self._wizardState = 2
+ wx.CallAfter(self.infoBox.SetAttention, 'Please load both extruders with PLA.')
+ wx.CallAfter(self.resumeButton.Enable, True)
+ wx.CallAfter(self.resumeButton.SetFocus)
+
+ def mcStateChange(self, state):
+ if self.comm is None:
+ return
+ if self.comm.isOperational():
+ if self._wizardState == 0:
+ wx.CallAfter(self.infoBox.SetInfo, 'Homing printer and heating up both extruders.')
+ self.comm.sendCommand('M105')
+ self.comm.sendCommand('M104 S220 T0')
+ self.comm.sendCommand('M104 S220 T1')
+ self.comm.sendCommand('G28')
+ self.comm.sendCommand('G1 Z15 F%d' % (profile.getProfileSettingFloat('print_speed') * 60))
+ self._wizardState = 1
+ if not self.comm.isPrinting():
+ if self._wizardState == 3:
+ self._wizardState = 4
+ wx.CallAfter(self.infoBox.SetAttention, 'Please measure the distance between the vertical lines in millimeters.')
+ wx.CallAfter(self.textEntry.SetValue, '0.0')
+ wx.CallAfter(self.textEntry.Enable, True)
+ wx.CallAfter(self.resumeButton.Enable, True)
+ wx.CallAfter(self.resumeButton.SetFocus)
+ elif self._wizardState == 6:
+ self._wizardState = 7
+ wx.CallAfter(self.infoBox.SetAttention, 'Which vertical line number lays perfect on top of each other? Leftmost line is zero.')
+ wx.CallAfter(self.textEntry.SetValue, '10')
+ wx.CallAfter(self.textEntry.Enable, True)
+ wx.CallAfter(self.resumeButton.Enable, True)
+ wx.CallAfter(self.resumeButton.SetFocus)
+