/**
   * The constructor.
   *
   * @param logFileName The experiment log file to analyze.
   * @param samplingInterval The interval at which to calculate the heading error in milliseconds.
   * @param saveToFile whether to save the error calculations to a file.
   */
  public VisualizeHeadingError(String logFileName, long samplingInterval, boolean saveToFile) {
    this.logFileName = logFileName;
    robotData = new RobotExpData(logFileName);

    long startTime = robotData.getExpStartTime();

    // Calculate heading divergence every sampling interval
    for (long time = startTime; time < robotData.getExpStopTime(); time += samplingInterval) {

      // Only do the calculation if the robot has started to move.
      if (time >= robotData.getPathEdge(0).getStartTime())
        divergenceData.add(getHeadingError(time));
    }

    if (saveToFile) saveToFile();
    showPlot();
  }