Hello Axillus and welcome to the forum,
There are some things to consider:
1. I would replace WAIT FOR statement with a DELAY statement.
2. If you want to run in parallel with other programs, as dha stated, you would start it with RUN.
3. If you start it with RUN and you want to run it continously you will need another WHILE or REPEAT loop above WHILE (duration > clock_var) DO
This loop will provide means on controlling the running/abort status of the program. Just use some virtual outputs (DO's mapped to rack 0, slot 0).
If you want the program just to finish after logging the data at 20 sec interval you don't need this extra loop.
In other case, run the program non-stop the program would look like :
REPEAT
- start recording
WHILE (duration > clock_var) DO
......
ENDWHILE
clock_var=0
DELAY(50)
UNTIL DOUT[..]=OFF
And you make DOUT[...]=ON in the beginning of the program. If you want to cancel the program you just make DOUT[..]=OFF.
And also take out SET_PERIOD routine.
I've made some modifications to your code:
PROGRAM datarecorder
%COMMENT = 'LOG DATA RECORD'
%SYSTEM
%NOLOCKGROUP
%NOABORT=ERROR+COMMAND+TPENABLE
%NOPAUSE=ERROR+COMMAND+TPENABLE
%NOPAUSESHFT
VAR
logFile : FILE
filename : STRING[16]
duration : INTEGER -- recording duration in milliseconds
clock_var : INTEGER -- clock count in milliseconds
period : INTEGER -- recording period in milliseconds (8 ms to 127 ms)
timeInt : INTEGER -- actual time
timeStr : STRING[18] -- formated
IntTQa1 : REAL -- internal joint torque on axis 1
IntTQa1Str : STRING[4] -- formated
entry : INTEGER
status : INTEGER
-- tests
test : INTEGER
clocky : INTEGER
-----------------------------------------------------------------------------------
-- routine to get internal torque measured on axis 1
ROUTINE GET_INT_TQ(active : BOOLEAN)
BEGIN
IF active=TRUE THEN
GET_VAR(entry, '*SYSTEM*', '$MOR_GRP[1].$CUR_TORQUE[1]', IntTQa1, status)
ENDIF
END GET_INT_TQ
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-- main routine
BEGIN -- execute the program
clock_var = 0
-- begin the clock time count
CONNECT TIMER TO clock_var
period = 150 -- ms
duration = 10000 -- ms
filename = 'UT1:'+'TEST'+'.dt'
entry = 0
status = 0
-- tests
test = 0
clocky = 0
-- get actual time and convert it into string
GET_TIME(timeInt)
CNV_TIME_STR(timeInt, timeStr)
-- open the log file
OPEN FILE logFile ('AP', filename)
-- write actual time and make a carriage return
WRITE logFile (timeStr, CR)
-- start recording
WHILE (duration > clock_var) DO
clocky = clock_var
test = clocky+period
GET_INT_TQ(TRUE) -- call internal torque routine
CNV_REAL_STR(IntTQa1, 2, 2, IntTQa1Str)
WRITE logFile(clock_var)
--WRITE logFile(';')
--WRITE logFile(IntTQa1Str, CR)
DELAY(period)
ENDWHILE
-- stop recording, close log file
CLOSE FILE logFile
-- end of program
END datarecorder
Display More