Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
robotran
mbsysc
Commits
76437a30
Commit
76437a30
authored
Aug 13, 2015
by
Nicolas Van der Noot
Browse files
user_hardcoded.h generation working
parent
27a6f3a6
Changes
6
Hide whitespace changes
Inline
Side-by-side
MBprojects/PendulumSpringC/userfctR/user_hardcoded.h
0 → 100644
View file @
76437a30
/* --------------------------------------------------------
* This code was generated automatically by MBsysC modules.
* MBsysC modules are distributed as part of the ROBOTRAN
* software. They provides functionalities for dealing with
* symbolic equations generated by ROBOTRAN.
*
* More info on www.robotran.be
*
* Universite catholique de Louvain, Belgium
*
* Last update : Thu Aug 13 11:02:43 2015
* --------------------------------------------------------
*
*/
#ifndef USER_HARDCODED_h
#define USER_HARDCODED_h
// ============================================================ //
// gravity
#define G_3 9.810000
// mass
#define M_1 5.000000
#define M_3 2.000000
#define M_4 2.000000
#define M_5 2.000000
// center of mass
#define L_3_1 0.400000
#define L_3_4 0.075000
#define L_1_5 0.290000
// inertia
#define IN_5_1 0.100000
#define IN_9_3 1.000000
#define IN_5_4 0.100000
#define IN_5_5 0.100000
// body point
#define DPT_1_1 0.250000
#define DPT_1_2 -0.500000
#define DPT_3_3 0.500000
#define DPT_3_4 0.250000
#define DPT_3_5 1.500000
#define DPT_3_6 0.150000
#define DPT_1_7 0.580000
#define DPT_1_8 0.290000
// ============================================================ //
# endif
MBsysC/mbs_app/user_file_generation/CMakeLists.txt
View file @
76437a30
...
...
@@ -40,7 +40,7 @@ xml_lib()
# function to list all source files in the src/ directory,
# recursing into sub-directories
function
(
list_gen_source_files
HEADER_FILES
)
function
(
list_gen_source_files
)
file
(
GLOB_RECURSE SOURCE_FILES_TMP
"
${
PROJECT_SOURCE_DIR
}
/src/*.c"
"
${
ROBOTRAN_SOURCE_DIR
}
/mbs_common/mbs_load_xml/mbs_xml_reader.c"
...
...
@@ -50,7 +50,7 @@ endfunction()
# function to list all paths to header files in the src/ directory,
# recursing into sub-directories (includes)
function
(
list_gen_include_directories
FULL_INCLUDE_DIRECTORIES
)
function
(
list_gen_include_directories
)
file
(
GLOB_RECURSE FULL_INCLUDE_DIRECTORIES_TMP RELATIVE
${
CMAKE_CURRENT_SOURCE_DIR
}
"
${
PROJECT_SOURCE_DIR
}
/src/*.h"
"
${
ROBOTRAN_SOURCE_DIR
}
/mbs_common/mbs_load_xml/mbs_xml_reader.h"
...
...
MBsysC/mbs_app/user_file_generation/readme.md
View file @
76437a30
...
...
@@ -38,5 +38,6 @@ make
specifying which file must be generated:
*
"user_models": user model files
*
"user_all_id": id header file
*
"all": both of the previous option (this is the default option
*
"user_hardcoded": hardcoded mbs values header file
*
"all": all previous options (this is the default option
if the options is omitted)
MBsysC/mbs_app/user_file_generation/src/main.c
View file @
76437a30
...
...
@@ -163,6 +163,32 @@ void generate_user_all_id(char* mbsfile)
}
/*! \brief Generates 'user_hardcoded.h'
*
* \param[in] mbsfile f.mbs file (with path) to use
*/
void
generate_user_hardcoded
(
char
*
mbsfile
)
{
// variables declaration
char
*
fileoutH
,
*
userpath
;
//struct stat mbs_stat, outH_stat;
userpath
=
find_user_path
(
mbsfile
);
MDS_gen_strct
*
gen
;
gen
=
NULL
;
// files initialization
fileoutH
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
(
strlen
(
userpath
)
+
50
));
sprintf
(
fileoutH
,
"%suser_hardcoded.h"
,
userpath
);
gen
=
MDS_mbs_reader
(
mbsfile
);
mbs_print_user_hardcoded
(
gen
,
fileoutH
);
free_MDS_gen_strct
(
gen
);
free
(
fileoutH
);
free
(
userpath
);
}
/**
*
...
...
@@ -203,6 +229,7 @@ int main(int argc, char *argv[])
{
generate_user_models
(
mbsFile
);
generate_user_all_id
(
mbsFile
);
generate_user_hardcoded
(
mbsFile
);
}
else
if
(
!
strcmp
(
argv
[
2
],
"user_models"
)
)
{
...
...
@@ -212,10 +239,14 @@ int main(int argc, char *argv[])
{
generate_user_all_id
(
mbsFile
);
}
else
if
(
!
strcmp
(
argv
[
2
],
"user_hardcoded"
)
)
{
generate_user_hardcoded
(
mbsFile
);
}
else
{
printf
(
"Error: %s is not a good argument !
\n
"
,
argv
[
2
]);
printf
(
"Arguments accepted: 'user_models' and 'user_
all_i
d' (without '')
\n
"
);
printf
(
"Arguments accepted:
'all',
'user_models'
, 'user_all_id'
and 'user_
hardcode
d' (without '')
\n
"
);
}
}
return
0
;
...
...
MBsysC/mbs_app/user_file_generation/src/mbs_print_user_files.c
View file @
76437a30
/*
* Functions used to generate 'user_models.c' 'user_models.h'
* Functions used to generate 'user_models.c'
,
'user_models.h'
, 'user_all_id.h' and 'user_hardcoded.h'
*
* author: Aubain VERLE, Nicolas Docquier
* author: Aubain VERLE, Nicolas Docquier
, Nicolas Van der Noot
*
* (c) Universite catholique de Louvain
*
...
...
@@ -388,3 +388,149 @@ void mbs_print_user_all_id(MDS_gen_strct* gen, char *fileoutH)
printf
(
">> 'user_all_id.h' created
\n
"
);
}
int
get_index_parent_joint
(
MDS_body_strct
*
body
,
MDS_bodytree_strct
*
bodytree
)
{
int
i
;
char
*
joint_name
;
joint_name
=
body
->
joint_list
[
body
->
n_joint
-
1
]
->
name
;
for
(
i
=
0
;
i
<
bodytree
->
n_joint
;
i
++
)
{
if
(
!
strcmp
(
bodytree
->
joint_list
[
i
]
->
name
,
joint_name
))
{
return
i
+
1
;
}
}
printf
(
"Error: unknown joint %s !
\n
"
,
joint_name
);
return
0
;
}
/*! \brief print the 'user_hardcoded.h' file
*
* \param[in] gen MDS generated structure (from the .mbs file)
* \param[in] fileoutH file to create
*/
void
mbs_print_user_hardcoded
(
MDS_gen_strct
*
gen
,
char
*
fileoutH
)
{
int
i
,
j
,
k
;
int
ind
;
int
cur_index
;
FILE
*
fidH
;
MDS_bodytree_strct
*
bodytree
;
MDS_body_strct
*
cur_body
;
MDS_point_strct
*
cur_point
;
int
inertia_tab
[
6
]
=
{
1
,
2
,
3
,
5
,
6
,
9
};
// File declaration
fidH
=
NULL
;
// internal filename
// Opening file
fidH
=
fopen
(
fileoutH
,
"wt"
);
// Fill the file
if
(
fidH
==
NULL
)
{
printf
(
"error: cannot open file '%s'
\n
"
,
fileoutH
);
exit
(
1
);
}
bodytree
=
gen
->
bodytree
;
// -- user_hardcoded.h -- //
// print the generic header
mbs_print_header
(
fidH
);
fprintf
(
fidH
,
"#ifndef USER_HARDCODED_h
\n
"
);
fprintf
(
fidH
,
"#define USER_HARDCODED_h
\n
"
);
fprintf
(
fidH
,
"
\n
"
);
fprintf
(
fidH
,
"// ============================================================ //
\n\n
"
);
fprintf
(
fidH
,
"
\n
"
);
// gravity
fprintf
(
fidH
,
"// gravity
\n
"
);
for
(
i
=
0
;
i
<
3
;
i
++
)
{
if
(
gen
->
base
->
gravity
[
i
])
{
fprintf
(
fidH
,
"#define G_%d %f
\n
"
,
i
+
1
,
gen
->
base
->
gravity
[
i
]);
}
}
fprintf
(
fidH
,
"
\n
"
);
// mass
fprintf
(
fidH
,
"// mass
\n
"
);
for
(
i
=
0
;
i
<
bodytree
->
n_body
;
i
++
)
{
cur_body
=
bodytree
->
body_list
[
i
];
cur_index
=
get_index_parent_joint
(
cur_body
,
bodytree
);
if
(
cur_body
->
mass
)
{
fprintf
(
fidH
,
"#define M_%d %f
\n
"
,
cur_index
,
cur_body
->
mass
);
}
}
fprintf
(
fidH
,
"
\n
"
);
// com
fprintf
(
fidH
,
"// center of mass
\n
"
);
for
(
i
=
0
;
i
<
bodytree
->
n_body
;
i
++
)
{
cur_body
=
bodytree
->
body_list
[
i
];
cur_index
=
get_index_parent_joint
(
cur_body
,
bodytree
);
//x y z
for
(
j
=
0
;
j
<
3
;
j
++
)
{
if
(
cur_body
->
com
[
j
])
{
fprintf
(
fidH
,
"#define L_%d_%d %f
\n
"
,
j
+
1
,
cur_index
,
cur_body
->
com
[
j
]);
}
}
}
fprintf
(
fidH
,
"
\n
"
);
// inertia
fprintf
(
fidH
,
"// inertia
\n
"
);
for
(
i
=
0
;
i
<
bodytree
->
n_body
;
i
++
)
{
cur_body
=
bodytree
->
body_list
[
i
];
cur_index
=
get_index_parent_joint
(
cur_body
,
bodytree
);
// Ixx Ixy Ixz Iyy Iyz Izz
for
(
j
=
0
;
j
<
6
;
j
++
)
{
if
(
cur_body
->
inertia
[
j
])
{
fprintf
(
fidH
,
"#define IN_%d_%d %f
\n
"
,
inertia_tab
[
j
],
cur_index
,
cur_body
->
inertia
[
j
]);
}
}
}
fprintf
(
fidH
,
"
\n
"
);
// body point
fprintf
(
fidH
,
"// body point
\n
"
);
for
(
i
=
0
;
i
<
gen
->
n_point
;
i
++
)
{
cur_point
=
gen
->
point_list
[
i
];
for
(
j
=
0
;
j
<
3
;
j
++
)
{
if
(
cur_point
->
pt
[
j
])
{
fprintf
(
fidH
,
"#define DPT_%d_%d %f
\n
"
,
j
+
1
,
i
+
1
,
cur_point
->
pt
[
j
]);
}
}
}
fprintf
(
fidH
,
"
\n
"
);
fprintf
(
fidH
,
"// ============================================================ //
\n\n
"
);
fprintf
(
fidH
,
"# endif""
\n
"
);
fclose
(
fidH
);
printf
(
">> 'user_hardcoded.h' created
\n
"
);
}
MBsysC/mbs_app/user_file_generation/src/mbs_print_user_files.h
View file @
76437a30
...
...
@@ -16,3 +16,5 @@ void print_empty_file(char *fileout);
void
mbs_print_user_models
(
MDS_gen_strct
*
gen
,
char
*
fileoutC
,
char
*
fileoutH
);
void
mbs_print_user_all_id
(
MDS_gen_strct
*
gen
,
char
*
fileoutH
);
void
mbs_print_user_hardcoded
(
MDS_gen_strct
*
gen
,
char
*
fileoutH
);
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment