I made this topic to show you a very nice feature that is not listed in any manual from Fanuc.
The following quote is my original post (from which this topic came), you can generally skip it and go straight to the description of the .CM files.
Please feel free to contribute and leave a Thank you
I am working on some small Karel software solution, that is sold to our customers as a "software package". To make the installation easier for the customer, I have prepared a .CM file that loads all necessary files (.PC, .VR, .TP, .TX etc.) to the robot and it works great. The thing is, that I would also like the file to do some more advanced changes or be flexible (allowing it to react to some unpredicted situations). As far as I know, it is doable, but can't seem to find any help on the syntax.
The commands that I use in the current file are taken from some other Fanc .CM files. These are:
# KCL LOAD FORM (this one allows me to think, that it is possible to use the KCL commands in the .CM files, but that does not help a lot, as I would also like to check some values and use conditional instructions if possible)
Okay, so this topic became a sticky one I will gather all the syntax posted in this topic in the first post, so that it is easy to find. Also, I will try to explain as much on the .CM files as I can find.
Please feel free to post anything you find out on .CM files, your suggestions, corrections or anything else which can make this topic better
The list contains .CM instructions grouped according to their functionality. Instructions in each group are listed alphabetically (at least more-or-less ).
What is a .CM file?
I guess it's a tool dedicated for Fanuc software developers. Basically, it's a file that can be executed using the FILE menu of the robot. It can perform various operations on files, programs (including .PC), variables (in specific programs or the system), print out information etc. It's a perfect solution for changing the robot configuration or creating installation procedures for custom software. For example, it is possible to:
- quickly change the robot configuration from delivery state to a specification that you use as standard, by operating on system variables
- create a kind of "installation wizards" for your custom-made software: loading files, running programs, setting up desired system variables etc. Hint: what Fanuc does (and what I have also implemented) is creating various .PC programs which perform operations more advanced than the .CM syntax allows, but loading, running, then deleting them and their variables using the .CM file, according to the logic evaluated in the .CM file)
- ...and many more, the possibilities here are really great!
.CM files can be executed in Cold/Hot- and Controlled-Start modes of the controller.
How do I create a .CM FILE?
.CM files are just text files that contain a set of instructions for the controller (they do not even have to be placed in separate lines). You can create a .CM file using any text editor (including a standard Windows Notepad). You just write the instructions, save the file with a .CM extension and that's it. Example (based on a software package's installation .CM-file that I have created):
How do I run a .CM FILE?
Create a .CM file, load it to a memory device (like an USB-stick), connect it to the robot, find the file using the FILE menu and then just select it, press ENTER and confirm with F4 - YES. The .CM files are not loadable, you just execute them from where they are.
Just remember to run your .CMs in the main window of the Teach Pendant (the left one when the screen is split). The file will be executed, with an appropriate information after the successful completion (that you should confirm with F4 - OK). That's all!
- Be careful when trying to make your file clearer by implementing spaces and/or tabulators in the layout. SOME INSTRUCTIONS DO NOT WORK WITH TABs (e.g. PCVLOAD), AND OTHERS WITH SPACES (e.g. KCL) BEFORE THE ACTUAL INSTRUCTION. Either do not use tabs/spaces before instructions, or test the file for proper function when using them.
KCL (Karel Command Language):
KCL anyKCLcommand - this allows you to use KCL commands, listed in the Karel Reference Manual. You can use it for operations on variables, files etc, for example:
This is definitely the most powerful tool for .CM files, as the KCL commands (described in the Karel manual) allow you a better control over the performed operations, and the command palette is much wider than the one of standard .CM instructions.
PROGRAM FLOW CONTROL:
IF statement - note: arguments listed one after another seem to be interpreted as OR - see the 2nd example of ORDER evaluation with IF.
- IF VAR VarName "VarValue" ... ELSE ... ENDIF - evaluates the value of the specified variable. Be sure to compare the variable with a correct data type. This function seems to have problems when working with variable arrays, like the $CUSTOMMENU variable...
- IF ORDER xxxx ... ELSE ... ENDIF - evaluates the robot specification.
OPERATIONS ON VARIABLES:
SETVAR $VarName VarValue - sets the specified system variable to the specified value. Be sure to use same data types.
OPERATIONS ON IOs:
This instruction comes from this reply by lexx905. I've done some interpretation of the instruction's parameters and I hope it's ok. Multiple examples provided below should help. I haven't tested this instruction yet, but I assume, that standard limitations to IOs apply here (so setting unsimulated inputs may be impossible).
SETIOVAL type index sim_mask unsim_val sim_val - sets an IO point of selected type to a selected value in a selected mode, where:
1 = DI
2 = DO
8 = RI
9 = RO
- index is just an index number of the IO point
0 = signal unsimulated
1 = signal simulated
- unsim_val is the value in UNSIMULATED mode
- sim_val is the value in SIMULATED mode
- instructions which are type-specific (designed to work with a particular filetype, like PCLOAD for PC-files only, VRCLEAR for .VR, etc.) should all work as described for PCLOAD - with full path, or just a filename (with the extension ommited in this case). However, there are some exceptions (like VRLOAD or TPLOAD) - as this is not an official feature, the syntax is a bit messy sometimes...
- generally, adressing goes as follows: you can use dev:filename when the addressed file is in the root folder of the selected device, but you have to use dev:\folder\...\filename.filetype if it is located deeper in the structure.
ASLOAD filename - loads namefile.AS (assembly files - used internally)
COPY device:\(path\)sourcefile.filetype device:\(path\)targetfile.filetype - copies sourcefile to targetfile.
DEL filepath:\filename.filetype\ - deletes filename.filetype located in filepath
DELFR FR:\filename.filetype - deletes filename.filetype from FROM (can also be used to delete files from FRS - internal system memory, not accessible via TP):
DELPC ProgramName - deletes the specified .PC program from the robot memory
DELTP ProgramName - deletes the specified .TP program from the robot memory. Important: this instruction will simply ignore a non-existing .TP program. This means it can be used before TP loading instructions to make sure they do not hit an existing file (which leads to .CM file execution being aborted). More in THIS post.
FRCOPY fr_:\targetfile.filetype dev:\sourcefile.filetype - copies a source file to specified location on FROM. fr_ is for FR, FRS, FRSU, FRB - however, have no idea what the last two mean). Can be used to copy any type of files, including .SV and .IO:
MKDIR device:folder - creates a folder under a specified address
PCCLEAR filename - clears namefile.PC (removes from program stack)
PCLOAD Device:\PathToProgram\ProgName.PC - loads the specified .PC program
Can be also used just with a program name (without the path) - the program will be loaded from the currently selected device:
PCVLOAD filename - loads filename.SV (no .SV-extension in the instruction!)
RUNPC ProgramName - runs the specified .PC program that is loaded to the robot (no .PC-extension in the instruction!)
TPLOAD programname.tp or TPLOAD device:program.tp - loads the specified .TP program to the robot memory (.TP-extension required!), for example:
TXPLOAD filename - loads filename.TX (no .TX-extension in the instruction!)
VRCLEAR ProgramName - deletes the .VR file of the specified program from the robot's memory (no .PC- or .VR-extension in the instruction!)
VRLOAD device:filename.vr - loads a specified .VR file to the robot's memory (.VR-extension required!), for example:
WR_FILE device:filename.filetype "text" - attaches a given text to the contents of the given file. I guess this instruction can only modify files in the root folder of a selected device.
@path:\file.cm - executes another .CM file from within the current .CM file. Can be used without path - in this case, the current device and path will be used. If the .CM file is located in the root folder of the memory device, backslash can be ommited in path. Examples:
CLRALMH - clears alarm history
DELAY # - delays execution of the .cm file by # milliseconds. DELAY 1000 will wait 1 second.
EXIT - finishes the .CM file execution. Can be used in IFs, to finish the execution before the whole program is completed (on errors for example).
IGALBKUP device:\folder - stores an AoA backup in a specified folder
PRINT "string" - displays the specified string. If you do not use quotation marks, only the string up to the first space will be displayed. If you use quotation marks, the whole string between them will be displayed, BUT including the marks.
SPEP_ON / SPEP_OFF -
not sure what these instructions do, but Fanuc uses SPEP_OFF right before operations like MKDIR, DEL, COPY or other istructions which operate on the structure of files or folders, and SPEP_ON right after these instructions, like in the example below (taken straight from a .CM file made by Fanuc)
EDIT: these instructions allow you to ignore errors from some instructions and avoid breaking the whole sequence because of one instruction returning an error. SPEP_OFF makes the .CM execution ignore the errors, SPEP_ON makes it vulnerable to faults again.
In the example below, if file TEMP_MEMORY_STAT.DG doesn't exist or any other fault is encountered by the COPY... instructions, the execution of the .CM file will not be aborted:
There are also instructions like COLDSPEP_ON and COLDSPEP_OFF, but found them only in 1 file and ofc have no idea what they do...
RE_POWER - cycles power on the controller. Be careful with this instruction - I have only tested it in Roboguide so far and it works OK when the .CM file is executed in Cold-Start, but causes a VARS-204 Power-off incomplete fault when in Controlled-Start!