-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoot_Locus.c
250 lines (216 loc) · 8.29 KB
/
Root_Locus.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/*
* File: untitled.c
*
* Code generated for Simulink model 'untitled'.
*
* Model version : 1.0
* Simulink Coder version : 9.9 (R2023a) 19-Nov-2022
* C/C++ source code generated on : Thu Apr 4 22:40:40 2024
*
* Target selection: ert.tlc
* Embedded hardware selection: Atmel->AVR
* Code generation objectives: Unspecified
* Validation result: Not run
*/
#include "untitled.h"
#include "untitled_types.h"
#include "rtwtypes.h"
#include "untitled_private.h"
/* Block signals (default storage) */
B_untitled_T untitled_B;
/* Block states (default storage) */
DW_untitled_T untitled_DW;
/* Real-time model */
static RT_MODEL_untitled_T untitled_M_;
RT_MODEL_untitled_T *const untitled_M = &untitled_M_;
/* Model step function */
void untitled_step(void)
{
MW_AnalogIn_ResultDataType_Type datatype_id;
codertarget_arduinobase_int_b_T *obj_0;
codertarget_arduinobase_inter_T *obj;
real_T u0;
uint16_T b_varargout_1;
/* Step: '<Root>/Step' */
if (untitled_M->Timing.t[0] < untitled_P.Step_Time) {
/* Step: '<Root>/Step' */
untitled_B.Stepinput = untitled_P.Step_Y0;
} else {
/* Step: '<Root>/Step' */
untitled_B.Stepinput = untitled_P.Step_YFinal;
}
/* End of Step: '<Root>/Step' */
/* MATLABSystem: '<Root>/Analog Input' */
if (untitled_DW.obj.SampleTime != untitled_P.AnalogInput_SampleTime) {
untitled_DW.obj.SampleTime = untitled_P.AnalogInput_SampleTime;
}
obj = &untitled_DW.obj;
obj->AnalogInDriverObj.MW_ANALOGIN_HANDLE = MW_AnalogIn_GetHandle(14UL);
datatype_id = MW_ANALOGIN_UINT16;
MW_AnalogInSingle_ReadResult
(untitled_DW.obj.AnalogInDriverObj.MW_ANALOGIN_HANDLE, &b_varargout_1,
datatype_id);
/* Gain: '<Root>/Gain 2' incorporates:
* MATLABSystem: '<Root>/Analog Input'
*/
untitled_B.Responce = (uint32_T)untitled_P.Gain2_Gain * b_varargout_1;
/* MATLABSystem: '<Root>/PWM' */
obj_0 = &untitled_DW.obj_b;
obj_0->PWMDriverObj.MW_PWM_HANDLE = MW_PWM_GetHandle(6UL);
/* ManualSwitch: '<Root>/Manual Switch' incorporates:
* Constant: '<Root>/Constant'
*/
if (untitled_P.ManualSwitch_CurrentSetting == 1) {
u0 = untitled_B.Stepinput;
} else {
u0 = untitled_P.Constant_Value;
}
/* Gain: '<Root>/Gain 1' incorporates:
* Gain: '<Root>/Gain 2'
* Gain: '<Root>/Kp'
* ManualSwitch: '<Root>/Manual Switch'
* Sum: '<Root>/Sum'
*/
u0 = (u0 - (real_T)untitled_B.Responce * 1.1920928955078125E-7) *
untitled_P.Kp_Gain * untitled_P.Gain1_Gain;
/* MATLABSystem: '<Root>/PWM' */
if (!(u0 <= 255.0)) {
u0 = 255.0;
}
if (!(u0 >= 0.0)) {
u0 = 0.0;
}
MW_PWM_SetDutyCycle(untitled_DW.obj_b.PWMDriverObj.MW_PWM_HANDLE, u0);
{ /* Sample time: [0.0s, 0.0s] */
extmodeErrorCode_T errorCode = EXTMODE_SUCCESS;
extmodeSimulationTime_T currentTime = (extmodeSimulationTime_T)
((untitled_M->Timing.clockTick0 * 1) + 0)
;
/* Trigger External Mode event */
errorCode = extmodeEvent(0,currentTime);
if (errorCode != EXTMODE_SUCCESS) {
/* Code to handle External Mode event errors
may be added here */
}
}
{ /* Sample time: [0.001s, 0.0s] */
extmodeErrorCode_T errorCode = EXTMODE_SUCCESS;
extmodeSimulationTime_T currentTime = (extmodeSimulationTime_T)
((untitled_M->Timing.clockTick1 * 1) + 0)
;
/* Trigger External Mode event */
errorCode = extmodeEvent(1,currentTime);
if (errorCode != EXTMODE_SUCCESS) {
/* Code to handle External Mode event errors
may be added here */
}
}
/* Update absolute time for base rate */
/* The "clockTick0" counts the number of times the code of this task has
* been executed. The absolute time is the multiplication of "clockTick0"
* and "Timing.stepSize0". Size of "clockTick0" ensures timer will not
* overflow during the application lifespan selected.
*/
untitled_M->Timing.t[0] =
((time_T)(++untitled_M->Timing.clockTick0)) * untitled_M->Timing.stepSize0;
{
/* Update absolute timer for sample time: [0.001s, 0.0s] */
/* The "clockTick1" counts the number of times the code of this task has
* been executed. The resolution of this integer timer is 0.001, which is the step size
* of the task. Size of "clockTick1" ensures timer will not overflow during the
* application lifespan selected.
*/
untitled_M->Timing.clockTick1++;
}
}
/* Model initialize function */
void untitled_initialize(void)
{
/* Registration code */
{
/* Setup solver object */
rtsiSetSimTimeStepPtr(&untitled_M->solverInfo,
&untitled_M->Timing.simTimeStep);
rtsiSetTPtr(&untitled_M->solverInfo, &rtmGetTPtr(untitled_M));
rtsiSetStepSizePtr(&untitled_M->solverInfo, &untitled_M->Timing.stepSize0);
rtsiSetErrorStatusPtr(&untitled_M->solverInfo, (&rtmGetErrorStatus
(untitled_M)));
rtsiSetRTModelPtr(&untitled_M->solverInfo, untitled_M);
}
rtsiSetSimTimeStep(&untitled_M->solverInfo, MAJOR_TIME_STEP);
rtsiSetSolverName(&untitled_M->solverInfo,"FixedStepDiscrete");
rtmSetTPtr(untitled_M, &untitled_M->Timing.tArray[0]);
rtmSetTFinal(untitled_M, 50.0);
untitled_M->Timing.stepSize0 = 0.001;
/* External mode info */
untitled_M->Sizes.checksums[0] = (409332823U);
untitled_M->Sizes.checksums[1] = (3908376490U);
untitled_M->Sizes.checksums[2] = (2627478581U);
untitled_M->Sizes.checksums[3] = (3176046263U);
{
static const sysRanDType rtAlwaysEnabled = SUBSYS_RAN_BC_ENABLE;
static RTWExtModeInfo rt_ExtModeInfo;
static const sysRanDType *systemRan[3];
untitled_M->extModeInfo = (&rt_ExtModeInfo);
rteiSetSubSystemActiveVectorAddresses(&rt_ExtModeInfo, systemRan);
systemRan[0] = &rtAlwaysEnabled;
systemRan[1] = &rtAlwaysEnabled;
systemRan[2] = &rtAlwaysEnabled;
rteiSetModelMappingInfoPtr(untitled_M->extModeInfo,
&untitled_M->SpecialInfo.mappingInfo);
rteiSetChecksumsPtr(untitled_M->extModeInfo, untitled_M->Sizes.checksums);
rteiSetTPtr(untitled_M->extModeInfo, rtmGetTPtr(untitled_M));
}
{
codertarget_arduinobase_int_b_T *obj_0;
codertarget_arduinobase_inter_T *obj;
/* Start for MATLABSystem: '<Root>/Analog Input' */
untitled_DW.obj.matlabCodegenIsDeleted = false;
untitled_DW.obj.SampleTime = untitled_P.AnalogInput_SampleTime;
obj = &untitled_DW.obj;
untitled_DW.obj.isInitialized = 1L;
obj->AnalogInDriverObj.MW_ANALOGIN_HANDLE = MW_AnalogInSingle_Open(14UL);
untitled_DW.obj.isSetupComplete = true;
/* Start for MATLABSystem: '<Root>/PWM' */
untitled_DW.obj_b.matlabCodegenIsDeleted = false;
obj_0 = &untitled_DW.obj_b;
untitled_DW.obj_b.isInitialized = 1L;
obj_0->PWMDriverObj.MW_PWM_HANDLE = MW_PWM_Open(6UL, 0.0, 0.0);
untitled_DW.obj_b.isSetupComplete = true;
}
}
/* Model terminate function */
void untitled_terminate(void)
{
codertarget_arduinobase_int_b_T *obj_0;
codertarget_arduinobase_inter_T *obj;
/* Terminate for MATLABSystem: '<Root>/Analog Input' */
obj = &untitled_DW.obj;
if (!untitled_DW.obj.matlabCodegenIsDeleted) {
untitled_DW.obj.matlabCodegenIsDeleted = true;
if ((untitled_DW.obj.isInitialized == 1L) && untitled_DW.obj.isSetupComplete)
{
obj->AnalogInDriverObj.MW_ANALOGIN_HANDLE = MW_AnalogIn_GetHandle(14UL);
MW_AnalogIn_Close(untitled_DW.obj.AnalogInDriverObj.MW_ANALOGIN_HANDLE);
}
}
/* End of Terminate for MATLABSystem: '<Root>/Analog Input' */
/* Terminate for MATLABSystem: '<Root>/PWM' */
obj_0 = &untitled_DW.obj_b;
if (!untitled_DW.obj_b.matlabCodegenIsDeleted) {
untitled_DW.obj_b.matlabCodegenIsDeleted = true;
if ((untitled_DW.obj_b.isInitialized == 1L) &&
untitled_DW.obj_b.isSetupComplete) {
obj_0->PWMDriverObj.MW_PWM_HANDLE = MW_PWM_GetHandle(6UL);
MW_PWM_SetDutyCycle(untitled_DW.obj_b.PWMDriverObj.MW_PWM_HANDLE, 0.0);
obj_0->PWMDriverObj.MW_PWM_HANDLE = MW_PWM_GetHandle(6UL);
MW_PWM_Close(untitled_DW.obj_b.PWMDriverObj.MW_PWM_HANDLE);
}
}
/* End of Terminate for MATLABSystem: '<Root>/PWM' */
}
/*
* File trailer for generated code.
*
* [EOF]
*/