main.c 6.93 KB
Newer Older
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
 /**
  *
  * Author: Nicolas Docquier
  * Creation date: 14/11/2011
  *
  * (c) Universite catholique de Louvain
  *
  * To turn this file as a C++ file, just change its extension to .cc (or .cpp).
  * If you plan to use some C++ files, it is usually better that the main is compiled as a C++ function.
  * Currently, most compilers do not require this, but it is a safer approach to port your code to other computers.
  */

#include <stdio.h>

#include "mbs_part.h"
#include "mbs_load_xml.h"
#include "mbs_equil.h"
#include "mbs_dirdyn.h"
#include "mbs_invdyn.h"
#include "mbs_data.h"
#include "realtime.h"
#include "cmake_config.h"
#include "mbs_set.h"
#include "mbs_modal.h"

26
27
#include "user_all_id.h"

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
int main(int argc, char const *argv[])
{

    MbsData *mbs_data;

    MbsAux *mbs_aux;

    MbsPart *mbs_part;
    MbsEquil *mbs_equil;
    MbsModal *mbs_modal;
    MbsDirdyn *mbs_dirdyn;
    MbsInvdyn *mbs_invdyn;

    printf("Hello MBS!\n");


    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    /*                     LOADING                               *
    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

    printf("Loading the PendulumSpring data file !\n");
    // Error: Bad filename
    // mbs_data = mbs_load(PROJECT_SOURCE_DIR"/../dataR/PendulumSpringC_ERROR.mbs", BUILD_PATH);
    // correct file
    mbs_data = mbs_load(PROJECT_SOURCE_DIR"/../dataR/PendulumSpringC.mbs", BUILD_PATH);
    printf("* .mbs file loaded!\n");

    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    /*              COORDINATE PARTITIONING                      *
    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    // Error: only independent joints
    // mbs_set_qu(mbs_data, 1);
    // mbs_set_qu(mbs_data, 2);
    // mbs_set_qu(mbs_data, 3);
    // mbs_set_qu(mbs_data, 4);
    // mbs_set_qu(mbs_data, 5);
64

65
66
    // Error: impossible cut
    // mbs_data->dpt[3][4] = 10;
67

68
69
70
71
72
73
74
75
76
77
78
79
80
81
    mbs_data->process = 1;
    mbs_part = mbs_new_part(mbs_data);
    mbs_part->options->rowperm=1;
    mbs_part->options->verbose = 1;

    mbs_run_part(mbs_part, mbs_data);

    mbs_delete_part(mbs_part);

    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    /*                    EQUILIBRIUM                            *
    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    mbs_data->process = 2;
    mbs_equil = mbs_new_equil(mbs_data);
82

83
84
    // Error: joints have change
    // mbs_set_qdriven(mbs_data, 2);
85

86
87
88
89
90
    // dirdyn options (see documentations for additional options)
    mbs_equil->options->method = 1;
    mbs_equil->options->senstol  = 1e-2;
    mbs_equil->options->verbose = 1;

Olivier Lantsoght's avatar
Olivier Lantsoght committed
91
    // Error: impossible cut
92
    // mbs_data->dpt[3][4] = 10;
Olivier Lantsoght's avatar
Olivier Lantsoght committed
93

94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
    // Error: Mass matrix full of 0.
    //        Set all mass to 0
    // mbs_data->m[1] = 0.0;
    // mbs_data->m[3] = 0.0;
    // mbs_data->m[4] = 0.0;
    // mbs_data->m[5] = 0.0;
    //        Set all inertia to 0
    // mbs_data->In[5][1] = 0.0;
    // mbs_data->In[5][4] = 0.0;
    // mbs_data->In[5][5] = 0.0;

    // Error: no sensitive variables
    //        Replace all independent joints
    // mbs_equil->options->nquch = 3;
    // mbs_equil_exchange(mbs_equil->options);
    // mbs_equil->options->quch[1] = R2_pendulum_id;
    // mbs_equil->options->quch[2] = T3_slider_id;
    // mbs_equil->options->quch[3] = R3_slider_id;
    //        By anchor point coordinates with no symbol
    // mbs_equil->options->xch_ptr[1] = &(mbs_data->dpt[2][1]);
    // mbs_equil->options->xch_ptr[2] = &(mbs_data->dpt[3][1]);
    // mbs_equil->options->xch_ptr[3] = &(mbs_data->dpt[2][2]);

117
118
119
120
121
122
123
124
125
    mbs_run_equil(mbs_equil, mbs_data);

    mbs_delete_equil(mbs_equil, mbs_data);

    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    /*                    MODAL ANALYSIS                         *
    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    mbs_data->process = 3;
    mbs_modal = mbs_new_modal(mbs_data);
126

127
128
    // Error: joints have change
    // mbs_set_qdriven(mbs_data, 2);
129

130
131
132
133
134
    // modal options (see documentations for additional options)
    mbs_modal->options->save_mat = 1;
    mbs_modal->options->save_result = 1;
    mbs_modal->options->save_anim = 1;
    mbs_modal->options->verbose = 1;
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149

    // Error: impossible cut
    // mbs_data->dpt[3][4] = 10;

    // Error: Mass matrix full of 0.
    //        Set all mass to 0
    // mbs_data->m[1] = 0.0;
    // mbs_data->m[3] = 0.0;
    // mbs_data->m[4] = 0.0;
    // mbs_data->m[5] = 0.0;
    //        Set all inertia to 0
    // mbs_data->In[5][1] = 0.0;
    // mbs_data->In[5][4] = 0.0;
    // mbs_data->In[5][5] = 0.0;

150
151
152
153
154
155
156
157
158
159
    mbs_run_modal(mbs_modal, mbs_data);

    mbs_delete_modal(mbs_modal, mbs_data);


    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    /*                   DIRECT DYNANICS                         *
    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

    mbs_data->qd[1] = 1.5;
160

161
162
163
    // See error defined in user_dirdyn_loop

    mbs_dirdyn = mbs_new_dirdyn(mbs_data);
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
    // Error: joints have change
    // mbs_set_qdriven(mbs_data, 2);

    // dirdyn options (see documentations for additional options)
    mbs_dirdyn->options->dt0 = 1e-3;
    mbs_dirdyn->options->tf  = 100.0e-3;
    mbs_dirdyn->options->save2file = 1;
    mbs_dirdyn->options->respath  = PROJECT_SOURCE_DIR"/../resultsR";
    mbs_dirdyn->options->animpath = PROJECT_SOURCE_DIR"/../animationR";
    mbs_dirdyn->options->realtime = 0;
    mbs_dirdyn->options->show_failed_closure = 0;
    mbs_dirdyn->options->integrator = RK4;
    mbs_dirdyn->options->resfilename = "RK4";

    mbs_run_dirdyn(mbs_dirdyn, mbs_data);

    mbs_delete_dirdyn(mbs_dirdyn, mbs_data);


    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    /*                     INVERSE DYNANMICS                     *
    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    mbs_data->process = 6;
    mbs_reset_data(mbs_data);
    mbs_set_qa(mbs_data, 4);
    mbs_set_qa(mbs_data, 1);
    mbs_set_qa(mbs_data, 2);
    mbs_set_qa(mbs_data, 3);

    mbs_invdyn = mbs_new_invdyn(mbs_data);
    mbs_invdyn->options->trajectoryqname = PROJECT_SOURCE_DIR"/../resultsR/dirdyn_q.res";
    mbs_invdyn->options->trajectoryqdname = PROJECT_SOURCE_DIR"/../resultsR/dirdyn_qd.res";
    mbs_invdyn->options->trajectoryqddname = PROJECT_SOURCE_DIR"/../resultsR/dirdyn_qdd.res";
    mbs_invdyn->options->t0 = 0.;
    mbs_invdyn->options->tf = 10.e-3;
    mbs_invdyn->options->dt = 1.5e-3;

    mbs_run_invdyn(mbs_invdyn, mbs_data);

    mbs_delete_invdyn(mbs_invdyn, mbs_data);



    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    /*                   CLOSING OPERATIONS                      *
    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    mbs_delete_data(mbs_data);

    return 0;
}