FileReader

The FileReader DataSource can be used to read data from a file and inject it into the application. This can be useful to test the application with pre-recorded data or to replay a specific scenario.

In this section, the ReferencePosition will be read from a file using the FileReader DataSource. As with the FileWriter, this DataSource can be configured to store the data in a binary or text CSV format.

FileReader configuration.
 1        +FileReader = {
 2            Class = FileReader
 3            Filename = "../Test/Integrated/MassSpring-21-Reference.csv"
 4            Interpolate = "no"
 5            FileFormat = "csv"
 6            CSVSeparator = ","
 7            XAxisSignal = "ReferenceTime"
 8            InterpolationPeriod = 10000
 9            EOF = "Rewind" 
10            Preload = "yes"
11        }

The FileReader DataSource can be configured to react in different ways to the end-of-file event. In this case, it is configured to rewind and reloop forever.

The DataSource can also be configured to interpolate the data between the samples in the file. This can be useful to test the application with a specific sampling time that is different from the one used to record the data.

In this example, the ReferencePosition is read from the file ../Test/Integrated/MassSpring-21-Reference.csv, which contains a constant value of 2.0 for the ReferencePosition signal.

Running the application

Start the application with:

./MARTeApp.sh -f ../Configurations/MassSpring/RTApp-MassSpring-21.cfg -l RealTimeLoader -s State1

Once the application is running, inspect the screen output and verify that the application is running without any issues. The log should show entries similar to the following:

$ [Warning - Threads.cpp:181]: Failed to change the thread priority (likely due to insufficient permissions)
$ [Information - RealTimeLoader.cpp:111]: Started application in state State1
$ [Information - MARTeApp.cpp:135]: Application starting
$ [Information - LoggerBroker.cpp:152]: Time [0:0]:1000000
...

Also check that the output file ../Test/Integrated/MassSpring-21.csv is being created and that the ReferencePosition is set to the constant value 2.0.

Exercises

Ex. 1: Read a ramp from the file

Modify the file ../Test/Integrated/MassSpring-22-reference.csv to include a ramp for the ReferencePosition signal as shown in the following figure.

Mass-spring-damper reference position ramp.
  1. Edit the file ../Configurations/MassSpring/RTApp-MassSpring-22.cfg and modify the FileReader to read from the ../Test/Integrated/MassSpring-22-Reference.csv file.

  2. Make sure that the FileReader interpolates the data between the samples in the file and rewinds and reloops forever.

  3. Check that the output file ../Test/Integrated/MassSpring-22.csv is being created and that the ReferencePosition is set to the expected ramp values.

./MARTeApp.sh -f ../Configurations/MassSpring/RTApp-MassSpring-22.cfg -l RealTimeLoader -s State1
Solution

The solution is to add the relevant points to the ../Test/Integrated/MassSpring-22-Reference.csv.

CSV file with ReferencePosition ramp values.
1#ReferenceTime (uint32)[1],ReferencePosition (float64)[1]
20,0.000000
35000000,2.0
410000000,2.0
515000000,0.0

Modify the FileReader DataSource to read from the new file and to interpolate the data between the samples.

Updated FileReader configuration to read the ramp values.
 1        +FileReader = {
 2            Class = FileReader
 3            Filename = "../Test/Integrated/MassSpring-22-Reference-solution.csv"
 4            Interpolate = "yes"
 5            FileFormat = "csv"
 6            CSVSeparator = ","
 7            XAxisSignal = "ReferenceTime"
 8            InterpolationPeriod = 10000
 9            EOF = "Rewind" 
10            Preload = "yes"
11        }

Verify that the output file ../Test/Integrated/MassSpring-22.csv is being created and that the ReferencePosition is set to the expected ramp values.