Ejemplo n.º 1
0
def safety_callback(channel):
    open(config.get('task', 'lock_file'), 'w').close()
    message = {'type': '', 'code': ''}
    write_emergency(json.dumps(message))
    su = SerialUtils()
    GPIO_STATUS = GPIO.input(2)
    type = "emergency"
    if (GPIO_STATUS == 0):
        su.sendGCode('M730')
        reply = su.getReply()
        #print ">>>> ", reply
        if (reply != ''):
            decodedReply = decodeReply(reply)
            if decodedReply != None:
                special_codes = [110, 120, 121]
                if (decodedReply in special_codes):
                    if decodedReply == 110:
                        type = "alert"
                        su.flush()
                        su.sendGCode('M999')
                    elif decodedReply == 120 or decodedReply == 121:
                        if (settings['bothy'] == 'Shutdown'
                                or settings['bothz'] == 'Shutdown'):
                            call([
                                'sudo php /var/www/fabui/application/modules/controller/ajax/shutdown.php'
                            ],
                                 shell=True)
                            GPIO.cleanup(
                            )  #we can disable GPIO as we are rebooting the system.

                message = {'type': type, 'code': str(decodedReply)}
                ws.send(json.dumps(message))
                write_emergency(json.dumps(message))

    su.flush()
    su.close()
    GPIO_STATUS = GPIO.HIGH
    if os.path.isfile(config.get('task', 'lock_file')):
        os.remove(config.get('task', 'lock_file'))
Ejemplo n.º 2
0
 def __init__(self,
              trace_file,
              response_file,
              settings,
              num_probes=1,
              skip_homing=False):
     print "init"
     self.serial = SerialUtils(debug=True)
     self.trace_file = trace_file
     self.response_file = response_file
     self.num_probes = num_probes
     self.skip_homing = skip_homing
     self.hardware_settings = settings
     self.probe_height = 50
     self.milling_offset = 0
     self.safety_door = False
     self.eeprom = None
     self.screw_turns = ["" for x in range(4)]
     self.screw_height = ["" for x in range(4)]
     self.screw_degrees = ["" for x in range(4)]
     if (self.num_probes > self.MAX_NUM_PROBES):
         self.num_probes = self.MAX_NUM_PROBES
Ejemplo n.º 3
0
parser.add_argument("-f", "--flush", action="store_true")
args = parser.parse_args()
hardware_reset = args.reset
flush = args.flush

#read config steps/units
settings_file = open(config.get('printer', 'settings_file'))
settings = json.load(settings_file)

#process params
if 'settings_type' in settings and settings['settings_type'] == 'custom':
    settings_file = open(config.get('printer', 'custom_settings_file'))
    settings = json.load(settings_file)
settings_file.close()

su = SerialUtils()

fw_version = su.fwVersion()
hw_version = su.hwVersion()


def saveSettings(data, file):
    ### save config file
    with open(file, 'w') as outfile:
        json.dump(data, outfile)
    outfile.close()


def customHardware(serialUtils, settings, settings_file):
    """
    Revision for customs edits
Ejemplo n.º 4
0
hardware_reset = args.reset
flush = args.flush
save_settings = args.save
debug = args.debug

commands = []

if (os.path.isfile(config.get('printer', 'settings_file')) == False):
    call(["sudo php /var/www/fabui/index.php settings recreateSettingsFiles"],
         shell=True)
#read config steps/units
settings_file = open(config.get('printer', 'settings_file'))
settings = json.load(settings_file)

su = SerialUtils(debug=debug)

fw_version = su.fwVersion()
hw_version = su.hwVersion()


def saveSettings(data, file):
    ### save config file
    with open(file, 'w') as outfile:
        json.dump(data, outfile)
    outfile.close()


def customHardware(serialUtils, settings, settings_file):
    """
    Revision for customs edits
