1
/*
2
* File: ActuatorLoop.c
3
*
4
* Code generated for Simulink model 'ActuatorLoop'.
5
*
6
* Model version : 1.45
7
* Simulink Coder version : 9.2 (R2019b) 18-Jul-2019
8
* C/C++ source code generated on : Wed May 13 13:52:25 2020
9
*
10
* Target selection: ert.tlc
11
* Embedded hardware selection: Intel->x86-32 (Windows32)
12
* Code generation objectives: Unspecified
13
* Validation result: Not run
14
*/
15
16
#include "ActuatorLoop.h"
17
18
/* Disable for referenced model: 'ActuatorLoop' */
19
void
ActuatorLoop_Disable
(
B_ActuatorLoop_caua_T
*
localB
,
DW_ActuatorLoop_fwu4_T
*
20
localDW
)
21
{
22
/* Disable for DiscreteIntegrator: '
<Root>/Integrator
'
23
*
24
* Block requirements for '
<Root>/Integrator
':
25
*
1. HLR_4: Hydraulic Actuator Loop Control (HelicopterSoftwareRequirements#8)
26
*/
27
localDW
->
Integrator_DSTATE
=
localB
->
Integrator
;
28
}
29
30
/* Output and update for referenced model: 'ActuatorLoop' */
31
void
ActuatorLoop
(
const
int16_T
*
rtu_PositionFeedback
,
const
real_T
32
*
rtu_PositionCommand
,
int16_T
*
rty_ActuatorCommand
,
33
B_ActuatorLoop_caua_T
*
localB
,
DW_ActuatorLoop_fwu4_T
*
localDW
,
34
real_T
rtp_Kp
,
real_T
rtp_Kd
,
real_T
rtp_Ki
)
35
{
36
real_T
rtb_Sum
;
37
real_T
y
;
38
real_T
u0
;
39
40
/* Sum: '
<Root>/Sum
' incorporates:
41
* DataTypeConversion: '
<Root>/TypeConversion
'
42
* Gain: '
<Root>/Scaling
'
43
*
44
* Block requirements for '
<Root>/Sum
':
45
*
1. HLR_4: Hydraulic Actuator Loop Control (HelicopterSoftwareRequirements#8)
46
*
47
* Block requirements for '
<Root>/TypeConversion
':
48
*
1. HLR_2 : Hydraulic Actuator Feedback (HelicopterSoftwareRequirements#6)
49
*
50
* Block requirements for '
<Root>/Scaling
':
51
*
1. HLR_2 : Hydraulic Actuator Feedback (HelicopterSoftwareRequirements#6)
52
*/
53
rtb_Sum
= (
*
rtu_PositionCommand
)
-
(3.0518509475997192E-6
*
((
real_T
)
54
(
*
rtu_PositionFeedback
)));
55
56
/* DiscreteIntegrator: '
<Root>/Integrator
'
57
*
58
* Block requirements for '
<Root>/Integrator
':
59
*
1. HLR_4: Hydraulic Actuator Loop Control (HelicopterSoftwareRequirements#8)
60
*/
61
localB
->
Integrator
=
localDW
->
Integrator_DSTATE
;
62
63
/* Sum: '
<Root>/Sum1
' incorporates:
64
* Gain: '
<Root>/Gain
'
65
* Gain: '
<Root>/Gain1
'
66
* Sum: '
<S1>/Diff
'
67
* UnitDelay: '
<S1>/UD
'
68
*
69
* Block requirements for '
<Root>/Sum1
':
70
*
1. HLR_4: Hydraulic Actuator Loop Control (HelicopterSoftwareRequirements#8)
71
*
72
* Block requirements for '
<Root>/Gain
':
73
*
1. HLR_4: Hydraulic Actuator Loop Control (HelicopterSoftwareRequirements#8)
74
*
75
* Block requirements for '
<Root>/Gain1
':
76
*
1. HLR_4: Hydraulic Actuator Loop Control (HelicopterSoftwareRequirements#8)
77
*/
78
u0
= (
localB
->
Integrator
+
(
rtp_Kp
*
rtb_Sum
))
-
(
rtp_Kd
*
(
rtb_Sum
-
79
localDW
->
UD_DSTATE
));
80
81
/* Saturate: '
<Root>/Saturation
'
82
*
83
* Block requirements for '
<Root>/Saturation
':
84
*
1. HLR_4: Hydraulic Actuator Loop Control (HelicopterSoftwareRequirements#8)
85
*/
86
if
(
u0
>
0.3)
{
87
y
= 0.3;
88
}
else
if
(
u0
<
(
-
0.3))
{
89
y
= (
-
0.3);
90
}
else
{
91
y
=
u0
;
92
}
93
94
/* End of Saturate: '
<Root>/Saturation
' */
95
96
/* DataTypeConversion: '
<Root>/TypeConversion6
' incorporates:
97
* Gain: '
<Root>/Scaling6
'
98
*
99
* Block requirements for '
<Root>/TypeConversion6
':
100
*
1. HLR_3: Hydraulic Actuator Drive (HelicopterSoftwareRequirements#7)
101
*
102
* Block requirements for '
<Root>/Scaling6
':
103
*
1. HLR_3: Hydraulic Actuator Drive (HelicopterSoftwareRequirements#7)
104
*/
105
*
rty_ActuatorCommand
= (
int16_T
)
floor
(109223.33333333334
*
y
);
106
107
/* Update for UnitDelay: '
<S1>/UD
' */
108
localDW
->
UD_DSTATE
=
rtb_Sum
;
109
110
/* Update for DiscreteIntegrator: '
<Root>/Integrator
' incorporates:
111
* Gain: '
<Root>/Gain2
'
112
*
113
* Block requirements for '
<Root>/Integrator
':
114
*
1. HLR_4: Hydraulic Actuator Loop Control (HelicopterSoftwareRequirements#8)
115
*
116
* Block requirements for '
<Root>/Gain2
':
117
*
1. HLR_4: Hydraulic Actuator Loop Control (HelicopterSoftwareRequirements#8)
118
*/
119
localDW
->
Integrator_DSTATE
=
localDW
->
Integrator_DSTATE
+
(0.001
*
(
rtp_Ki
*
120
rtb_Sum
));
121
if
(
localDW
->
Integrator_DSTATE
>=
0.1)
{
122
localDW
->
Integrator_DSTATE
= 0.1;
123
}
else
{
124
if
(
localDW
->
Integrator_DSTATE
<=
(
-
0.1))
{
125
localDW
->
Integrator_DSTATE
= (
-
0.1);
126
}
127
}
128
129
/* End of Update for DiscreteIntegrator: '
<Root>/Integrator
' */
130
}
131
132
/* Model initialize function */
133
void
ActuatorLoop_initialize
(
B_ActuatorLoop_caua_T
*
localB
,
134
DW_ActuatorLoop_fwu4_T
*
localDW
)
135
{
136
/* Registration code */
137
138
/* block I/O */
139
{
140
localB
->
Integrator
= 0.0;
141
}
142
143
/* states (dwork) */
144
localDW
->
UD_DSTATE
= 0.0;
145
localDW
->
Integrator_DSTATE
= 0.0;
146
}
147
148
/*
149
* File trailer for generated code.
150
*
151
* [EOF]
152
*/
153