This example shows a physical system model and controller configured for HIL testing. It is derived from example Hydraulic Actuator with Digital Position Controller, ssc_hydraulic_actuator_digital_control. The model has been configured for HIL testing by performing the following steps:
1. Make the controller discrete time: The Transport Delay block is replaced by a Unit Delay block. This represents the worst case delay whereby it takes a full computational frame time for the controller output u to be updated based on current input values for r and y. Zero-Order Hold blocks are added to all analog measurements (ZOHr and ZOHy) to represent digital sampling of continuous time measurements. The controller itself must be made discrete time, so the continuous time first order filter converted to a discrete time filter using a Tustin transformation. In this example the discrete sample time is made a parameter, the advantage of this being that it can be easily adjusted if necessary to ensure the controller calculations do not cause a frame time overrun.
2. Partition each HIL component into its own subsystem. The hydraulic plant is already in its own subsystem, so we just need to group the controller into its own subsystem. This partitioning helps if just part of the model is to be run in HIL, or controller and plant are to be run on separate HIL systems.
3. Set fixed step local solver option, setting fixed step to the controller sample time ts. Make ts as large as possible whilst retaining simulation fidelity required. Sometimes the plant may require a different sample time, typically smaller, than the controller. In this case ts=0.001 is small enough for the plant and controller. Determine how many Nonlinear iterations are required for convergence; some models may need more than the default 3.
4. Run Performance Advisor checks relating to Simscape™.
5. Review the model for any simplifications that the Performance Advisor did not find. One method is to linearize the model to look for fast eigenvalues, and then to relate these back to model components. Applying to ssc_hydraulic_actuator_digital_control reveals that dynamic compressibility in the Hydraulic Cylinder can be removed to avoid an oscillatory dynamic pole pair. This change has been made to the model.
6. Configure code generation target: see Simulink® Coder Deployment documentation
Plot "Cylinder Pressures" shows how the cylinder pressure varies during simulation. It corresponds with the opening of the valve. The opening of the valve is set by the controller so that the actuator tracks a reference signal.
Plot "Cylinder Pressure, Solver Types" shows the effect of solver type on simulation results. The variable-step simulation uses smaller simulation steps to accurately capture the system dynamics. The fixed-step simulation results are close but do not exactly match the variable-step simulation results, for the solver is not permitted to adjust its step size. The fixed-step solver settings should be adjusted until the fixed-step simulation results are within an acceptable range of the variable-step simulation results.