Ejemplo n.º 5
0
def main():
    
    parser = argparse.ArgumentParser()

    parser.add_argument("-t", "--trace",    help="log travce file",        default=config.get('macro', 'trace_file'))
    parser.add_argument("-r", "--response", help="log response file",      default=config.get('macro', 'response_file'))
    parser.add_argument("-l", "--heigth",   help="height",                 default=38, type=int)
    parser.add_argument("-n", "--probes",   help="Number of probes",       default=1,  type=int)
    parser.add_argument("-s", "--skip",     help="Skip homing",            action="store_true")
    parser.add_argument("-d", "--debug",    help="Debug: print console",   action="store_true")
    args = parser.parse_args()
    #write LOCK FILE    
    open(config.get('task', 'lock_file'), 'w').close()
    
    """ ### init  ### """
    log_trace     = args.trace
    logfile       = args.response
    response_file = args.response
    num_probes    = args.probes
    skip_homing   = args.skip
    debug         = args.debug
    
    cycle=True
    s_warning=s_error=s_skipped=0
    probe_height=50.0
    milling_offset=0.0
    probe_offset_security=15
    
    screw_turns=["" for x in range(4)]
    screw_height=["" for x in range(4)]
    screw_degrees=["" for x in range(4)]
    
    #points to probe
    probed_points=np.array([[5+17,5+61.5,0],[5+17,148.5+61.5,0],[178+17,148.5+61.5,0],[178+17,5+61.5,0]])
    #first screw offset (lower left corner)
    screw_offset=[8.726,10.579,0]
    
    ''' #### START #### '''
    su = SerialUtils(debug = debug)
    su.trace('Manual Bed Calibration Wizard Initiated')
    eeprom = su.eeprom();
    probe_height = (abs(float(eeprom['probe_length'])) + 1 ) + probe_offset_security
    
    settings_file = open(config.get('printer', 'settings_file'))
    settings = json.load(settings_file)
    
    if 'settings_type' in settings and settings['settings_type'] == 'custom':
        settings_file = open(config.get('printer', 'custom_settings_file'))
        settings = json.load(settings_file)
    settings_file.close()
    
    try:
        safety_door = int (settings['safety']['door']) == 1
        milling_offset = float(settings['milling']['layer-offset'])
    except KeyError:
        safety_door = False
        milling_offset = 0
    
    
    if(safety_door):
        su.doMacro('M741', 'TRIGGERED', -1, 'Front panel door control', verbose=False)
    
    su.doMacro('M744', 'TRIGGERED', -1, 'Milling bed side up', warning=True, verbose=False)
    #su.trace("Milling sacrificial layer thickness: "+str(milling_offset))
    su.doMacro('M402', 'ok', 1, 'Retracting Probe (safety)', verbose=False)
    su.doMacro('G90', 'ok', -1, 'Setting absolute mode', verbose=False)
    
    if(skip_homing == False):
        su.doMacro('G27', 'ok', -1, 'Homing Z - Fast', verbose=False)
        su.doMacro('G92 Z241.2', 'ok', -1, 'Setting correct Z', verbose=False)
        su.doMacro('M402', 'ok', 1, 'Retracting Probe (safety)', verbose=False)
    
    su.doMacro("G0 Z"+str(probe_height)+" F15000", 'ok', -1, 'Moving to start Z height', verbose=False)#mandatory!
    
    for (p,point) in enumerate(probed_points):
    
        #real carriage position
        x=point[0]-17
        y=point[1]-61.5
        
        su.doMacro("G0 X"+str(x)+" Y"+str(y)+" Z"+str(probe_height)+" F15000", 'ok', -1, 'Moving to Pos', verbose=False)
        msg="Measuring point " +str(p+1)+ " of "+ str(len(probed_points)) + " (" +str(num_probes) + " times)"
        su.trace(msg)
        #Touches 4 times the bed in the same position
        probes=num_probes #temp
        for i in range(0,num_probes):
            su.sendGCode('M401')
            z = su.g30()
            probed_points[p,2]+=float(z) # store Z
            #G0 Z40 F5000
            #macro("G0 Z40 F5000","ok",10,"Rising Bed",0.1, warning=True, verbose=False)
            su.doMacro("G0 Z"+str(probe_height)+" F15000", 'ok', -1, 'Rising Bed', verbose=False)
            
        #mean of the num of measurements
        probed_points[p,0]=probed_points[p,0]
        probed_points[p,1]=probed_points[p,1]
        probed_points[p,2]=probed_points[p,2]/probes; #mean of the Z value on point "p"
        
        #trace("Mean ="+ str(probed_points[p,2]))
        
        #msg="Point " +str(p+1)+ "/"+ str(len(probed_points)) + " , Z= " +str(probed_points[p,2])
        #trace(msg)
        su.sendGCode('M402')
        #su.doMacro("M402", 'ok', -1, 'Raising Probe', verbose=False)
        #macro("M402","ok",2,"Raising Probe",0.1, warning=True, verbose=False)    
        
        #G0 Z40 F5000
        #macro("G0 Z40 F5000","ok",2,"Rising Bed",0.1, warning=True, verbose=False)
        su.doMacro("G0 Z"+str(probe_height)+" F15000", 'ok', -1, 'Rising Bed', verbose=False)
        #macro("G0 Z"+str(probe_height)+" F5000","ok",2,"Rising Bed",0.5, warning=True, verbose=False)
        
    su.doMacro("G0 X5 Y5 Z"+str(probe_height)+" F15000", 'ok', -1, 'Idle Position', verbose=False)
    su.doMacro("M18", 'ok', -1, 'Motors off', verbose=False)
    su.trace("Completed")
    
    probed_points=np.add(probed_points,screw_offset)
    
    Fit = str(fitplane(probed_points))
    
    Fit = fitplane(probed_points)
    coeff = Fit[0:3]
    d = Fit[3]
    
    eeprom = su.eeprom();
    z_probe = float(eeprom['probe_length'])
    
    d_ovr=d
    
    cal_point=np.array([[0-8.726,0-10.579,0],[0-8.726,257.5-10.579,0],[223-8.726,257.5-10.579,0],[223-8.726,0-10.579,0]])
    
    idx=0
    for (p,point) in enumerate(cal_point):
        #cal_point[p][0][1]  => point[1]  #Y coordinate of point 0
    
        z=(-coeff[0]*point[0] - coeff[1]*point[1] +d)/coeff[2]
            
        #difference from titled plane to straight plane
        #distance=P2-P1
        diff=abs(-d_ovr)-abs(z)
        
        #msg= "d :"+str(d)+", P :"+str(p)+" , Z:" +str(z) +" Diff: "+str(diff) +" d_ovr: "+str(d_ovr) 
        #msg= str(d_ovr)+ "-"+str(abs(z))+" = " + str(diff)
        #trace(msg)
        
        #number of screw turns, pitch 0.5mm
        turns=round(diff/0.5, 2) #
        degrees= turns*360
        degrees=int(5 * round(float(degrees)/5))  #lets round to upper 5
        
        screw_turns[idx]=turns
        screw_height[idx]=diff
        screw_degrees[idx]=degrees
        
        idx+=1
        print "Calculated=" + str(z) + " Difference " + str(diff) +" Turns: "+ str(turns) + " deg: " + str(degrees)
    
    #save everything
    bed_calibration = {
     "t1": screw_turns[0],
     "t2": screw_turns[1],
     "t3": screw_turns[2],
     "t4": screw_turns[3],
     "s1": screw_height[0],
     "s2": screw_height[1],
     "s3": screw_height[2],
     "s4": screw_height[3],
     "d1": screw_degrees[0],
     "d2": screw_degrees[1],
     "d3": screw_degrees[2],
     "d4": screw_degrees[3]
    }
    
    result = {
     "bed_calibration" : bed_calibration
    }
    
    with open(logfile, 'w') as outfile:
        json.dump(result, outfile)
    outfile.close()
    
    if os.path.isfile(config.get('task', 'lock_file')):
        os.remove(config.get('task', 'lock_file'))
Ejemplo n.º 6
0
 def __init__(self):
     self.serial = SerialUtils(debug=False)
     self.reply = None
     self.command = None
     self.response = {}