Bonjour

Suite à mon ancien topic où les erreurs ont été corrigé et la compilation s'effectue normalement
Mon programme sort 9 valeurs nulles (position, vitesse et accélération) au lieu de sortir des valeurs de position dans l'espace cartésien d'un trois quart de cercle.
Il est possible que la déclaration de mes sorties (Cart) soit mal positionné dans le programme ou mal déclaré!

Code C : Sélectionner tout - Visualiser dans une fenêtre à part
real_T      *Cart = ssGetOutputPortRealSignal(S,9);

Merci de votre aide

Cordialement

Celtic


Code C : Sélectionner tout - Visualiser dans une fenêtre à part
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
/**************************************************************************
*        Simulation de la commande dynamique du robot Orthoglide          *
*             Génération de trajectoire en fonction du temps              *
*                                                      *
*                                                      *
*                                                *
***************************************************************************
*                             MENU PRINCIPAL                              *
**************************************************************************/
 
 /* Spécification de la S-FUNCTION */
 
 
#define S_FUNCTION_NAME  sim_generation_trajectoire_c
#define S_FUNCTION_LEVEL 2
 
 
 /* Need to include simstruc.h for the definition of the SimStruct and
    its associated macro definitions.*/
 
#include <math.h>
#include "simstruc.h"
 
/* déclaration des paramètres*/
 
#define  ki                   mxGetPr(ssGetSFcnParam( S, 0))
#define  ka                   mxGetPr(ssGetSFcnParam( S, 1))
#define  kv                   mxGetPr(ssGetSFcnParam( S, 2))
#define  OI                   mxGetPr(ssGetSFcnParam( S, 3))
#define  Qm                   mxGetPr(ssGetSFcnParam( S, 4))
#define  Qp                   mxGetPr(ssGetSFcnParam( S, 5))
#define  Traj                 mxGetPr(ssGetSFcnParam( S, 6))
#define  alpha_0              mxGetPr(ssGetSFcnParam( S, 7))
#define  alpha_f              mxGetPr(ssGetSFcnParam( S, 8))
#define  amplitude            mxGetPr(ssGetSFcnParam( S, 9))
#define  dx                   mxGetPr(ssGetSFcnParam( S, 10))
#define  dy                   mxGetPr(ssGetSFcnParam( S, 11))
#define  dz                   mxGetPr(ssGetSFcnParam( S, 12))
#define  lbroche              mxGetPr(ssGetSFcnParam( S, 13))
#define  q0                   mxGetPr(ssGetSFcnParam( S, 14))
#define  temps_final          mxGetPr(ssGetSFcnParam( S, 15))
#define  tool                 mxGetPr(ssGetSFcnParam( S, 16))
#define  wn                   mxGetPr(ssGetSFcnParam( S, 17))
 
 
static void mdlInitializeSizes(SimStruct *S)
{
 
 
    ssSetNumSFcnParams(S, 18);  /* Number of expected parameters */
    if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
        return; /* Parameter mismatch will be reported by Simulink */
    }
 
    ssSetNumContStates(S, 0);
    ssSetNumDiscStates(S, 0);
 
    if (!ssSetNumInputPorts(S, 1)) return;
    ssSetInputPortWidth(S, 0, 2);
    /*
     * Set direct feedthrough flag (1=yes, 0=no).
     * A port has direct feedthrough if the input is used in either
     * the mdlOutputs or mdlGetTimeOfNextVarHit functions.
     * See matlabroot/simulink/src/sfuntmpl_directfeed.txt.
     */
    ssSetInputPortDirectFeedThrough(S, 0, 0);
 
    if (!ssSetNumOutputPorts(S,1)) return;
    ssSetOutputPortWidth(S, 0, 9);
 
    ssSetNumSampleTimes(S, 1);
 
    ssSetNumRWork(S, 0);
    ssSetNumIWork(S, 0);
    ssSetNumPWork(S, 0);
    ssSetNumModes(S, 0);
    ssSetNumNonsampledZCs(S, 0);
 
    ssSetOptions(S, 0);
}
 
static void mdlInitializeSampleTimes(SimStruct *S)
{
    ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME);
    ssSetOffsetTime(S, 0, 0.0);
 
}
 
#define MDL_INITIALIZE_CONDITIONS   /* Change to #undef to remove function */
#if defined(MDL_INITIALIZE_CONDITIONS)
  /* 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.
   */
  static void mdlInitializeConditions(SimStruct *S)
  {
  }
