Generated Code and Simulation with xPC Target

Comparision of two different Matlab compiler outputs and Simulink

D. Clark

02-May-2008 16:40:38


Table of Contents

1. Introduction
2. Data Sources
3. Testing Procedure
4. Code for Data Display
5. Data Figures
Command Signal Path
Feedback Signal Path
DAC Output Path
6. Conclusion

List of Tables

2.1. Data files in archive for this report

Chapter 1. Introduction

Recent testing by myself and Keith Powell has led to the discovery that the controller as constituted in the deployed VxWorks mount computer and that obtained by running the xPC Target test controller has a major instability in the controller whenever disturbance decoupling is enabled. While simulation and hardware-in-the-loop testing with xPC Target agree that the servo goes unstable, we were at a loss to explain why this should work when deployed on the VxWorks mount computer. To eliminate code-generation issues on the Windows development side with xPC Target as the problem source, a version of the controller was built using two different Windows hosts, one using Visual Studio 2003 as a compiler, and the other using Visual Studio 2005. The following documents the differences between simulation results on the host as the two Real Time Workshop generated xPC Target applications. Analysis of the difference between the results of a Simulink session and the outputs from generated code running on the xPC test machine may tell us where the fault lies.

For all tests, the disturbance decoupling signal was fixed at zero, and the variable integral gain in the position loop PID was fixed at 10 to eliminate the nonlinear controller components for simplicity.

Chapter 2. Data Sources

Source files for the data and models referenced in this report are in the table below:

 

Table 2.1. Data files in archive for this report

ModelDataM-file
testCodeGen_vxmode9b.mdlxpcsim_all.matcheck_codegen.m


Chapter 3. Testing Procedure

The link below documents the Simulink controller diagram used for this series of tests in exhaustive detail. It runs all the normal xPC Target test code, including the UDP communications for i/o to a Java GUI normally used to command slewing and tracking on the telescope during testing. The only real difference between this controller and one used to drive the hardware is that the DAC output and encoder feedback have been routed instead to an LTI model object for real-time simulation of the controller behavior. Simply renaming the i/o tags in the diagram is all that is required to run the hardware-in-the-loop version of the controller. As mentioned above, the nonlinear integral gain and disturbance decoupling path have been turned off. Model for testing

The controller supports four different kinds of tests, in both closed and open loop form. This allows the controller to be exercised under all the standard control engineering i/o pairs (e.g. command path to position response). In addition, if the Java GUI is used to command a track at constant velocity, the controller gets a simulated wind disturbance applied to explore the wind-rejection properties of the controller. All data presented below is in the test order shown in the list.

  1. Closed-loop command path
  2. Closed-loop disturbance rejection
  3. Open-loop passed direct to DAC
  4. Open-loop passed through controller PID

We use the normal xPC Target signal logging points to log all signals of interest during execution on the target. For simulation, a "To Workspace" block with a signal mux passes a selected subset of the signals to the Matlab workspace after a simulation pass completes. When the controller is built into an xPC Target executable, the "To Workspace" block is non-functional. Using the the target signal logging and the workspace array allows direct one-to-one comparison of the signals in the controller.

Chapter 4. Code for Data Display

Running the reduction m-file check_codegen runs the code reproduced below for data visualization of the data comparisons, provided the data mat-file has been loaded into the workspace.

%Compare simulation of testCodeGen_vxmode9b(b) on rotpunkt (Visual Studio
%2005 compiler) and skidmark (Visual Studio 2003 compiler) with generated
%code running on brunel. Generated code closes the loop on NewElss3 model.

%First, create arrays of the To Workspace data from simulation and xpc
%logging points

%First, compare the test signal 
%%
SimTestSignal = [modelsim_tm1(:,8) modelsim_tm2(:,8) modelsim_tm3(:,8)...
    modelsim_tm4(:,8)];
xpc_rot = [xpcsim_tm1(:,15) xpcsim_tm2(:,15) xpcsim_tm3(:,15)...
    xpcsim_tm4(:,15)];
xpc_bru = [xpcsim2_tm1(:,15) xpcsim2_tm2(:,15) xpcsim2_tm3(:,15)...
    xpcsim2_tm4(:,15)];

time = (1:length(SimTestSignal(:,1)))*0.001;
%plot!
sta = 1e5; sto = sta + 1e3;
%%
for k = 1:4
    figure(k); subplot(2,1,1); 
    plot(time(sta:sto),SimTestSignal(sta:sto,k),'b'); hold on; grid on;
    axis 'tight'; 
    plot(time(sta:sto),xpc_rot(sta:sto,k),'r');
    plot(time(sta:sto),xpc_bru(sta:sto,k),'g');
    legend('Simulink','RTgenVS2005','RTgenVS2003');
    title('1s of the Test Signal: Simulation & Real Time Code');
    subplot(2,1,2);
    plot(time(sta:sto),(SimTestSignal(sta:sto,k) - xpc_rot(sta:sto,k)),'.r');
    hold on; grid on; axis 'tight';
    plot(time(sta:sto),(SimTestSignal(sta:sto,k) - xpc_bru(sta:sto,k)),'b');
    legend('Sim - VS2005','Sim - VS2003');
    title('Delta on Test Signal: Simulation & Real Time Code');
