use Karel read data from .DT file

  • Good morning guys,

    is there anyone know how to read data from a .dt file with KAREL? the data is applied as input for further programming,

    . dt file is consists of string and numbers(real), for instance:

    data monitor

    joint1 joint2 joint3

    3.513 2.034 13.765

    3.513 10.234 14.244

    i have tried several times following the karel manual, however, it seems that some important part is still missing.


    best regards,


    Chen

  • Here's a short karel program I wrote when I was trying to figure out how to read from .DT files. It reads the file line by line and prints the line to the user screen.

  • Good morning TitusLepic,


    thank you for the reply.

    i used your program to read my .dt file, unfortunately, it does not show any number or string in the TPdisplay, the USER screen.

    my .dt file is generated by data monitor, the template is given as below:

    DATA MONITOR REPORT


    Number Tick Time J1

    1 250 .500 -150.524

    2 500 1.000 -176.253

    3 750 1.500 -162.752

    ... ... ... ...


    do you happen to know what might be the reason why the program does not work?


    regards,

    Chen

    Here's a short karel program I wrote when I was trying to figure out how to read from .DT files. It reads the file line by line and prints the line to the user screen.

  • Sounds like you're probably getting an error when you're trying to read the file. Did you change the filepath to point to your dt file?


    add this line between lines 17 & 18, it will show what the error is:

    WRITE TPERROR('error: ', STATUS,CR)

  • the file was loaded successfully, running the program give no error remark. however, the user screen shows nothing.

    after added the extra line between 17&18, an error 'uninitialized value' appeared.

    if it is possible, could you show the screenshot of what the result in your user screen looks like after run the karel program? and provide a .dt file which works properly.


    thank you for your help, really appreciate it.

    Chen


    Sounds like you're probably getting an error when you're trying to read the file. Did you change the filepath to point to your dt file?


    add this line between lines 17 & 18, it will show what the error is:

    WRITE TPERROR('error: ', STATUS,CR)

  • Hi,

    with copy andy paste the code above can't work.


    STATUS would be uninitialized.


    ...

    EOF = FALSE

    REPEAT

    READ myfile(curLine)


    STATUS = IO_STATUS(myfile)

    IF STATUS = 0 THEN


    WRITE TPDISPLAY(curLine,cr)

    ELSE

    WRITE TPERROR('error: ', STATUS,CR)

    EOF = TRUE

    ENDIF

    UNTIL EOF

    CLOSE FILE myfile

    ....


    !!

    WRITE TPERROR('error: ', STATUS,CR)

    !!

    but this is not useful.


    try:


    POST_ERR(STATUS,'',0,2)


    Syntax: POST_ERR(error_code, parameter, cause_code, severity)

    ...

  • Hi PnsStarter,

    Thank you for your reply.

    POST_ERR works well after adding an extra line to define the status(status=IO_STATUS(myfile)),

    it found that this definition was missing, which is the reason for causing "uninitialized" error.

    regards,

    Chen


  • hi TitusLepic,

    your program is correct for loading the .dt file.

    it turns out that my file's path was not accessible. after changing the file path, the program works perfectly.

    thank you for your help,

    regards,

    Chen

    Sounds like you're probably getting an error when you're trying to read the file. Did you change the filepath to point to your dt file?


    add this line between lines 17 & 18, it will show what the error is:

    WRITE TPERROR('error: ', STATUS,CR)

Advertising from our partners