User Tools

Site Tools


tools:logger_trace:start

This is an old revision of the document!


Logging with a Trace Block

When working with realtime applications you have to be careful when logging. The formatting of any output into an output stream takes time and usually cannot be done with the full speed of the control system or the safety system. However, when debugging a intricate control algorithm it might be desirable to study various signal values together with their timestamps as they are calculated in the control system.

For this purpose you can place Trace blocks and log any signal into its internal ring buffer. The following example can be found under examples/controlSystem/traceTest. It has a simple control system with two trace blocks, each having a ring buffer lenght of 64.

  class ControlSystem {
  public:
    ControlSystem() : c(0.1), trace1(64), trace2(64) {
      i.getIn().connect(c.getOut());
      i.setInitCondition(Vector3{0, 1.0, 2.0});
      i.enable();
      trace1.getIn().connect(c.getOut());
      trace2.getIn().connect(i.getOut());
      trace1.enable();
      trace2.enable();
    }
 
    Constant<Vector3> c;
    I<Vector3> i;
    Trace<Vector3> trace1, trace2;
  };

An application can now run this control system. After stopping the executor you can output the content of the trace blocks onto any output stream, e.g. into a file.

  log.info() << "start writing file";
  std::ofstream file;
  file.open("/tmp/ctrlData.txt", std::ios::trunc);
  timestamp_t* timeStampBuf = controlSystem.trace1.getTimestampTrace();
  Vector3* buf1 = controlSystem.trace1.getTrace();
  Vector3* buf2 = controlSystem.trace2.getTrace();
  for (int i = 0; i < controlSystem.trace1.getSize(); i++) file << timeStampBuf[i] << " " << buf1[i] << " " << buf2[i] << std::endl;
  file.close();
  log.info() << "file written";

Enabling and Disabling

A trace block, though it will run by the control system, has to be enabled. If so, it will contineously fill its trace buffer until it is disabled. This allows for tracing a given stream of signals. You could start tracing as soon as the safety system enters a certain safety level. You do this by starting the trace in the safety level action, see Safety Properties

tools/logger_trace/start.1515752189.txt.gz · Last modified: 2018/01/12 11:16 (external edit)