::heading=Context
This article describes a method on how to log program variables into a .csv file on the robot.
::important=The Screwdriving URcap must be installed to use this method.
::heading=Knowledge
In a script function, one can use the following to append a variable to a .csv file on the robot.
bash.echo("variables_to_log", ">>", filename)
::info=If the file does not exist, it will be created.
::info=The ">>" creates a new line on the file.
The filename variable should contain the filename as well as the file path on the robot.
::info=If filename="/programs/log.csv", then the log file will be called log.csv and be located in the programs folder on the robot.
The "variables_to_log" string should contain the desired variable to appear in the .csv file. They should be separated in the string by a separator character. When the .csv file is open on a computer, the given character should be used as the separator to properly separate the columns.
A custom script function was written to ease this process, logging_main.script. To use this function, the script file must be included in the Before Start section of the program.
Then, one can use the log_csv_row(filename, col1, col2, col3, ...) script function. Each argument after filename represents a new column in the .csv file. The arguments do not need to be strings. Up to 20 columns can be set this way. With this function, the separator used is the * character.
::info=The function can be used in the Before Start section of the program with the names of the columns to make a header.
::heading=Example
This section shows an example using the previously mentioned function with a screwdriver program. Here, the program logs whether the torque was reached or not and the angle reached during the fastening.

And here is the created log.csv file.

As mentioned, the use of the function in the Before Start section of the program creates the header (column titles). Each subsequent use of the function creates a new line, filling the columns with the variable values.
0 Comments