Skip to main content
Erschienen in:

Open Access 2025 | OriginalPaper | Buchkapitel

10. Software Implementation

verfasst von : Gernot Herbst, Rafal Madonski

Erschienen in: Active Disturbance Rejection Control

Verlag: Springer Nature Switzerland

Aktivieren Sie unsere intelligente Suche, um passende Fachinhalte oder Patente zu finden.

search-config
loading …

Abstract

The “cooking recipes” in this book shall provide guidance and encouragement for custom ADRC implementations. To demonstrate that the transition from principles to practice is immediately possible based on the results from previous chapters, we will implement discrete-time variants in software form in this chapter; both using a model-based environment and using manual C language coding.

10.1 Implementation in MATLAB/Simulink

Widely used in both industry and academia, MATLAB/Simulink 1 offers a programming and simulation environment that is particularly well-suited for design, analysis, and implementation of control systems. Later in this book, in Appendix B, we will discuss existing ADRC solutions for Simulink. In this section, however, we want to demonstrate that a custom Simulink implementation of ADRC can be created straightforwardly, and encourage readers to do so on their own.
Using the block diagrams and equations given in this book, especially in the condensed compilation of ADRC variants in Appendix A, it is a straightforward task to implement ADRC on one’s own in a model-based environment such as Simulink. We will demonstrate that by implementing the control loop from the second-order example in Sect. 5.​2, this time with the discrete-time state-space variant of ADRC introduced in Sect. 8.​1, which is summarized in condensed form in Appendix A.​5.
The model-based ADRC implementation consists of:
  • the discrete-time control law (A.​5.​1);
  • the discrete-time observer (A.​5.​2) derived in Sect. 8.​1;
  • a (magnitude) limitation of the controller output signal discussed in Sect. 9.​1, including the simple but effective windup protection provided by feeding the limited controller output back into the observer.
Listing 10.1 MATLAB initialization code for the ADRC implementation in Fig. 10.1
https://static-content.springer.com/image/chp%3A10.1007%2F978-3-031-72687-3_10/MediaObjects/617308_1_En_10_Figaaa_HTML.png
As can be seen from Fig. 10.1, the resulting ADRC block is a direct replication of Fig. A.​5.​1. The saturation block must be parameterized with the allowed output range of the control signal (umin and umax). The scalar, vector, and matrix gain blocks are making use of variables b0 (scalar, critical gain parameter b0 to be obtained from plant modeling), K (row vector containing the controller gains kT), L (column vector of observer gains l), A_ESO (system matrix AESO of the observer), and B_ESO (column vector, input gain bESO of the observer).
The initialization script required to set up the necessary matrices and vectors from ADRC’s tuning parameters is given in Listing 10.​1. User-defined values are the critical gain parameter b0, the two bandwidth tuning parameters ωCL and kESO, and the sampling interval Ts. Controller and observer gains kT and l as well as the observer matrix/vector AESO and bESO are then automatically being computed exactly as given in Tables A.​5.​1 and A.​5.​2 for the order N = 2.

10.2 Implementation in C Programming Language

A second important option for implementing discrete-time ADRC is to manually write source code. Here, we will make use of the C programming language, the lingua franca of embedded systems, which allows to target practically every available processor or microcontroller platform.

10.2.1 State-Space Form

As a first example, we want to demonstrate how the discrete-time state-space form of ADRC, summarized in Appendix A.​5, can be implemented in C source code, and also pay attention to practical aspects discussed in Chap. 9. A possible implementation of ADRC structure as shown in Fig. A.​5.​1 for N = 1 comprises the following steps.
Data Structure: We begin with the declaration of a data structure holding controller parameters and internal state variables. Inspection of (A.​5.​1) and (A.​5.​2) for N = 1 reveals that we need two state variables (for \(\hat {x}_1\) and \(\hat {x}_2\)), and ten coefficients (controller and observer gains, b0, observer matrix/vector elements). We will do that with one single struct as shown in Listing 10.​2, also including parameters for limiting the controller output. A user will then have to instantiate this struct, and pass the instance to further C functions implemented below. A more refined approach separating coefficients and state variables would, of course, also be possible.
Listing 10.2 Discrete-time state-space implementation of first-order ADRC: definition of a combined data structure to hold controller parameters and states
https://static-content.springer.com/image/chp%3A10.1007%2F978-3-031-72687-3_10/MediaObjects/617308_1_En_10_Figaab_HTML.png
Parameter Tuning: Controller and observer gains can be obtained using bandwidth parameterization, as given in Table A.​5.​1. Based on that, the observer matrix/vector elements can be computed as listed in Table A.​5.​2. We therefore implement a C function that computes the coefficients based on tuning values ωCL, kESO, as well as b0 and Ts. Comparing the resulting Listing 10.​3 with these tables confirms that the given equations can indeed be transformed into C source in a rather straightforward manner.
Listing 10.3 Discrete-time state-space implementation of first-order ADRC: initialize coefficient values using bandwidth parameterization
https://static-content.springer.com/image/chp%3A10.1007%2F978-3-031-72687-3_10/MediaObjects/617308_1_En_10_Figaac_HTML.png
Control Law and Observer Update: To understand the implementation of the control law, we have redrawn Fig. A.​5.​1 for N = 1 in Fig. 10.2, introducing required state variables (x1 and x2). To abbreviate the resulting code, some intermediate variables (named f1 and f2 here) were introduced. These are the values fed back through the state-feedback control law, and also needed to update the state variables, i. e. the storage variables of the unit delay. Figure 10.2 links all required source code lines with their origin in the block diagram. As discussed in Sect. 9.​1, every practical controller should limit its output and be equipped with anti-windup measures. We therefore added an output magnitude limitation to the controller, which was already apparent from the block diagram. The resulting C function for computing a new, limited controller output value can be found in Listing 10.​4.
Listing 10.4 Discrete-time state-space implementation of first-order ADRC: compute new limited controller output value and update internal states
https://static-content.springer.com/image/chp%3A10.1007%2F978-3-031-72687-3_10/MediaObjects/617308_1_En_10_Figaad_HTML.png
Customization: To add the ability to enable the controller from non-zero initial conditions for y and/or u, we implement the direct initialization strategy covered in Sect. 9.​2 to ensure bumpless transfer. The resulting function is shown in Listing 10.​5.
Listing 10.5 Discrete-time state-space implementation of first-order ADRC: initialize internal states for bumpless transfer from manual mode in a settled state r = y, cf. Sect. 9.​2
https://static-content.springer.com/image/chp%3A10.1007%2F978-3-031-72687-3_10/MediaObjects/617308_1_En_10_Figaae_HTML.png
This concludes our example implementation of first-order discrete-time ADRC in its state-space form. A user of this implementation will have to:
  • instantiate the data structure from Listing 10.​2;
  • initialize the coefficients (“tune the controller”) by calling the function in Listing 10.​3;
  • initialize the internal state variables before being able to bumplessly enable the controller using the function from Listing 10.​5;
  • and, periodically (once every Ts), call the update function in Listing 10.​4 to compute the next controller output from the most recently measured plant output, before feeding the controller output to the actuator of the user’s application.

