-
Notifications
You must be signed in to change notification settings - Fork 1
/
sfun_trajgen_vel.tlc
186 lines (164 loc) · 8.97 KB
/
sfun_trajgen_vel.tlc
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
%% Abstract:
%% Tlc file for S-function sfun_trahgen.cpp
%implements "sfun_trajgen_vel" "C"
%% Function: BlockTypeSetup ====================================================
%function BlockTypeSetup(block, system) void
%%
%% The Target Language must be C++
%if ::GenCPP==0 && !IsModelReferenceSimTarget()
%<LibReportFatalError("This S-Function generated by the Legacy Code Tool must be only used with the C++ Target Language")>
%endif
%<LibAddToCommonIncludes("<ReflexxesAPI.h>")>
%<LibAddToCommonIncludes("<RMLVelocityFlags.h>")>
%<LibAddToCommonIncludes("<RMLVelocityInputParameters.h>")>
%<LibAddToCommonIncludes("<RMLVelocityOutputParameters.h>")>
%<LibAddToModelSources("ReflexxesAPI")>
%<LibAddToModelSources("TypeIIRMLCalculatePositionalExtrems")>
%<LibAddToModelSources("TypeIIRMLDecisions")>
%<LibAddToModelSources("TypeIIRMLDecisionTree1A")>
%<LibAddToModelSources("TypeIIRMLDecisionTree1B")>
%<LibAddToModelSources("TypeIIRMLDecisionTree1C")>
%<LibAddToModelSources("TypeIIRMLDecisionTree2")>
%<LibAddToModelSources("TypeIIRMLFallBackStrategy")>
%<LibAddToModelSources("TypeIIRMLIsPhaseSynchronizationPossible")>
%<LibAddToModelSources("TypeIIRMLPolynomial")>
%<LibAddToModelSources("TypeIIRMLPosition")>
%<LibAddToModelSources("TypeIIRMLQuicksort")>
%<LibAddToModelSources("TypeIIRMLSetupModifiedSelectionVector")>
%<LibAddToModelSources("TypeIIRMLStep1")>
%<LibAddToModelSources("TypeIIRMLStep1IntermediateProfiles")>
%<LibAddToModelSources("TypeIIRMLStep1Profiles")>
%<LibAddToModelSources("TypeIIRMLStep2")>
%<LibAddToModelSources("TypeIIRMLStep2IntermediateProfiles")>
%<LibAddToModelSources("TypeIIRMLStep2PhaseSynchronization")>
%<LibAddToModelSources("TypeIIRMLStep2Profiles")>
%<LibAddToModelSources("TypeIIRMLStep2WithoutSynchronization")>
%<LibAddToModelSources("TypeIIRMLStep3")>
%<LibAddToModelSources("TypeIIRMLVelocity")>
%<LibAddToModelSources("TypeIIRMLVelocityCalculatePositionalExtrems")>
%<LibAddToModelSources("TypeIIRMLVelocityFallBackStrategy")>
%<LibAddToModelSources("TypeIIRMLVelocityIsPhaseSynchronizationPossible")>
%<LibAddToModelSources("TypeIIRMLVelocityMethods")>
%<LibAddToModelSources("TypeIIRMLVelocitySetupPhaseSyncSelectionVector")>
%endfunction
%% Function: mdlInitializeConditions ========================================
%% Abstract:
%% In this function, you should initialize the continuous and discrete
%% states for your S-function block. The initial states are placed
%% in the state vector, ssGetContStates(S) or ssGetRealDiscStates(S).
%% You can also perform any other initialization activities that your
%% S-function may require. Note, this routine will be called at the
%% start of simulation and if it is present in an enabled subsystem
%% configured to reset states, it will be call when the enabled
%% subsystem restarts execution to reset the states.
%function InitializeConditions(block, system) Output
/* %<Type> Block: %<Name> */
{
%% The mdlInitializeConditions method is called when the simulation
%% start and every time an enabled subsystem is re-enabled.
%% Reset the IWork flag to 1 when values need to be reinitialized.
%<LibBlockIWork(BlockInit, "", "", 0)> = 1;
}
%endfunction
%% Function: mdlStart =======================================================
%% Abstract:
%% This function is called once at start of model execution. If you have
%% states that should be initialized once, this is the place to do it.
%function Start(block, system) Output
/* %<Type> Block: %<Name> */
{
%% Creating all relevant objects of the Type II Reflexxes Motion Library
const unsigned int ndofs = static_cast<unsigned int>(%<SFcnParamSettings.NumberOfDoFs>);
ReflexxesAPI *RML = new ReflexxesAPI( ndofs, %<SFcnParamSettings.SampleTime> );
RMLVelocityInputParameters *IP = new RMLVelocityInputParameters( ndofs );
RMLVelocityOutputParameters *OP = new RMLVelocityOutputParameters( ndofs );
RMLVelocityFlags *FLAGS = new RMLVelocityFlags();
FLAGS->SynchronizationBehavior = RMLFlags::%<SFcnParamSettings.SyncBehavior>;
%% Store new C++ object in the pointers vector
%<LibBlockPWork(ReflexxesAPI, "", "", 0)> = RML;
%<LibBlockPWork(RMLVelocityInputParameters, "", "", 0)> = IP;
%<LibBlockPWork(RMLVelocityOutputParameters, "", "", 0)> = OP;
%<LibBlockPWork(RMLVelocityFlags, "", "", 0)> = FLAGS;
}
%endfunction
%% Function: mdlOutputs =======================================================
%% Abstract:
%% In this function, you compute the outputs of your S-function block.
%function Outputs(block, system) Output
/* %<Type> Block: %<Name> */
{
%% Initialize values if the IWork vector flag is true.
if (%<LibBlockIWork(BlockInit, "", "", 0)> == 1) {
const int_T ndofs = static_cast<int_T>(%<SFcnParamSettings.NumberOfDoFs>);
for (int_T dof=0; dof < ndofs; dof++)
{
(%<LibBlockOutputSignalAddr(0, "", "", 0)>)[dof] = (%<LibBlockInputSignalAddr(1, "", "", 0)>)[dof];
(%<LibBlockOutputSignalAddr(1, "", "", 0)>)[dof] = (%<LibBlockInputSignalAddr(2, "", "", 0)>)[dof];
(%<LibBlockOutputSignalAddr(2, "", "", 0)>)[dof] = (%<LibBlockInputSignalAddr(3, "", "", 0)>)[dof];
}
%<LibBlockIWork(BlockInit, "", "", 0)> = 0;
}
else {
%% Retrieve C++ object from the pointers vector
RMLVelocityOutputParameters *OP = static_cast<RMLVelocityOutputParameters *>(%<LibBlockPWork(RMLVelocityOutputParameters, "", "", 0)>);
const int_T ndofs = static_cast<int_T>(%<SFcnParamSettings.NumberOfDoFs>);
for (int_T dof=0; dof < ndofs; dof++)
{
(%<LibBlockOutputSignalAddr(0, "", "", 0)>)[dof] = OP->NewPositionVector->VecData[dof];
(%<LibBlockOutputSignalAddr(1, "", "", 0)>)[dof] = OP->NewVelocityVector->VecData[dof];
(%<LibBlockOutputSignalAddr(2, "", "", 0)>)[dof] = OP->NewAccelerationVector->VecData[dof];
}
}
}
%endfunction
%% Function: mdlUpdate ======================================================
%% Abstract:
%% This function is called once for every major integration time step.
%% Discrete states are typically updated here, but this function is
%% useful for performing any tasks that should only take place once per
%% integration step.
%function Update(block, system) Output
/* %<Type> Block: %<Name> */
{
%% Retrieve C++ object from the pointers vector
ReflexxesAPI *RML = static_cast<ReflexxesAPI *>(%<LibBlockPWork(ReflexxesAPI, "", "", 0)>);
RMLVelocityInputParameters *IP = static_cast<RMLVelocityInputParameters *>(%<LibBlockPWork(RMLVelocityInputParameters, "", "", 0)>);
RMLVelocityOutputParameters *OP = static_cast<RMLVelocityOutputParameters *>(%<LibBlockPWork(RMLVelocityOutputParameters, "", "", 0)>);
RMLVelocityFlags *FLAGS = static_cast<RMLVelocityFlags *>(%<LibBlockPWork(RMLVelocityFlags, "", "", 0)>);
%% Set-up the input parameters
const int_T ndofs = static_cast<int_T>(%<SFcnParamSettings.NumberOfDoFs>);
for (int_T dof=0; dof < ndofs; dof++)
{
IP->CurrentPositionVector->VecData[dof] = (%<LibBlockInputSignalAddr(1, "", "", 0)>)[dof];
IP->CurrentVelocityVector->VecData[dof] = (%<LibBlockInputSignalAddr(2, "", "", 0)>)[dof];
IP->CurrentAccelerationVector->VecData[dof] = (%<LibBlockInputSignalAddr(3, "", "", 0)>)[dof];
IP->MaxAccelerationVector->VecData[dof] = (%<LibBlockParameterAddr(AccLimit, "", "", 0)>)[dof];
IP->MaxJerkVector->VecData[dof] = (%<LibBlockParameterAddr(JrkLimit, "", "", 0)>)[dof];
IP->TargetVelocityVector->VecData[dof] = (%<LibBlockInputSignalAddr(0, "", "", 0)>)[dof];
IP->SelectionVector->VecData[dof] = true;
}
%% Calling the Reflexxes OTG algorithm
int_T ResultValue = RML->RMLVelocity( *IP, OP, *FLAGS );
}
%endfunction
%% Function: mdlTerminate =====================================================
%% Abstract:
%% In this function, you should perform any actions that are necessary
%% at the termination of a simulation. For example, if memory was
%% allocated in mdlStart, this is the place to free it.
%function Terminate(block, system) Output
/* %<Type> Block: %<Name> */
{
%% Retrieve and destroy C++ objects
ReflexxesAPI *RML = static_cast<ReflexxesAPI *>(%<LibBlockPWork(ReflexxesAPI, "", "", 0)>);
RMLVelocityInputParameters *IP = static_cast<RMLVelocityInputParameters *>(%<LibBlockPWork(RMLVelocityInputParameters, "", "", 0)>);
RMLVelocityOutputParameters *OP = static_cast<RMLVelocityOutputParameters *>(%<LibBlockPWork(RMLVelocityOutputParameters, "", "", 0)>);
RMLVelocityFlags *FLAGS = static_cast<RMLVelocityFlags *>(%<LibBlockPWork(RMLVelocityFlags, "", "", 0)>);
%% Deleting the objects of the Reflexxes Motion Library end terminating
%% the process
delete RML;
delete IP;
delete OP;
delete FLAGS;
}
%endfunction