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 (PRG xx) 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

Conditional loop control

A-Script supports a number of conditional statements that perform different actions for different conditions. A-Script supports the following conditional statements: IF/ELSEIF/ELSE loop and WHILE loop.  Table Conditions below shows the available conditions.

Symbol

Meaning

=

Equals

!=

Not Equal

>

Greater than

<

Less than

>=

Greater than or Equals

<=

Less than or Equals

Conditions

Examples of using conditional loop control in a program are found in sections Standalone Example Program 3 – Single Thread, through Standalone Example Program 10 – Multi-thread with subroutine.

Return to Top

Standalone Variables

Commander controllers have 100 32-bit signed standalone variables available for general purpose use. They can be used to perform basic calculations and support integer operations. The V [0-99] command can be used to access the specified variables. The syntax for all available operations are seen in the table below. 

Note: These operations can only be performed in standalone programming.

Operator

Description

Example

+

Integer Addition

V1=V2+V3

-

Integer Subtraction

V1=V2-V3

*

Integer Multiplication

V1=V2*V3

/

Integer Division (round down)

V1=V2/V3

%

Modulus

V1=V2%5

>>

Bit Shift Right

V1=V2>>2

<<

Bit Shift Left

V1=V2<<2

&

Bitwise AND

V1=V2&7

|

Bitwise OR

V1=V2|8

~

Bitwise NOT

V1=~V2

Operations

All variables can be accessed and written with the ASCII V[0-99] command. Variables V0-V49 are initialized to zero on power up, and variables V50 through V99 can be stored to flash memory using the STORE command.

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 - Single Thread with subroutine, Standalone Example - Multi-thread with subroutine, and Standalone Example - 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 – Single Thread with error handling, Standalone Example  – Multi-thread with subroutine, and Standalone Example  – 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 – Multi-thread, through Standalone Example – 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

Standalone Control

The Commander series of controllers supports the simultaneous execution of four standalone programs. All programs can be controlled by the SACTRL[0-3]=[control] ASCII command and the SR[0-3]=[control] standalone command. Program 0 uses command SACTRL0, Program 1 uses command SACTRL1, and so on.  The following [control] assignments can be used for the standalone control command.

Value

Description

0

Stop standalone program

1

Start standalone program

2

Pause standalone program

3

Continue standalone program

SACTRL command

Return to Top

Standalone Status

The SASTAT[0-3] command can be used to determine the current status of the specified standalone program. The table below details the returned values of this command.

Value

Description

0

Idle

1

Running

2

Paused

3

N/A

4

Error

SASTAT command

The SPC[0-3] command can also be used to find the current assembled line that the specified standalone program is executing. Note that the return value of the SPC[0-3] command is referencing the assembly language line of code and does not directly transfer to the pre-compiled user generated code. The return value ranges from [0-1799].

Return to Top

Standalone Run on Boot-Up

Standalone can be configured to run on boot-up using the SLOAD command.  Once this command has been issued, the STORE command is needed to save the setting to flash memory. It will take effect on the following power cycle. See description in the table below for the bit assignment of the SLOAD setting.

Bit

Description

0

Standalone Program 0 

1

Standalone Program 1 

2

Standalone Program 2

3

Standalone Program 3

SLOAD  command

ASCII

SACTRL[0-3]

SASTAT[0-3]

SPC[0-3]

GS[0-31]

V[0-99]

SLOAD

Standalone

SR[0-3]

-

-

GOSUB[0-31]

V[0-99]

-


ASCII

SAP

STORE

Standalone

-

STORE