Skip to content
English
  • There are no suggestions because the search field is empty.

How to log variables into a CSV file

Use script to track and export runtime data from your program

 

This article explains how to log program variables into a .csv file stored on the robot. This can be useful for tracking events, measurements, or process status over time.

Important: The Robotiq Screwdriving URCap must be installed for this method to work.

 

Basic Logging Using bash.echo

You can append values to a .csv file using the following script command:

bash.echo("variables_to_log", ">>", filename)
  • filename must include the full path and name of the file, e.g.:

    filename = "/programs/log.csv"
  • variables_to_log is a string containing one or more variables separated by a character (e.g., , or *).

  • The >> operator appends a new line to the file.

If the file doesn’t exist, it will be automatically created.

 

Advanced Logging with log_csv_row Function

A custom script file, logging_main.script, simplifies the logging process. It must be included in the Before Start section of your UR program.

Once included, use:

log_csv_row(filename, col1, col2, col3, ...)
  • filename: full path and file name (same as above)

  • col1, col2, ...: values to log (can be strings, numbers, or variables)

  • Supports up to 20 columns per row

  • Uses the * character as a column separator

You can also use this function in the Before Start section to write the CSV header:

log_csv_row(filename, "Torque OK", "Angle Reached")

 

Example

In a Screwdriving program, you might want to log:

  • Whether the torque was reached

  • The angle reached during the fastening process

log_csv_row("/programs/log.csv", torque_ok, final_angle)

The resulting log.csv file would look like:

Torque OK*Angle Reached
true*68.5
false*52.7

 

Conclusion

Logging to a .csv file is a simple and powerful way to track variable data on your UR robot. For best results, use the provided log_csv_row function along with a consistent separator character. Don't forget to include logging_main.script in your program setup.