10.2.2 Dual-Feedback Transfer Function Form

In a second example, we want to demonstrate how a transfer function variant of ADRC can be transferred from its block diagram to C source code. We pick the dual-feedback transfer function form in its minimum-footprint realization given in Fig. A.​7.​2 for N = 1, and implement it with the following steps.
Data Structure: By inspection of Fig. A.​7.​2 it becomes apparent that two state variables (for the two unit delay blocks) and seven coefficients are needed. Similar to the previous example, we will declare one single struct for parameters and internal state variables. The result is shown in Listing 10.​6, also including parameters for the controller output limitation.
Listing 10.6 Discrete-time dual-feedback transfer function implementation of first-order ADRC: definition of a combined data structure to hold controller parameters and states
https://static-content.springer.com/image/chp%3A10.1007%2F978-3-031-72687-3_10/MediaObjects/617308_1_En_10_Figaaf_HTML.png
Parameter Tuning: The transfer function coefficient values can be obtained using bandwidth parameterization, as given in Table A.​7.​2. The C function in Listing 10.​7 computes these coefficients based on tuning values ωCL, kESO, as well as b0 and Ts. Once more, a comparison with Table A.​7.​2 reveals that the given equations can easily be transformed into C source code.
Listing 10.7 Discrete-time dual-feedback transfer function implementation of first-order ADRC: initialize coefficient values using bandwidth parameterization
https://static-content.springer.com/image/chp%3A10.1007%2F978-3-031-72687-3_10/MediaObjects/617308_1_En_10_Figaag_HTML.png
Control Law: To implement the actual control law, one has to go over Fig. A.​7.​2 from top to bottom. This includes updating the two state variables (of the unit delay blocks), which we will name x1 and x2. It is also useful to introduce an intermediate variable—named f here—which is being fed back through the α coefficients. To better support understanding the process of translating a block diagram to a programming language, Fig. 10.3 shows the block diagram annotated with C source code lines. A magnitude limitation was added to the controller output. The resulting C function for computing the controller output value is given in Listing 10.​8.
Listing 10.8 Discrete-time dual-feedback transfer function implementation of first-order ADRC: compute new limited controller output value and update internal states, as shown in Fig. 10.3
https://static-content.springer.com/image/chp%3A10.1007%2F978-3-031-72687-3_10/MediaObjects/617308_1_En_10_Figaah_HTML.png
Customization: To bumplessly enable the controller from non-zero initial conditions for y and/or u, the direct initialization strategy from Sect. 9.​2 is applied here, as well, resulting in Listing 10.​9.
Listing 10.9 Discrete-time dual-feedback transfer function implementation of first-order ADRC: initialize internal states for bumpless transfer from manual mode
https://static-content.springer.com/image/chp%3A10.1007%2F978-3-031-72687-3_10/MediaObjects/617308_1_En_10_Figaai_HTML.png
This concludes our implementation. From a user’s perspective, this implementation is to be treated in exactly the same manner as the state-space form covered in Sect. 10.2.1. Using these functions requires:
  • instantiating the data structure from Listing 10.​6;
  • initializing the coefficients (= tuning the controller) by calling the function in Listing 10.​7;
  • initializing the internal state variables before being able to bumplessly enable the controller using the function from Listing 10.​9;
  • and, periodically (once per sampling interval Ts), calling the update function in Listing 10.​8 to compute the next controller output from the most recently measured plant output. The resulting controller output must then be fed to the actuator of the user’s application.
Open Access This chapter is licensed under the terms of the Creative Commons Attribution 4.0 International License (http://​creativecommons.​org/​licenses/​by/​4.​0/​), which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons license and indicate if changes were made.
The images or other third party material in this chapter are included in the chapter's Creative Commons license, unless indicated otherwise in a credit line to the material. If material is not included in the chapter's Creative Commons license and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder.
Fußnoten
1
MATLAB and Simulink are registered trademarks of The MathWorks, Inc.
 
Metadaten
Titel
Software Implementation
verfasst von
Gernot Herbst
Rafal Madonski
Copyright-Jahr
2025
DOI
https://doi.org/10.1007/978-3-031-72687-3_10