On this page

Program Development

Commander series of controllers utilizes AScript, a BASIC-like language that helps the programmer quickly write programs for motion control projects, including conditional statements (IF, ELSE, ELSEIF, ENDIF, WHILE, ENDWHILE), subroutines, and mathematical and logical expressions (=, !=, <, >, <=, >=, +, -, *, /).  Single-line comments are available and start with ; and continue until the end of the line. The programming syntax uses a series of standalone commands, listed in section Standalone Command Set, that allows the programmer to build single and multi-thread programs that can be compiled and run in the controller.  By writing lines of code using the set of commands that make up the A-Script language, set-up, control of motion, management of inputs and outputs, and error handling can all be addressed. A basic program consists of a start line (PRGxx) and an end line (END).  All code is written between the PRG and END lines.  Use the Utility software to write, compile, download, upload, and execute programs.

Return to Top

Subroutines

Up to 32 (0-31) subroutines can be called upon. Subroutines are independent program snippets that can be accessed based on the needs of the programmer.  Typically, subroutines are used to perform functions that are repeated throughout the operation and can be used in conjunction with logic statements related to motor actions or the status of inputs and outputs.  Sections Standalone Example Program 6 – Single Thread with subroutine, Standalone Example Program 9 – Multi-thread with subroutine, and Standalone Example Program 10 – Multi-thread with subroutine contain examples of using a subroutine in a program.

Subroutine 31 is used specifically for error handling and is executed whenever an error occurs.

Note: Subroutines can be shared by both standalone programs and the ASCII command set.  Once a subroutine is written into the flash memory, it can be recalled via ASCII communication using the GS command. Standalone programs can also jump to a subroutine using the GOSUB command. The subroutines are referenced by their subroutine number [SUB 0- SUB 31]. If a subroutine number is not defined, the controller returns with an error.

Return to Top

Error Handling

Subroutine 31 (SUB 31) is used specifically for error handling and is executed whenever an error occurs. If SUB 31 is not defined, the program will cease execution and go into an error state.

How errors are addressed can be coded in SUB 31.  Conditional statements that check for specific error conditions can execute additional operations, depending on the error conditions.  Typically, the code within subroutine 31 will contain the standalone command ECLEAR[axis] in order to clear the current error. Sections Standalone Example Program 7 – Single Thread with error handling, Standalone Example Program 9 – Multi-thread with subroutine, and Standalone Example Program 10 – Multi-thread with subroutine contain examples of using subroutine 31 to perform error handling.

The return jump from subroutine 31 are determined by the ASCII command SAP. Write a 0 to this setting to have the standalone program jump back to the last performed line. Write a 1 to this setting to have the standalone program jump back to the first line of the program.

Value

Description

0

Return to last excited line

1

Return to first line of program

SAP command

Return to Top

Multi-thread

The Commander series of controllers utilizes four independent processors that can run simultaneously. Therefore, it is possible to run multiple programs at the same time with or without coordination. 

While multiple programs may be running independently, global variable settings can cause unintended consequences between individual programs.  As an example, a thread that changes the position mode to incremental could inadvertently cause the position moves of a second thread to respond incorrectly, if it was based on absolute position mode.  As such it is recommended that all motion activities be written in one thread, which will prevent unintended interactions between axes, utilizing the other threads to manage I/O and other monitoring operations. 

Standalone Example Program 8 – Multi-thread, through Standalone Example Program 10 – Multi-thread with subroutine contain examples of using multi-threads in a program.

Return to Top

Compile, Save, Download

Standalone programs can be written to the Commander series of controllers using the Windows GUI. Refer to the Software Manual for details. Once a standalone program is written by the user, it is then compiled, saved for future reference and downloaded to the Commander core.  Each line of written standalone code creates 1-4 assembly lines of code after compilation.  See the software manual for more information.

Return to Top