end
%--------------------------------------------------------------------------

%Next, feedback signal
%%
SimFdbk = [modelsim_tm1(:,2) modelsim_tm2(:,2) modelsim_tm3(:,2)...
    modelsim_tm4(:,2)];
xpc_rotfdbk = [xpcsim_tm1(:,2) xpcsim_tm2(:,2) xpcsim_tm3(:,2)...
    xpcsim_tm4(:,2)];
xpc_brufdbk = [xpcsim2_tm1(:,2) xpcsim2_tm2(:,2) xpcsim2_tm3(:,2)...
    xpcsim2_tm4(:,2)];

%plot!
%%
for k = 1:4
    figure(k+4); subplot(2,1,1); 
    plot(time(sta:sto),SimFdbk(sta:sto,k),'b'); hold on; grid on;
    axis 'tight'; 
    plot(time(sta:sto),xpc_rotfdbk(sta:sto,k),'r');
    plot(time(sta:sto),xpc_brufdbk(sta:sto,k),'g');
    legend('Simulink','RTgenVS2005','RTgenVS2003');
    title('1s of Feedback Signal: Simulation & Real Time Code');
    subplot(2,1,2);
    plot(time(sta:sto),(SimFdbk(sta:sto,k) - xpc_rotfdbk(sta:sto,k)),'.r');
    hold on; grid on; axis 'tight';
    plot(time(sta:sto),(SimFdbk(sta:sto,k) - xpc_brufdbk(sta:sto,k)),'b');
    legend('Sim - VS2005','Sim - VS2003');
    title('Delta on Feedback Signal: Simulation & Real Time Code');
end
%--------------------------------------------------------------------------

%Finally, DAC signal
%%
SimDac = [modelsim_tm1(:,5) modelsim_tm2(:,5) modelsim_tm3(:,5)...
    modelsim_tm4(:,5)];
xpc_rotdac = [xpcsim_tm1(:,1) xpcsim_tm2(:,1) xpcsim_tm3(:,1)...
    xpcsim_tm4(:,1)];
xpc_brudac = [xpcsim2_tm1(:,1) xpcsim2_tm2(:,1) xpcsim2_tm3(:,1)...
    xpcsim2_tm4(:,1)];

%plot!
%%
for k = 1:4
    figure(k+8); subplot(2,1,1); 
    plot(time(sta:sto),SimDac(sta:sto,k),'b'); hold on; grid on;
    axis 'tight'; 
    plot(time(sta:sto),xpc_rotdac(sta:sto,k),'r');
    plot(time(sta:sto),xpc_brudac(sta:sto,k),'g');
    legend('Simulink','RTgenVS2005','RTgenVS2003');
    title('1s of DAC Signal: Simulation & Real Time Code');
    subplot(2,1,2);
    plot(time(sta:sto),(SimDac(sta:sto,k) - xpc_rotdac(sta:sto,k)),'.r');
    hold on; grid on; axis 'tight';
    plot(time(sta:sto),(SimDac(sta:sto,k) - xpc_brudac(sta:sto,k)),'b');
    legend('Sim - VS2005','Sim - VS2003');
    title('Delta on DAC Signal: Simulation & Real Time Code');
end

Chapter 5. Data Figures

For each of the four possible tests mentioned above, the data with both real time and simulation was collected and reduced to the figures below. In each case, only 1s of data is displayed for clarity in the top graph, and the difference between the simulation output and the generated code over the same interval is plotted in the bottom graph. While there are many more signals logged in the course of the testing, it is sufficient to only show the command, feedback, and DAC signals, as the differences all end up being very small, so no further investigation is considered necessary.

Command Signal Path

First, the command signal is compared in the figure snapshots below. Note that all the signal plots lie on top of each other, so the different line colors are indistinguishable; the deltas are plotted with dots and lines for clarity, they also overlay each other.

Feedback Signal Path

Next, we have the feedback signal based on the sum of a fixed constant value simulating the absolute encoder and the telescope model output.

DAC Output Path

Finally, the DAC torque command signal is presented.

Chapter 6. Conclusion

As can be seen, the differences between generated code from both possible Windows compilers and simulation output are very small in all cases. We can then safely say that code generation on the Windows side is not currently suspected as the cause of the implementation problems in running disturbance decoupling on the xPC Target controller. It is critical, however, that we get disturbance decoupling working in any case.

The current plan is to a) develop and improved linear controller PID gain set, b) Do some optimization of the 6Hz notch filter, which currently is slightly decentered from the measured structural resonant peak, and c) rebuild the disturbance decoupling loop with an observer that is rigid-body only, eliminating all filters in the disturbance estimation loop, and then d) test the improved controller with the xPC Target test system to confirm the design works as expected. Once this is completed, we will want to ensure that the test controller and the deployed VxWorks controller operate in the same manner.