Waveforms
In this section, we will modify the application to generate the ReferencePosition signal as a waveform instead of a constant.
The waveforms are implemented using the WaveformGAM.
The GAM allows generating three types of waveforms:
WaveformSin, for sinusoidal waveforms.
WaveformChirp, for waveforms where the frequency varies over time.
WaveformPointsDef, for waveforms defined by a set of points. The points are defined as a list of time-value pairs, where the time is relative to the start of the waveform and the value is the value of the signal at that time. The values between the defined points are computed by linear interpolation. The waveform is periodically repeated when the time is greater than the duration of the waveform.
In this example, the WaveformGAM is used to slowly modify the ReferencePosition as shown in the following figure.
Reference position ramp.
1 +GAMReferenceWaveform = {
2 Class = WaveformGAM::WaveformPointsDef
3 Times = {0.00 5.00 10.00}
4 Points = {0.00 2.00 0.00}
5 InputSignals = {
6 Time = {
7 DataSource = DDB1
8 Type = uint32
9 }
10 }
11 OutputSignals = {
12 ReferencePosition = {
13 DataSource = DDB1
14 Type = float64
15 Default = 2.0
16 }
17 }
18 }
Note
The WaveformGAM is an example of how to instantiate classes with a name different from the library name, as described here.
Running the application
Start the application with:
./MARTeApp.sh -f ../Configurations/MassSpring/RTApp-MassSpring-11.cfg -l RealTimeLoader -s State1
Once the application is running, inspect the screen output and verify that the log shows the ReferencePosition value varying as a function of time. The log should show entries similar to the following:
$ [Information - LoggerBroker.cpp:152]: Time [0:0]:1040000
$ [Information - LoggerBroker.cpp:152]: ReferencePosition [0:0]:0.416000
$ [Information - LoggerBroker.cpp:152]: Position [0:0]:0.354657
Exercises
Ex. 1: Modify the waveform
Edit the file
../Configurations/MassSpring/RTApp-MassSpring-12.cfgand modify the existingGAMReferenceWaveformto implement the following figure.
Reference position square wave.
Solution
The solution is to modify the GAMReferenceWaveform and add points near the transition regions so that the change is as sharp as possible.
1 +GAMReferenceWaveform = {
2 Class = WaveformGAM::WaveformPointsDef
3 Times = {0.00 4.99 5.00 9.99 10.00}
4 Points = {0.00 0.00 2.00 2.00 0.00}
5 InputSignals = {
6 Time = {
7 DataSource = DDB1
8 Type = uint32
9 }
10 }
11 OutputSignals = {
12 ReferencePosition = {
13 DataSource = DDB1
14 Type = float64
15 Default = 2.0
16 }
17 }
18 }
Ex. 2: Add a disturbance to the system
Edit the file
../Configurations/MassSpring/RTApp-MassSpring-13.cfgand add a disturbance to thePositionsignal before it enters the controller. The disturbance should be a sinusoidal signal with an amplitude of0.01and a frequency of 10 Hz.
Solution
The solution is to add a WaveformSin to generate the disturbed PositionDisturbance signal.
1 +GAMDisturbanceWaveform = {
2 Class = WaveformGAM::WaveformSin
3 Offset = 0.0
4 Phase = 0.0
5 Amplitude = 0.01
6 Frequency = 10.0
7 InputSignals = {
8 Time = {
9 DataSource = DDB1
10 Type = uint32
11 }
12 }
13 OutputSignals = {
14 PositionDisturbance = {
15 DataSource = DDB1
16 Type = float64
17 }
18 }
19 }
The PositionDisturbance signal should then be added to the Position before it enters the controller.
Position. 1 +GAMMathDisturbance = {
2 Class = MathExpressionGAM
3 Expression = "PositionDisturbed = Position + PositionDisturbance;"
4 InputSignals = {
5 Position = {
6 DataSource = DDB1
7 Type = float64
8 }
9 PositionDisturbance = {
10 DataSource = DDB1
11 Type = float64
12 }
13 }
14 OutputSignals = {
15 PositionDisturbed = {
16 DataSource = DDB1
17 Type = float64
18 }
19 }
20 }
Modify the GAMController to use the disturbed signal instead of the original Position signal.
1 +GAMController = {
2 Class = PIDGAM
3 Kp = 22.0
4 Ki = 40.0
5 Kd = 12.3
6
7 SampleTime = 0.01
8 MaxOutput = 30
9 MinOutput = -30
10 InputSignals = {
11 ReferencePosition = {
12 DataSource = DDB1
13 Type = float64
14 NumberOfDimensions = 1
15 NumberOfElements = 1
16 }
17 PositionDisturbed = {
18 DataSource = DDB1
19 Type = float64
20 NumberOfDimensions = 1
21 NumberOfElements = 1
22 }
23 }
24 OutputSignals = {
25 Force = {
26 DataSource = DDB1
27 Type = float64
28 NumberOfDimensions = 1
29 NumberOfElements = 1
30 }
31 }
32 }
Make sure that the GAMs are added to the execution list and that the new signals are added to the GAMDisplay for monitoring.
Note that the disturbance causes the system to oscillate around the reference position, and the controller tries to compensate for the disturbance to keep the position close to the reference.