# Copyright 2015-2020 - RoboDK Inc. - https://robodk.com/ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # http://www.apache.org/licenses/LICENSE-2.0 # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ---------------------------------------------------- # This file is a POST PROCESSOR for Robot Offline Programming to generate programs # for a generic Fanuc robot with RoboDK # # To edit/test this POST PROCESSOR script file: # Select "Program"->"Add/Edit Post Processor", then select your post or create a new one. # You can edit this file using any text editor or Python editor. Using a Python editor allows to quickly evaluate a sample program at the end of this file. # Python should be automatically installed with RoboDK # # You can also edit the POST PROCESSOR manually: # 1- Open the *.py file with Python IDLE (right click -> Edit with IDLE) # 2- Make the necessary changes # 3- Run the file to open Python Shell: Run -> Run module (F5 by default) # 4- The "test_post()" function is called automatically # Alternatively, you can edit this file using a text editor and run it with Python # # To use a POST PROCESSOR file you must place the *.py file in "C:/RoboDK/Posts/" # To select one POST PROCESSOR for your robot in RoboDK you must follow these steps: # 1- Open the robot panel (double click a robot) # 2- Select "Parameters" # 3- Select "Unlock advanced options" # 4- Select your post as the file name in the "Robot brand" box # # To delete an existing POST PROCESSOR script, simply delete this file (.py file) # # ---------------------------------------------------- # More information about RoboDK Post Processors and Offline Programming here: # https://robodk.com/help#PostProcessor # https://robodk.com/doc/en/PythonAPI/postprocessor.html # ---------------------------------------------------- DRIPFEED_FILE = """# Drip Feed python script generated by RoboDK for Fanuc robot controllers # To use: simply run the script and follow on screen instructions # You can double click this file to run the script # Make sure to install RoboDK on the computer you want to use to dripfeed your program # (a RoboDK license is not required to run this script) import os import sys import time import socket import ftplib from ftplib import FTP RobotFTPIP = "%s" RobotFTPPath = "%s" RobotFTPUsername = "%s" RobotFTPPassword = "%s" fMainFile = "%s" flFilesToSend = %s # Define timeout to reconnect or send in Seconds TIMEOUT = 1 # Fix robot path # RobotFTPPath = r'''\''' + RobotFTPPath def SafeFTPDelete(filename, show_warning=False): filesave_TP = filename[:-3] + '.tp' try: ftpRobot.delete(filesave_TP.lower()) except: if show_warning and filesave_TP == filename: print("Warning! Unable to delete file: " + filesave_TP.lower()) filesave_LS = filename[:-3] + '.ls' try: ftpRobot.delete(filesave_LS.lower()) except: if show_warning and filesave_LS == filename: print("Warning! Unable to delete file: " + filesave_LS.lower()) return 0 def SendFTPFile(filename): # first, try TP file: filesave_TP = filename[:-3] + '.TP' if filename.endswith(".LS") and os.path.isfile(filesave_TP): filename = filesave_TP while True: writeCmdFTP = "" writeCmdFTP = "STOR " + filename try: print("Sending file: " + filename) ftpRobot.storbinary(writeCmdFTP, open(filename, 'rb')) return 0 except: print(" Error Sending File: " + filename + ". Is the robot running this program?") time.sleep(TIMEOUT) return 0 def GetFilesFromFTP(): ftpRobot.cwd("md:") ftpRobot.retrbinary('RETR curpos.dg', open('curpos.dg', 'wb+').write) ftpRobot.retrbinary('RETR prgstate.dg', open('prgstate.dg', 'wb+').write) ftpRobot.cwd(RobotFTPPath) return def GetCurrentTask(): curSubName = GetCurRunningTasks() if (curSubName == []): return -1 curSubName = curSubName[0] counter = 0 for compSubName in flFilesToSend: compSubName = compSubName[:-3] #Truncate file extension if (curSubName.upper() == compSubName.upper()): return counter counter = counter + 1 return -1 def GetCurJoints(): FILE_CURPOS = 'curpos.dg' joints = [0]*20 nDOFs = 0 with open(FILE_CURPOS,'r') as fid: lines = fid.readlines() for line in lines: line = line.strip() if line.startswith("Joint ") and ':' in line: lineinfo = line.replace(':',' ').split(' ') lineinfo = [x for x in lineinfo if x] if len(lineinfo) >= 3: jid = int(lineinfo[1]) jval = float(lineinfo[2]) joints[nDOFs] = jval nDOFs += 1 else: print("Something is wrong: " + str(lineinfo)) joints = joints[:nDOFs] return joints def GetCurRunningTasks(): proglist = [] FILE_PRGSTAT = 'prgstate.dg' with open(FILE_PRGSTAT,'r') as fid: lines = fid.readlines() for line in lines: line = line.strip() FindMainProgRunning = fMainFile FindMainProgRunning = FindMainProgRunning[:-3] + " " FindMainProgRunning = FindMainProgRunning + 'RUNNING @ ' FindMainProgRunning = FindMainProgRunning.upper() FindMainProgPaused = fMainFile FindMainProgPaused = FindMainProgRunning[:-3] + " " FindMainProgPaused = FindMainProgRunning + 'PAUSED @ ' FindMainProgPaused = FindMainProgRunning.upper() if FindMainProgRunning in line: lineinfo = line.split(' ') lineinfo = [x for x in lineinfo if x] proglist.append(lineinfo[6]) elif FindMainProgPaused in line: lineinfo = line.split(' ') lineinfo = [x for x in lineinfo if x] proglist.append(lineinfo[6]) return proglist if __name__ == "__main__": try: print("Drip feeder script to load programs to Fanuc robot controllers (LS or TP files).") print("This program allows you to run large robot programs to Fanuc robot controllers.") print("This script was automatically created by RoboDK.") print("Important: Do not modify this file. Change the RoboDK project instead and generate the program.") print("For more information visit:") print(" https://robodk.com/doc/en/Robots-Fanuc.html") print("") # Change current directory to this directory (in case we run this file from another directory) folder_files = os.path.dirname(__file__) print("Program files directory: " + folder_files) os.chdir(folder_files) print("Main program to run: " + fMainFile) numFilesToSend = len(flFilesToSend) print(" Number of subprograms: " + str(numFilesToSend)) if numFilesToSend <= 3: #raise Exception("Program is less than 3 files, no drip feed nessesary") print("") print(" (the program is split in less than 3 files: Drip feeding is not nessesary)") print(" (sending programs anyway...)") #input("Press any key to close") #quit() #input("Press enter to load the files") numFilesToSend = len(flFilesToSend) nCurrentTaskRunning = 0 if (RobotFTPIP == ""): input("Robot FTP IP not defined, edit the top of the script to fix") sys.exit() if (RobotFTPUsername == ""): RobotFTPUsername = "anonymous" #input("Robot FTP username not defined, edit the top of the script to fix") #sys.exit() ftpRobot = None while True: print("") print("Trying to connect to Fanuc robot controller: " + RobotFTPIP + " ...") try: ftpRobot = FTP(RobotFTPIP) #Connect ftpRobot.login() break except Exception as e: print(" " + str(e)) print(" Unable to connect. Make sure the FTP server is running and no other clients are connected.") time.sleep(TIMEOUT) print("") print("Connected!") GetFilesFromFTP() print("") print("Current robot position:") print(GetCurJoints()) print("") print("Current running tasks:") print(GetCurRunningTasks()) print("") print("Files to send:") print(flFilesToSend) SafeFTPDelete(fMainFile) for subFileName in flFilesToSend: SafeFTPDelete(subFileName) SendFTPFile(fMainFile) for i in range(min(3, numFilesToSend)): SendFTPFile(flFilesToSend[i]) ftpRobot.quit() displayMessage = "Waiting for: " + fMainFile + " to be run." print(displayMessage) print("") print(" If you are resuming a partially completed program,") print(" make sure the robot has the current subroutine it's on") print(" and the next two subroutines after that. Disconect") print(" your ftp client and then resume the robot program.") print("") nCurrentTaskRunning = -1 while (nCurrentTaskRunning == -1): try: ftpRobot = FTP(RobotFTPIP) #Connect ftpRobot.login() ftpRobot.cwd(RobotFTPPath) GetFilesFromFTP() ftpRobot.quit() #Disconect and reconect to allow the user to manually ftp a file over nCurrentTaskRunning = GetCurrentTask() except: time.sleep(TIMEOUT) time.sleep(TIMEOUT) print("Starting drip feed sequence") #Reconect for drip feeding ftpRobot = FTP(RobotFTPIP) #Connect ftpRobot.login() ftpRobot.cwd(RobotFTPPath) fExit = False previousTaskRunning = nCurrentTaskRunning while (fExit != True): GetFilesFromFTP() # update the local files tempNum = GetCurrentTask() if (tempNum != -1): nCurrentTaskRunning = tempNum if ( (nCurrentTaskRunning > previousTaskRunning) ): previousTaskRunning = nCurrentTaskRunning #Increment a position #Delete the previous file for space if (nCurrentTaskRunning > 0): SafeFTPDelete(flFilesToSend[nCurrentTaskRunning-1], True) #Send the next one if ( (nCurrentTaskRunning+3-1) < numFilesToSend): SendFTPFile(flFilesToSend[nCurrentTaskRunning+3-1]) if (previousTaskRunning == (numFilesToSend-1) ): fExit = True time.sleep(TIMEOUT) print("Cleaning up") SafeFTPDelete(fMainFile, True) SafeFTPDelete(flFilesToSend[numFilesToSend-1], True) print("Job Completed Successfully") except Exception as e: print("Unexpected Error: " + str(e)) print("") input("Done. Press any key to close") """ def get_safe_name(progname, max_chars = 10): """Get a safe program name""" # Remove special characters for c in r'-[]/\;,><&*:%=+@!#^()|?^': progname = progname.replace(c,'') # Set a program name by default: if len(progname) <= 0: progname = 'Program' # Force the program to start with a letter (not a number) if progname[0].isdigit(): progname = 'P' + progname # Set the maximum size of a program (number of characters) if len(progname) > max_chars: progname = progname[:max_chars] return progname # ---------------------------------------------------- # Import RoboDK tools from robodk import * import sys import os # ---------------------------------------------------- # Object class that handles the robot instructions/syntax class RobotPost(object): """Robot post object defined for Fanuc robots""" # maximum number of lines per program. It will then generate multiple "pages" (files). # This setting can be overriden by RoboDK settings (Tools-Options-Program) MAX_LINES_X_PROG = 9999 # Generate sub programs INCLUDE_SUB_PROGRAMS = True # set default joint speed (percentage of the total speed) JOINT_SPEED = '20%' # set default cartesian speed motion SPEED = '200mm/sec' # set default CNT value (all motion until smooth value is changed) # CNT_VALUE = 'CNT5' # 5% smoothing (set CNT1-CNT100) CNT_VALUE = 'FINE' # Active UFrame Id (register) ACTIVE_UF = 9 # Active UTool Id (register) ACTIVE_UT = 9 # Spare Position register for calculations (such as setting UFRAME and UTOOL) SPARE_PR = 9 # Set the turntable grup (usually GP2 or GP3) TURNTABLE_GROUP = 'GP2' #TURNTABLE_GROUP = 'GP3' # Set to True to generate programs compatible with RJ3 controllers (small difference in the program header) FANUC_RJ3_COMPATIBLE = True # Compile LS program to TP programs # More help here: https://robodk.com/doc/en/Robots-Fanuc.html#LSvsTP # Set the path to Roboguide WinOLPC tools, alternatively, set to None to prevent generating TP files # This step is ignored if the path does not exist PATH_MAKE_TP = 'C:/Program Files (x86)/FANUC/WinOLPC/bin/' #PATH_MAKE_TP = None # Ignore program compilation # Generate a drip feeder program: this will split long programs in subprograms and load them to the controller as they are executed # Set a file name to use an automatic dripfeeder: Files will be sent over FTP as they are executed # Right click a program and select "Send Program to Robot" to trigger the dripfeeding automatically #DRIPFEED_FILE_NAME = "Fanuc_SendProgram_DripFeed.py" DRIPFEED_FILE_NAME = None # Don't do any dripfeeding # Force user input to save the folder FORCE_POPUP_SAVE = False #--------------------------------------------------------------------------------------------- # Program-specific variables: LINE_COUNT = 0 # Count the number of instructions (limited by MAX_LINES_X_PROG) P_COUNT = 0 # Count the number of P targets in one file nProgs = 0 # Count the number of programs and sub programs LBL_ID_COUNT = 0 # Number of labels used # other variables PROG_EXT = 'LS' # set the program extension ROBOT_POST = '' ROBOT_NAME = '' PROG_FILES = [] # List of Program files to be uploaded through FTP PROG_NAMES = [] # List of PROG NAMES PROG_LIST = [] # List of PROG PROG_NAME = 'unknown' # Original name of the current program (example: ProgA) PROG_NAME_CURRENT = 'unknown' # Auto generated name (different from PROG_NAME if we have more than 1 page per program. Example: ProgA2) nPages = 0 # Count the number of pages PROG_NAMES_MAIN = [] # List of programs called by a main program due to splitting PROG = [] # Save the program lines PROG_TARGETS = [] # Save the program lines (targets section) LOG = '' # Save a log nAxes = 6 # Important: This is usually provided by RoboDK automatically. Otherwise, override the __init__ procedure. AXES_TYPE = ['R','R','R','R','R','R'] # Important: This is usually set up by RoboDK automatically. Otherwise, override the __init__ procedure. # 'R' for rotative axis, 'L' for linear axis, 'T' for external linear axis (linear track), 'J' for external rotative axis (turntable) #AXES_TYPE = ['R','R','R','R','R','R','T','J','J'] #example of a robot with one external linear track axis and a turntable with 2 rotary axes AXES_TRACK = [] AXES_TURNTABLE = [] HAS_TRACK = False HAS_TURNTABLE = False HAS_EXTAXES = False EXTAXES_FLAGS = ['1','*','*','*','*'] # Specific to ARC welding applications SPEED_BACKUP = None LAST_POSE = None ROBOT_IP = 'unknown-ip' # robot IP is provided automatically by RoboDK def __init__(self, robotpost=None, robotname=None, robot_axes = 6, **kwargs): self.ROBOT_POST = robotpost self.ROBOT_NAME = robotname self.nAxes = robot_axes self.PROG = [] self.LOG = '' #for k,v in kwargs.iteritems(): # python2 for k,v in kwargs.items(): if k == 'lines_x_prog': self.MAX_LINES_X_PROG = v if k == 'axes_type': self.AXES_TYPE = v elif k == 'ip_com': self.ROBOT_IP = v for i in range(len(self.AXES_TYPE)): if self.AXES_TYPE[i] == 'T': self.AXES_TRACK.append(i) self.HAS_TRACK = True self.HAS_EXTAXES = True elif self.AXES_TYPE[i] == 'J': self.AXES_TURNTABLE.append(i) self.HAS_TURNTABLE = True self.HAS_EXTAXES = True def ProgStart(self, progname, new_page = False): progname = get_safe_name(progname) progname_i = progname if new_page: #nPages = len(self.PROG_LIST) if self.nPages == 0: if len(self.PROG_NAMES_MAIN) > 0: print("Can't split %s: Two or more programs are split into smaller programs" % progname) print(self.PROG_NAMES_MAIN) raise Exception("Only one program at a time can be split into smaller programs") self.PROG_NAMES_MAIN.append(self.PROG_NAME) # add the first program in the list to be genrated as a subprogram call self.nPages = self.nPages + 1 self.nPages = self.nPages + 1 progname_i = "%s%i" % (self.PROG_NAME, self.nPages) self.PROG_NAMES_MAIN.append(progname_i) else: if self.nProgs > 1 and not self.INCLUDE_SUB_PROGRAMS: return self.PROG_NAME = progname self.nProgs = self.nProgs + 1 #self.PROG_NAMES = [] self.PROG_NAME_CURRENT = progname_i self.PROG_NAMES.append(progname_i) def ProgFinish(self, progname, new_page = False): progname = get_safe_name(progname) if not new_page: # Reset page count self.nPages = 0 #if self.nPROGS > 1: # # Fanuc does not support defining multiple programs in the same file, so one program per file # return header = '' header = header + ('/PROG %s' % self.PROG_NAME_CURRENT) + '\n' # Use the latest name set at ProgStart header = header + '/ATTR' + '\n' header = header + 'OWNER\t\t= MNEDITOR;' + '\n' header = header + 'COMMENT\t\t= "RoboDK sequence";' + '\n' header = header + 'PROG_SIZE\t= 0;' + '\n' header = header + 'CREATE\t\t= DATE 31-12-14 TIME 12:00:00;' + '\n' header = header + 'MODIFIED\t= DATE 31-12-14 TIME 12:00:00;' + '\n' header = header + ('FILE_NAME\t= %s;' % self.PROG_NAME_CURRENT) + '\n' header = header + 'VERSION\t\t= 0;' + '\n' header = header + ('LINE_COUNT\t= %i;' % (self.LINE_COUNT)) + '\n' header = header + 'MEMORY_SIZE\t= 0;' + '\n' header = header + 'PROTECT\t\t= READ_WRITE;' + '\n' header = header + 'TCD: STACK_SIZE\t= 0,' + '\n' header = header + ' TASK_PRIORITY\t= 50,' + '\n' header = header + ' TIME_SLICE\t= 0,' + '\n' header = header + ' BUSY_LAMP_OFF\t= 0,' + '\n' header = header + ' ABORT_REQUEST\t= 0,' + '\n' header = header + ' PAUSE_REQUEST\t= 0;' + '\n' if self.HAS_EXTAXES: header = header + 'DEFAULT_GROUP\t= ' + ','.join(self.EXTAXES_FLAGS) if not self.FANUC_RJ3_COMPATIBLE: header = header + ',*,*' header = header + ';\n' else: if self.FANUC_RJ3_COMPATIBLE: header = header + 'DEFAULT_GROUP\t= 1,*,*,*,*;' + '\n' # required for older controllers such as RJ3 else: header = header + 'DEFAULT_GROUP\t= 1,*,*,*,*,*,*;' + '\n' header = header + 'CONTROL_CODE\t= 00000000 00000000;' + '\n' if self.HAS_TURNTABLE: header = header + '/APPL' + '\n' header = header + '' + '\n' header = header + 'LINE_TRACK;' + '\n' header = header + 'LINE_TRACK_SCHEDULE_NUMBER : 0;' + '\n' header = header + 'LINE_TRACK_BOUNDARY_NUMBER : 0;' + '\n' header = header + 'CONTINUE_TRACK_AT_PROG_END : FALSE;' + '\n' header = header + '' + '\n' header = header + '/MN' #header = header + '/MN' + '\n' # Important! Last line should not have \n self.PROG.insert(0, header) self.PROG.append('/POS') self.PROG += self.PROG_TARGETS self.PROG.append('/END') # Save PROG in PROG_LIST self.PROG_LIST.append(self.PROG) self.PROG = [] self.PROG_TARGETS = [] #self.nLines = 0 self.LINE_COUNT = 0 self.P_COUNT = 0 self.LBL_ID_COUNT = 0 def progsave(self, folder, progname, ask_user = False, show_result = False): #print(folder) #if not folder.endswith('/'): # folder = folder + '/' if ask_user or not DirExists(folder): folder = getSaveFolder(folder,'Select a directory to save your program') if folder is None: # The user selected the Cancel button return filesave = folder + '/' + progname + '.' + self.PROG_EXT #filesave = folder + progname #if ask_user or not DirExists(folder): # filesave = getSaveFile(folder, progname, 'Save program as...') # if filesave is not None: # filesave = filesave.name # else: # return #else: # filesave = folder + progname fid = open(filesave, "w") #fid.write(self.PROG) for line in self.PROG: fid.write(line) fid.write('\n') fid.close() print('SAVED: %s\n' % filesave) # tell RoboDK the path of the saved file self.PROG_FILES.append(filesave) # Delete TP file filesave_TP = filesave[:-3] + '.TP' if os.path.isfile(filesave_TP): os.remove(filesave_TP) # open file with default application if show_result: if type(show_result) is str: # Open file with provided application import subprocess p = subprocess.Popen([show_result, filesave]) elif type(show_result) is list: import subprocess p = subprocess.Popen(show_result + [filesave]) else: # open file with default application os.startfile(filesave) #if len(self.LOG) > 0: # mbox('Program generation LOG:\n\n' + self.LOG) # -------- attempt to build from LS to TP with MakeTP --------- # set robot first with setrobot.exe (delete robot.ini file) sFileExtention = '.LS' if self.PATH_MAKE_TP is not None and FileExists(self.PATH_MAKE_TP + 'MakeTP.exe'): print("POPUP: Compiling LS file with MakeTP.exe: %s..." % progname) sFileExtention = '.TP' sys.stdout.flush() import subprocess command = [self.PATH_MAKE_TP + 'MakeTP.exe', filesave.replace('/','\\'), filesave_TP.replace('/','\\'), '/config', self.PATH_MAKE_TP + 'robot.ini'] #output = subprocess.check_output(command) #self.LOG = output.decode('utf-8') self.LOG += 'Program generation for: ' + progname + '\n' with subprocess.Popen(command, stdout=subprocess.PIPE, bufsize=1, universal_newlines=True) as p: for line in p.stdout: line_ok = line.strip() self.LOG += line_ok + '\n' print("POPUP: " + line_ok) sys.stdout.flush() self.LOG += '\n' #Function to generate def ProgGenerateAssistScript(self, folder, prognames, scriptName, progMain, ftpparam, trigger_start=True): filenameToOpen = folder + '/' + scriptName sFileExtention = '.LS' if self.PATH_MAKE_TP is not None and FileExists(self.PATH_MAKE_TP + 'MakeTP.exe'): sFileExtention = '.TP' localProgNamesCopy = [] for progName in prognames: progName = progName + sFileExtention localProgNamesCopy.append(progName) param_list = ftpparam param_list.append(progMain + sFileExtention) param_list.append(str(localProgNamesCopy)) with open(filenameToOpen,"w+") as fid: fid.write(DRIPFEED_FILE % tuple(param_list)) if trigger_start: import subprocess import sys print("POPUP: Running dripfeeder") sys.stdout.flush() #subprocess.call([sys.executable, filenameToOpen], shell = False) command = 'start "" "' + sys.executable + '" "' + filenameToOpen + '"' print("Running command: " + command) sys.stdout.flush() os.system(command) def ProgSave(self, folder, progname, ask_user = False, show_result = False): ask_user = ask_user or self.FORCE_POPUP_SAVE progname = get_safe_name(progname) nfiles = len(self.PROG_LIST) if nfiles >= 1: if self.LINE_COUNT > 0: # Progfinish was not called! print("Warning: ProgFinish was not called properly") self.PROG_LIST.append(self.PROG) self.PROG_NAMES.append("Unknown") self.PROG = [] self.LINE_COUNT = 0 if len(self.PROG_NAMES_MAIN) > 1: # Warning: the program might be cut to a maximum number of chars progname_main = "M_" + self.PROG_NAMES_MAIN[0] self.INCLUDE_SUB_PROGRAMS = True # Force generation of main program self.ProgStart(progname_main) for prog_call in self.PROG_NAMES_MAIN: self.RunCode(prog_call, True) self.ProgFinish(progname_main) # Save the last program added to the PROG_LIST self.PROG = self.PROG_LIST.pop() progname_last = self.PROG_NAMES.pop() self.progsave(folder, progname_last, ask_user, show_result) #------------------------- #self.LOG = '' if len(self.PROG_FILES) == 0: # cancelled by user return first_file = self.PROG_FILES[0] folder_user = getFileDir(first_file) # progname_user = getFileName(self.FILE_SAVED) # Generate each program for i in range(len(self.PROG_LIST)): if show_result and i > 2: show_result = False self.PROG = self.PROG_LIST[i] self.progsave(folder_user, self.PROG_NAMES[i], False, show_result) #Generate Assist program #self.ProgGenerateAssistScript(folder_user,self.PROG_NAMES,"DripFeed.py", self.PROG_NAME) elif nfiles == 1: self.PROG = self.PROG_NAMES[0] self.progsave(folder, progname, ask_user, show_result) if len(self.PROG_FILES[0]): # user selected cancel return first_file = self.PROG_FILES[0] folder_user = getFileDir(first_file) else: print("Warning! Program has not been properly finished") self.progsave(folder, progname, ask_user, show_result) # Important: Generate dripfeed file, however, FTP credentials are not known at this point if self.DRIPFEED_FILE_NAME is not None: self.ProgGenerateAssistScript(folder_user,self.PROG_NAMES, self.DRIPFEED_FILE_NAME, self.PROG_NAME, [self.ROBOT_IP, 'md:/', 'anonymous', ''], False) if show_result and len(self.LOG) > 0: mbox('Program generation LOG:\n\n' + self.LOG) def ProgSendRobot(self, robot_ip, remote_path, ftp_user, ftp_pass): """Send a program to the robot using the provided parameters. This method is executed right after ProgSave if we selected the option "Send Program to Robot". The connection parameters must be provided in the robot connection menu of RoboDK""" if self.DRIPFEED_FILE_NAME is None: UploadFTP(self.PROG_FILES, robot_ip, remote_path, ftp_user, ftp_pass) else: first_file = self.PROG_FILES[0] folder_user = getFileDir(first_file) self.ProgGenerateAssistScript(folder_user, self.PROG_NAMES, self.DRIPFEED_FILE_NAME, self.PROG_NAME, [robot_ip, remote_path, ftp_user, ftp_pass]) def MoveJ(self, pose, joints, conf_RLF=None): """Add a joint movement""" self.page_size_control() # Important to control the maximum lines per program and not save last target on new program target_id = self.add_target_joints(pose, joints) move_ins = 'P[%i] %s %s ;' % (target_id, self.JOINT_SPEED, self.CNT_VALUE) self.addline(move_ins, 'J') self.LAST_POSE = pose def MoveL(self, pose, joints, conf_RLF=None): """Add a linear movement""" # important to have this check if we don't to move to the same instruction twice if self.LAST_POSE is not None and pose is not None: # Skip adding a new movement if the new position is the same as the last one if distance(pose.Pos(), self.LAST_POSE.Pos()) < 0.001 and pose_angle_between(pose, self.LAST_POSE) < 0.001: return self.page_size_control() # Important to control the maximum lines per program and not save last target on new program if pose is None: target_id = self.add_target_joints(pose, joints) move_ins = 'P[%i] %s %s ;' % (target_id, self.SPEED, self.CNT_VALUE) else: target_id = self.add_target_cartesian(pose, joints, conf_RLF) move_ins = 'P[%i] %s %s ;' % (target_id, self.SPEED, self.CNT_VALUE) #if self.HAS_EXTAXES: # move_ins = 'P[%i] %s %s COORD ;' % (target_id, self.SPEED, self.CNT_VALUE) # self.addline(move_ins, 'A') # self.LAST_POSE = pose # return self.addline(move_ins, 'L') self.LAST_POSE = pose def MoveC(self, pose1, joints1, pose2, joints2, conf_RLF_1=None, conf_RLF_2=None): """Add a circular movement""" self.page_size_control() # Important to control the maximum lines per program and not save last target on new program target_id1 = self.add_target_cartesian(pose1, joints1, conf_RLF_1) target_id2 = self.add_target_cartesian(pose2, joints2, conf_RLF_2) move_ins = 'P[%i] \n P[%i] %s %s ;' % (target_id1, target_id2, self.SPEED, self.CNT_VALUE) self.addline(move_ins, 'C') self.LAST_POSE = pose2 def setFrame(self, pose, frame_id=None, frame_name=None): """Change the robot reference frame""" xyzwpr = Pose_2_Fanuc(pose) if frame_id is None or frame_id < 0 or frame_id > 9: for i in range(6): self.addline('PR[%i,%i]=%.3f ;' % (self.SPARE_PR, i+1, xyzwpr[i])) for i in range(6,self.nAxes): self.addline('PR[%i,%i]=%.3f ;' % (self.SPARE_PR, i+1, 0)) self.addline('UFRAME[%i]=PR[%i] ;' % (self.ACTIVE_UF, self.SPARE_PR)) self.addline('UFRAME_NUM=%i ;' % (self.ACTIVE_UF)) else: self.ACTIVE_UF = frame_id self.addline('UFRAME_NUM=%i ;' % (self.ACTIVE_UF)) self.RunMessage('UF%i:%.1f,%.1f,%.1f,%.1f,%.1f,%.1f' % (frame_id, xyzwpr[0], xyzwpr[1], xyzwpr[2], xyzwpr[3], xyzwpr[4], xyzwpr[5]), True) frame_name_lower = frame_name.lower() # Auto detect motion group for post processor if self.HAS_EXTAXES: if 'gp3' in frame_name_lower: self.TURNTABLE_GROUP = 'GP3' self.EXTAXES_FLAGS[2] = '1' elif 'gp2' in frame_name_lower: self.TURNTABLE_GROUP = 'GP2' self.EXTAXES_FLAGS[1] = '1' else: self.EXTAXES_FLAGS[1] = '1' def setTool(self, pose, tool_id=None, tool_name=None): """Change the robot TCP""" xyzwpr = Pose_2_Fanuc(pose) if tool_id is None or tool_id < 0 or tool_id > 9: for i in range(6): self.addline('PR[%i,%i]=%.3f ;' % (self.SPARE_PR, i+1, xyzwpr[i])) for i in range(6,self.nAxes): self.addline('PR[%i,%i]=%.3f ;' % (self.SPARE_PR, i+1, 0)) self.addline('UTOOL[%i]=PR[%i] ;' % (self.ACTIVE_UT, self.SPARE_PR)) self.addline('UTOOL_NUM=%i ;' % (self.ACTIVE_UT)) else: self.ACTIVE_UT = tool_id self.addline('UTOOL_NUM=%i ;' % (self.ACTIVE_UT)) self.RunMessage('UT%i:%.1f,%.1f,%.1f,%.1f,%.1f,%.1f' % (tool_id, xyzwpr[0], xyzwpr[1], xyzwpr[2], xyzwpr[3], xyzwpr[4], xyzwpr[5]), True) def Pause(self, time_ms): """Pause the robot program""" if time_ms <= 0: self.addline('PAUSE ;') else: self.addline('WAIT %.2f(sec) ;' % (time_ms*0.001)) def setSpeed(self, speed_mms): """Changes the robot speed (in mm/s)""" if self.SPEED_BACKUP is None: # Set the normal speed self.SPEED = '%.0fmm/sec' % max(speed_mms, 0.01) # assume 5000 mm/s as 100% self.JOINT_SPEED = '%.0f%%' % max(min(100.0*speed_mms/5000.0, 100.0), 1) # Saturate percentage speed between 1 and 100 else: # Do not alter the speed as we are in ARC movement mode # skip speed settings if it has been overriden self.SPEED_BACKUP = '%.0fmm/sec' % max(speed_mms, 0.01) # assume 5000 mm/s as 100% #self.JOINT_SPEED = '%.0f%%' % max(min(100.0*speed_mms/5000.0, 100.0), 1) # Saturate percentage speed between 1 and 100 def setAcceleration(self, accel_mmss): """Changes the robot acceleration (in mm/s2)""" self.addlog('setAcceleration not defined') def setSpeedJoints(self, speed_degs): """Changes the robot joint speed (in deg/s)""" #self.addlog('setSpeedJoints not defined') self.JOINT_SPEED = '%.0f%%' % max(min(100.0*speed_degs/200.0, 100.0), 1) # Saturate percentage speed between 1 and 100 def setAccelerationJoints(self, accel_degss): """Changes the robot joint acceleration (in deg/s2)""" self.addlog('setAccelerationJoints not defined') def setZoneData(self, zone_mm): """Changes the zone data approach (makes the movement more smooth)""" if zone_mm < 0: self.CNT_VALUE = 'FINE' else: self.CNT_VALUE = 'CNT%i' % round(min(zone_mm, 100.0)) def setDO(self, io_var, io_value): """Set a Digital Output""" if type(io_var) != str: # set default variable name if io_var is a number io_var = 'DO[%s]' % str(io_var) if type(io_value) != str: # set default variable value if io_value is a number if io_value > 0: io_value = 'ON' else: io_value = 'OFF' # at this point, io_var and io_value must be string values self.addline('%s=%s ;' % (io_var, io_value)) def setAO(self, io_var, io_value): """Set an Analog Output""" self.setDO(io_var, io_value) def waitDI(self, io_var, io_value, timeout_ms=-1): """Waits for an input io_var to attain a given value io_value. Optionally, a timeout can be provided.""" if type(io_var) != str: # set default variable name if io_var is a number io_var = 'DI[%s]' % str(io_var) if type(io_value) != str: # set default variable value if io_value is a number if io_value > 0: io_value = 'ON' else: io_value = 'OFF' # at this point, io_var and io_value must be string values if timeout_ms < 0: self.addline('WAIT %s=%s ;' % (io_var, io_value)) else: self.LBL_ID_COUNT = self.LBL_ID_COUNT + 1 self.addline('$WAITTMOUT=%i ;' % round(timeout_ms)) self.addline('WAIT %s=%s TIMEOUT, LBL[%i] ;' % (io_var, io_value, self.LBL_ID_COUNT)) self.addline('MESSAGE[Timed out for LBL %i] ;' % self.LBL_ID_COUNT) self.addline('PAUSE ;') self.addline('LBL[%i] ;' % self.LBL_ID_COUNT) def addlastline(self, add_params): """Add parameters to the last command""" if len(self.PROG) > 0 and self.PROG[-1].endswith(';'): self.PROG[-1] = self.PROG[-1][:-1] + add_params + ';' # remove last 2 characters def RunCode(self, code, is_function_call = False): """Adds code or a function call""" if is_function_call: # Change the last line to force a Fine movement if len(self.PROG) > 0: str_search = ' ' + self.CNT_VALUE + ' ' str_replace = ' FINE ' self.PROG[-1] = self.PROG[-1].replace(str_search, str_replace) if code.lower().startswith("arcstart"): if not code.endswith(')'): code = code + ')' self.ARC_PARAMS = code[9:-1] if len(self.ARC_PARAMS) < 1: # Use default sine wave parameters self.ARC_PARAMS = '2.0Hz,8.0mm,0.075s,0.075' # To impose a desired weld speed, uncomment the following 2 lines: #self.SPEED_BACKUP = self.SPEED #self.SPEED = 'R[20]' # Force a specific weld speed # Provoke ARC START: self.addlastline('Arc Start[11]') # Tune weave with parameters self.addline('Weave Sine[%s] ;' % self.ARC_PARAMS) return # Do not generate default program call elif code.lower().startswith("arcend"): # Provoke ARC END: self.addlastline('Arc End[11]') # Revert to desired speed if self.SPEED_BACKUP is not None: self.SPEED = self.SPEED_BACKUP self.SPEED_BACKUP = None self.ARC_PARAMS = None return # Do not generate default program call code = get_safe_name(code, 12) # default program call code.replace(' ','_') self.addline('CALL %s ;' % (code)) else: if not code.endswith(';'): code = code + ';' self.addline(code) def RunMessage(self, message, iscomment = False): """Add a comment or a popup message""" if iscomment: #pass for i in range(0,len(message), 20): i2 = min(i + 20, len(message)) self.addline('! %s ;' % message[i:i2]) else: for i in range(0,len(message), 20): i2 = min(i + 20, len(message)) self.addline('MESSAGE[%s] ;' % message[i:i2]) # ------------------ private ---------------------- def page_size_control(self): if self.LINE_COUNT >= self.MAX_LINES_X_PROG: #self.nLines = 0 self.ProgFinish(self.PROG_NAME, True) self.ProgStart(self.PROG_NAME, True) def addline(self, newline, movetype = ' '): """Add a program line""" if self.nProgs > 1 and not self.INCLUDE_SUB_PROGRAMS: return self.page_size_control() self.LINE_COUNT = self.LINE_COUNT + 1 newline_ok = ('%4i:%s ' % (self.LINE_COUNT, movetype)) + newline self.PROG.append(newline_ok) def addline_targets(self, newline): """Add a line at the end of the program (used for targets)""" self.PROG_TARGETS.append(newline) def addlog(self, newline): """Add a log message""" if self.nProgs > 1 and not self.INCLUDE_SUB_PROGRAMS: return self.LOG = self.LOG + newline + '\n' # ------------------ targets ---------------------- def add_target_joints(self, pose, joints): if self.nProgs > 1 and not self.INCLUDE_SUB_PROGRAMS: return self.P_COUNT = self.P_COUNT + 1 add_comma = "" if self.HAS_TRACK: add_comma = "," self.addline_targets('P[%i]{' % self.P_COUNT) self.addline_targets(' GP1:') self.addline_targets(' UF : %i, UT : %i, ' % (self.ACTIVE_UF, self.ACTIVE_UT)) self.addline_targets('\tJ1= %.3f deg,\tJ2= %.3f deg,\tJ3= %.3f deg,' % (joints[0], joints[1], joints[2])) self.addline_targets('\tJ4= %.3f deg,\tJ5= %.3f deg,\tJ6= %.3f deg%s' % (joints[3], joints[4], joints[5], add_comma)) if self.HAS_TRACK: # adding external axes (linear track): track_str = '' for i in range(len(self.AXES_TRACK)): track_str = track_str + '\tE%i=%10.3f mm,' % (i+1, joints[self.AXES_TRACK[i]]) track_str = track_str[:-1] self.addline_targets(track_str) if self.HAS_TURNTABLE: # adding rotative axes (turntable): self.addline_targets(' %s:' % self.TURNTABLE_GROUP) self.addline_targets(' UF : %i, UT : %i,' % (self.ACTIVE_UF, self.ACTIVE_UT)) turntable_str = '' for i in range(len(self.AXES_TURNTABLE)): turntable_str = turntable_str + '\tJ%i=%10.3f deg,' % (i+1, joints[self.AXES_TURNTABLE[i]]) turntable_str = turntable_str[:-1] self.addline_targets(turntable_str) self.addline_targets('};') return self.P_COUNT def add_target_cartesian(self, pose, joints, conf_RLF=None): if self.nProgs > 1 and not self.INCLUDE_SUB_PROGRAMS: return def angle_2_turn(angle): if angle >= 0.0: return +math.floor((+angle+180.0)/360.0) else: return -math.floor((-angle+180.0)/360.0) #return add_target_joints(pose, joints) # using joints as targets is safer to avoid problems setting up the reference frame and configurations xyzwpr = Pose_2_Fanuc(pose) config = ['N','U','T'] #normal #config= ['F','D','B'] #alternative if conf_RLF is not None: if conf_RLF[2] > 0: config[0] = 'F' # F means axis 5 >= 0, N means axis 5 < 0 if conf_RLF[1] > 0: config[1] = 'D' if conf_RLF[0] > 0: config[2] = 'B' turnJ1 = angle_2_turn(joints[0]) turnJ4 = angle_2_turn(joints[3]) turnJ6 = angle_2_turn(joints[5]) self.P_COUNT = self.P_COUNT + 1 add_comma = "" if self.HAS_TRACK: add_comma = "," self.addline_targets('P[%i]{' % self.P_COUNT) self.addline_targets(' GP1:') self.addline_targets(' UF : %i, UT : %i, CONFIG : \'%c %c %c, %i, %i, %i\',' % (self.ACTIVE_UF, self.ACTIVE_UT, config[0], config[1], config[2], turnJ1, turnJ4, turnJ6)) self.addline_targets('\tX =%10.3f mm,\tY =%10.3f mm,\tZ =%10.3f mm,' % (xyzwpr[0], xyzwpr[1], xyzwpr[2])) self.addline_targets('\tW =%10.3f deg,\tP =%10.3f deg,\tR =%10.3f deg%s' % (xyzwpr[3], xyzwpr[4], xyzwpr[5], add_comma)) if self.HAS_TRACK: # adding external axes (linear track): track_str = '' for i in range(len(self.AXES_TRACK)): track_str = track_str + '\tE%i=%10.3f mm,' % (i+1, joints[self.AXES_TRACK[i]]) track_str = track_str[:-1] self.addline_targets(track_str) if self.HAS_TURNTABLE: # adding rotative axes (turntable): self.addline_targets(' %s:' % self.TURNTABLE_GROUP) self.addline_targets(' UF : %i, UT : %i,' % (self.ACTIVE_UF, self.ACTIVE_UT)) turntable_str = '' for i in range(len(self.AXES_TURNTABLE)): turntable_str = turntable_str + '\tJ%i=%10.3f deg,' % (i+1, joints[self.AXES_TURNTABLE[i]]) turntable_str = turntable_str[:-1] self.addline_targets(turntable_str) self.addline_targets('};') return self.P_COUNT # syntax examples for joint-defined targets: #P[1]{ # GP1: # UF : 1, UT : 1, # J1= 0.000 deg, J2= -40.966 deg, J3= 43.328 deg, # J4= 0.000 deg, J5= -84.792 deg, J6= 180.000 deg #}; #P[258]{ # GP1: # UF : 6, UT : 4, # J1= -41.180 deg, J2= -26.810 deg, J3= 11.060 deg, # J4= -217.400 deg, J5= 71.740 deg, J6= 85.790 deg, # E1= 0.000 deg #}; # syntax examples for cartesian targets: #P[2]{ # GP1: # UF : 1, UT : 1, CONFIG : 'F U T, 0, 0, 0', # X = 564.871 mm, Y = 0.000 mm, Z = 571.832 mm, # W = -180.000 deg, P = 0.000 deg, R = -180.000 deg #}; #P[8:]{ # GP1: # UF : 9, UT : 8, CONFIG : 'N D B, 0, 0, 0', # X = 0.000 mm, Y = -10.000 mm, Z = 0.000 mm, # W = 0.000 deg, P = 0.000 deg, R = 0.000 deg # GP2: # UF : 9, UT : 2, # J1= 0.000 deg, J2= 0.000 deg #}; # ------------------------------------------------- # ------------ For testing purposes --------------- def Pose(xyzrpw): [x,y,z,r,p,w] = xyzrpw a = r*math.pi/180 b = p*math.pi/180 c = w*math.pi/180 ca = math.cos(a) sa = math.sin(a) cb = math.cos(b) sb = math.sin(b) cc = math.cos(c) sc = math.sin(c) return Mat([[cb*ca, ca*sc*sb - cc*sa, sc*sa + cc*ca*sb, x],[cb*sa, cc*ca + sc*sb*sa, cc*sb*sa - ca*sc, y],[-sb, cb*sc, cc*cb, z],[0,0,0,1]]) def test_post(): """Test the post with a basic program""" robot = RobotPost('Fanuc_custom', 'Fanuc robot', 6) robot.ProgStart("Program") robot.RunMessage("Program generated by RoboDK", True) robot.setFrame(Pose([807.766544, -963.699898, 41.478944, 0, 0, 0])) robot.setTool(Pose([62.5, -108.253175, 100, -60, 90, 0])) robot.MoveJ(Pose([200, 200, 500, 180, 0, 180]), [-46.18419, -6.77518, -20.54925, 71.38674, 49.58727, -302.54752] ) robot.MoveL(Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] ) robot.MoveL(Pose([200, 200, 262.132034, 180, 0, -150]), [-43.73892, -3.91728, -35.77935, 58.57566, 54.11615, -253.81122] ) robot.RunMessage("Setting air valve 1 on") robot.RunCode("TCP_On", True) robot.Pause(1000) robot.MoveL(Pose([200, 250, 348.734575, 180, 0, -150]), [-41.62707, -8.89064, -30.01809, 60.62329, 49.66749, -258.98418] ) robot.MoveL(Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] ) robot.MoveL(Pose([250, 250, 191.421356, 180, 0, -150]), [-39.75778, -1.04537, -40.37883, 52.09118, 54.15317, -246.94403] ) robot.RunMessage("Setting air valve off") robot.RunCode("TCP_Off", True) robot.Pause(1000) robot.MoveL(Pose([250, 300, 278.023897, 180, 0, -150]), [-37.52588, -6.32628, -34.59693, 53.52525, 49.24426, -251.44677] ) robot.MoveL(Pose([250, 200, 278.023897, 180, 0, -150]), [-41.85389, -1.95619, -34.89154, 57.43912, 52.34162, -253.73403] ) robot.MoveL(Pose([250, 150, 191.421356, 180, 0, -150]), [-43.82111, 3.29703, -40.29493, 56.02402, 56.61169, -249.23532] ) robot.ProgFinish("Program") # robot.ProgSave(".","Program",True) robot.PROG = robot.PROG_LIST.pop() for line in robot.PROG: print(line) if len(robot.LOG) > 0: mbox('Program generation LOG:\n\n' + robot.LOG) input("Press Enter to close...") def test_post2(): def p(v): return Pose(v) print('Total instructions: 25') r = RobotPost(r"""Fanuc_R30iA""",r"""Fanuc ARC Mate 120iC""",9,axes_type=['R','R','R','R','R','R','T','T','T'], pose_rail=p([2835.968412,3817.764593,1195.654333,-0.000000,-0.000000,180.000000])) #r = RobotPost(r"""Fanuc_R30iA""",r"""Fanuc ARC Mate 120iC""",9,axes_type=['R','R','R','R','R','R'], pose_rail=p([2835.968412,3817.764593,1195.654333,-0.000000,-0.000000,180.000000])) r.ProgStart(r"""Curve1""") r.RunMessage(r"""Program generated by RoboDK v3.5.3 for Fanuc ARC Mate 120iC on 10/11/2018 10:34:26""", True) r.RunMessage(r"""Using nominal kinematics.""", True) r.setFrame(p([-13114.312225,1641.490176,3032.967400,-89.429405,-0.828158,0.547393]),-1,r"""Part Local Ref""") r.setTool(p([6.579694,-0.871557,381.879694,-0.000000,45.000000,-0.000000]),-1,r"""Weld gun""") r.setSpeed(1000.000) r.MoveJ(None,[83.882578,-15.754442,-46.523597,49.296707,69.533346,-29.398461,2984.678090,2570.163700,563.830565],None) r.MoveL(p([-128.772331,15775.117798,-2955.672119,142.328568,35.043147,-175.776553]),[83.882578,-15.754442,-46.523597,49.296707,69.533346,-29.398461,2984.678090,2570.163700,563.830565],[0.0,0.0,1.0]) r.RunCode(r"""ArcStart(2.0Hz,8.0mm,0.075s,0.075)""", True) r.MoveL(p([-87.947502,15734.292969,-3037.321777,142.328568,35.043147,-175.776553]),[87.328162,-15.924572,-40.474499,48.176067,63.664228,-32.552985,2984.678090,2570.163700,563.830565],[0.0,0.0,1.0]) r.setSpeed(50.000) r.MoveL(p([-87.947502,15740.364258,-3038.315186,143.296306,39.222486,-169.641516]),[84.993829,-15.820725,-37.736589,57.497002,62.008852,-34.964581,2984.678090,2570.163700,563.830565],[0.0,0.0,1.0]) r.MoveL(p([-87.947502,15753.342773,-3056.371826,162.364741,57.321011,-139.122540]),[83.865207,-17.204132,-23.104629,94.375731,49.260470,-53.900868,2984.678090,2570.163700,563.830565],[0.0,0.0,1.0]) print('Done instruction: 10') sys.stdout.flush() r.MoveL(p([-87.947502,15753.342773,-3056.371826,162.364741,57.321011,-139.122540]),[83.865207,-17.204132,-23.104629,94.375731,49.260470,-53.900868,2984.678090,2570.163700,563.830565],[0.0,0.0,1.0]) r.setSpeed(50.000) r.MoveL(p([-87.947502,15753.342773,-3323.071777,178.450701,-27.782697,-41.102688]),[91.280214,-24.514099,-7.482821,94.264844,27.576637,52.827242,2984.678090,2570.163700,563.830565],[0.0,0.0,1.0]) r.MoveL(p([-87.947502,15734.292969,-3342.121826,115.212292,-23.920623,8.299772]),[82.536012,-9.623914,-3.656630,110.966378,66.076926,91.743683,2984.678090,2570.163700,563.830565],[0.0,0.0,1.0]) r.setSpeed(50.000) r.MoveL(p([-87.947502,15467.592773,-3342.121826,106.861708,12.533873,22.086494]),[109.719609,2.464938,10.538370,161.900353,67.639292,65.645182,2984.678090,2570.163700,563.830565],[0.0,0.0,1.0]) print('Done instruction: 20') sys.stdout.flush() r.setSpeed(1000.000) r.RunCode(r"""ArcEnd""", True) r.MoveL(p([-87.947502,15467.592773,-3342.121826,106.861708,12.533873,22.086494]),[109.719609,2.464938,10.538370,161.900353,67.639292,65.645182,2984.678090,2570.163700,563.830565],[0.0,0.0,1.0]) r.MoveL(p([-93.977729,15961.562547,-2860.212507,106.861708,12.533873,22.086494]),[79.404467,-8.562284,-21.927019,140.074273,53.809210,114.164583,2984.678090,2570.163700,563.830565],[0.0,0.0,1.0]) r.ProgFinish(r"""Curve1""") r.PROG = r.PROG_LIST.pop() for line in r.PROG: print(line) if len(r.LOG) > 0: mbox('Program generation LOG:\n\n' + robot.LOG) input("Press Enter to close...") if __name__ == "__main__": """Function to call when the module is executed by itself: test""" test_post2()