#endif /* MDL_INITIALIZE_CONDITIONS */
 
#define MDL_START  /* Change to #undef to remove function */
#if defined(MDL_START)
  /* 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.
   */
  static void mdlStart(SimStruct *S)
  {
 
  }
#endif /*  MDL_START */
 
static void trajectoire(SimStruct *S, const real_T t)
{
 
 
real_T      var,var2,var3,var4,var5;
real_T      res, R_Trj, phi, pi, gamma;
real_T      pos_alpha, vit_alpha, acc_alpha, Px, Py, Pz, ppx, ppy, ppz, pppx, pppy, pppz;
real_T      *Cart = ssGetOutputPortRealSignal(S,9);
 
/**************************  Trajectoire    **********************************/
 
	pi=3.14116;
	if (*Traj==1)
	  {
 
        // resolution
        res=30;
        //Rayon de la Trajectoire en métres [m]
        R_Trj=150/1000;
        //Angle entre l'axe X et le plan de la trajectoire
        phi=0*pi/180;
 
        //Angle entre v et l'axe Z
        gamma=45*pi/180;
 
        if (t<*temps_final)
        	{
            var=(t)/(*temps_final);
            var2=var*var;
            var3=var2*var;
            var4=var3*var;
            var5=var4*var;
            pos_alpha=((10.0*var3)-(15.0*var4)+(6.0*var5))*(*amplitude)+*alpha_0;
            vit_alpha=((30.0*var2)-(60.0*var3)+(30.0*var4))/(*temps_final)*(*amplitude);
            acc_alpha=((60.0*var)-(180.0*var2)+(120.0*var3))/(*temps_final*(*temps_final))*(*amplitude);
 
            Px=*dx+(R_Trj-*lbroche*sin(gamma))*cos(pos_alpha);
            Py=*dy+(R_Trj-*lbroche*sin(gamma))*sin(pos_alpha);
            Pz=*dz+(*lbroche*cos(gamma));
 
            //Vitesse du Point p
            ppx=-(R_Trj-*lbroche*sin(gamma))*vit_alpha*sin(pos_alpha) ;
            ppy=(R_Trj-*lbroche*sin(gamma))*vit_alpha*cos(pos_alpha);
            ppz=-*lbroche*sin(gamma);
 
            //Acceleration de Point p
            pppx=-(R_Trj-*lbroche*sin(gamma))*(vit_alpha*vit_alpha*cos(pos_alpha)+acc_alpha*sin(pos_alpha));
            pppy=-(R_Trj-*lbroche*sin(gamma))*(vit_alpha*vit_alpha*sin(pos_alpha)+acc_alpha*cos(pos_alpha));
            pppz=-*lbroche*cos(gamma);
					}
        else
        	{
            Px=*dx+(R_Trj-*lbroche*sin(gamma))*cos(*alpha_f);
            Py=*dy+(R_Trj-*lbroche*sin(gamma))*sin(*alpha_f);
            Pz=*dz+(*lbroche*cos(gamma));
            ppx=0;
            ppy=0;
            ppz=-*lbroche*sin(gamma);
            pppx=0;
            pppy=0;
            pppz=-*lbroche*cos(gamma);
					}
 
	} 
 
Cart[0]=Px;
Cart[1]=Py;
Cart[2]=Pz;
Cart[3]=ppx;
Cart[4]=ppy;
Cart[5]=ppz;
Cart[6]=pppx;
Cart[7]=pppy;
Cart[8]=pppz;
}
/*************************************************************************
*                      Fin du menu principal                              *
/*************************************************************************/
 
 
/* Function: mdlOutputs =======================================================
 * Abstract:
 *    In this function, you compute the outputs of your S-function
 *    block. Generally outputs are placed in the output vector(s),
 *    ssGetOutputPortSignal.
 *
 *    Qcourant=[q,dq,ddq];
 */
static void mdlOutputs(SimStruct *S, int_T tid)
{
}
 
 
/* 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.
 *
 */
static void mdlTerminate(SimStruct *S)
{
 
}
 
 
#ifdef  MATLAB_MEX_FILE    /* Is this file being compiled as a MEX-file? */
#include "simulink.c"      /* MEX-file interface mechanism */
#else
#include "cg_sfun.h"       /* Code generation registration function */
#endif