P
ar
t
1: P
rog
ra
m
ming
Moog Animatics SmartMotor™ Developer's Guide, Rev. L
Page 189 of 909
Program Flow Examples
The following are techniques that can be used for flow control in your SmartMotor program.
All sample code shows advanced use of program flow syntax. Additionally, there are
references to lesser-used math functions and system parameters to enforce learning of new
programming techniques.
NOTE:
The Variables and Math section should be referenced for a better
understanding of the following example programs. For details, see Variables and
Math on page 195.
IF, ELSEIF, ELSE, ENDIF Examples
The following example shows the proper use of the IF, ELSE and ENDIF commands along with
nested conditions and math capabilities. For more details on the IF, ELSE and ENDIF
commands, see IF, ENDIF on page 184.
'Find shortest dist. to Top Dead Center Shaft position from present position
IF
(
PA
%
RES
)>(
RES
/2)
'Check shortest distance using Modulo Math function
PRT
=
RES
-(
PA
%
RES
)
'Set Relative Position to Modulo Remainder
ELSE
PRT
=-(
PA
%
RES
)
'Otherwise Set to RES - Modulo remainder
ENDIF
The following example uses #define to associate values and I/O points for use in code.
#define
UpperLimit
3000
'Set high voltage threshold
#define
LowerLimit
1500
'Set low Voltage
threshold
#define
MyVoltage
INA
(V1,3)
'Set input Port to read
C124
IF
(UpperLimit>MyVoltage) & MyVoltage>LowerLimit
("Voltage is in range",#13)
ELSEIF
MyVoltage>=UpperLimit
("Voltage is too high",#13)
ELSE
("Voltage is too low",#13)
ENDIF
RETURN
WHILE, LOOP Examples
The following example shows the proper use of the WHILE and LOOP commands. For more
details on these commands, see WHILE, LOOP on page 186.
Part 1: Programming: Program Flow Examples