Filters and type conversion

The last exercise in the previous section introduced a disturbance to the system.

In this section, we will add a filter before the controller to mitigate the effect of the disturbance.

The filter is implemented using the FilterGAM, and is configured as a notch filter centred at 10 Hz.

FilterGAM configuration.
 1        +GAMFilterDisturbance = {
 2            Class = FilterGAM
 3            Num = {0.9565450850 -1.5477224593 0.9565450850}
 4            Den = {1.0 -1.5371322893 0.9025000000} 
 5 
 6            InputSignals = {
 7                PositionDisturbed = {
 8                    NumberOfElements = 1
 9                    NumberOfDimensions = 1
10                    DataSource = DDB1
11                    Type = float64
12                }
13            }
14            OutputSignals = {
15                PositionFiltered = {
16                    DataSource = DDB1
17                    Type = float64
18                    NumberOfElements = 1
19                    NumberOfDimensions = 1
20                }
21            }
22        }

Running the application

Start the application with:

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

Once the application is running, inspect the screen output and verify that the log shows the Position converging to the ReferencePosition value despite the PositionDisturbed signal (which is the input to the filter) varying over time. The log should show entries similar to the following:

$ [Information - LoggerBroker.cpp:152]: Time [0:0]:151070000
$ [Information - LoggerBroker.cpp:152]: ReferencePosition [0:0]:2.000000
$ [Information - LoggerBroker.cpp:152]: Position [0:0]:2.000000
$ [Information - LoggerBroker.cpp:152]: PositionDisturbed [0:0]:1.990489
$ [Information - LoggerBroker.cpp:152]: PositionFiltered [0:0]:2.000000

Exercises

Ex. 1: Simple statistics

  1. Edit the file ../Configurations/MassSpring/RTApp-MassSpring-15.cfg and add a FilterGAM to implement a moving average of the Thread1CycleTime and compare it with the one being computed by the StatisticsGAM. The moving average should be computed over a window of 100 ms.

  2. Given that the FilterGAM does not accept uint32 signals, use a ConversionGAM to convert the Thread1CycleTime signal to a float32 before feeding it to the FilterGAM.

Solution

The solution is to add a ConversionGAM to convert the signal.

Type conversion.
 1        +GAMConversion = {
 2            Class = ConversionGAM
 3            InputSignals = {
 4                Thread1CycleTime = {
 5                    DataSource = DDB1
 6                    Type = uint32
 7                }
 8            }
 9            OutputSignals = {
10                Thread1CycleTimeF32 = {
11                    DataSource = DDB1
12                    Type = float32
13                }
14            }
15        }

And to add a FilterGAM to compute the moving average.

Moving average filter.
 1        +GAMFilterMovingAvg = {
 2            Class = FilterGAM
 3            Num = {0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1}
 4            Den = {1.0} 
 5 
 6            InputSignals = {
 7                Thread1CycleTimeF32 = {
 8                    DataSource = DDB1
 9                    Type = float32
10                    NumberOfDimensions = 1
11                    NumberOfElements = 1
12                }
13            }
14            OutputSignals = {
15                Thread1CycleTimeMovingAverage = {
16                    DataSource = DDB1
17                    Type = float32
18                    NumberOfDimensions = 1
19                    NumberOfElements = 1
20                }

Finally, add the output signal of the FilterGAM to the GAMDisplay and the GAMs to the execution list.