What I have done in the past is store the VR.Offset to a PR. I have data PRs 41-43 o, then at the end of the TP program I "RUN OFFLOGV2". This prgram outputs a .csv file with a header line then adds lines with the vision offsets. This also contains handling logic for when the log files grow too large.
PROGRAM OFFLOGV2
%COMMENT = 'Offset Logger'
%NOLOCKGROUP
%NOPAUSE = ERROR + COMMAND + TPENABLE
%ENVIRONMENT IOSETUP
%ENVIRONMENT REGOPE
%ENVIRONMENT TIM
%ENVIRONMENT STRNG
%ENVIRONMENT BYNAM
%ENVIRONMENT FDEV
%INCLUDE KLIOTYPS
--This karel program stores the vision offset and grommet install status
CONST
file_spec = 'FR:Off_log2.csv'
oldfile_spec = 'FR:Off_log2.old'
n_skip = 0
maxgrom =13
maxfilesize=1048576 --1 megabyte
VAR
file_var1 : FILE
offset :XYZWPR
STATUS,
filesize,
task,
i,
timeint,
l_status,
n_files :INTEGER
xoffstr,
yoffstr :STRING[7]
timestr :STRING[32]
teststr :STRING[254]
ary_name :ARRAY[9] OF STRING[40]
fileprops :ARRAY[4] OF STRING[40]
BEGIN
--Get the current task number
GET_PORT_VAL(io_gpin, 3, task, STATUS)
IF (STATUS=0) THEN
--clear out the ary_name var for the file search
FOR i=1 TO ARRAY_LEN (ary_name) DO
ary_name[i] = ''
ENDFOR
--See if the log file exists, create header if not.
FILE_LIST (file_spec, n_skip, 4, ary_name, n_files, l_status)
--Pull the file size out of the ary_name var if a file exists.
IF (n_files=1) AND (l_status=0) THEN
--File exisits. See if it is too large.
--Substring lengths from the karel manual. The string from the FILE_LIST command will look like this:
-- OFF_LOG .CSV 1864 23-MAR-14 19:11
fileprops[1]=SUB_STR(ary_name[1],1,8) --File name
fileprops[2]=SUB_STR(ary_name[1],9,4) --File ext
fileprops[3]=SUB_STR(ary_name[1],13,11) --File size in bytes
fileprops[4]=SUB_STR(ary_name[1],24,16) --File creation date & time
CNV_STR_INT(fileprops[3],filesize)
IF (filesize>maxfilesize) THEN
--Too large, rename it and start a fresh one. Delete the old one if it exists.
DELETE_FILE(oldfile_spec,FALSE,STATUS)
RENAME_FILE(file_spec,oldfile_spec,FALSE,STATUS)
--Set n_files to a 0 so the header creation runs.
n_files=0
ENDIF
ENDIF
OPEN FILE file_var1 ('AP',file_spec)
IF (n_files=0) AND (l_status=0) THEN --file not found, create header.
WRITE file_var1 ('Date & Time,Task number,')
FOR i=1 TO maxgrom DO
WRITE file_var1 ('Grom',i,' x offset,Grom',i,' y offset,Grom',i,' install,')
ENDFOR
WRITE file_var1 (CR)
ENDIF
--Write the date and time and current task number.
GET_TIME(timeint)
CNV_TIME_STR(timeint,timestr)
WRITE file_var1 (timestr,',',task)
--Write all the offsets.
FOR i = 1 TO maxgrom DO
offset=GET_POS_REG(40+i,STATUS)
IF (STATUS = 0) AND NOT (UNINIT(offset)) THEN
--xoff=offset.x
--yoff=offset.y
CNV_REAL_STR(offset.x,7,3,xoffstr)
CNV_REAL_STR(offset.y,7,3,yoffstr)
ELSE
xoffstr = 'NULL'
yoffstr = 'NULL'
ENDIF
WRITE file_var1 (',',xoffstr,',',yoffstr,',',FLG[i])
--clear old pos_reg CLR_POS_REG(register_no, group_no, status)
--CLR_POS_REG(40+i, 1, STATUS)
ENDFOR
WRITE file_var1 (CR)
CLOSE FILE file_var1
ELSE
--Unknown task or status failed. Exit.
ENDIF
END OFFLOGV2