Commit 12696e5c authored by Timothee Habra's avatar Timothee Habra

merge new xml reading in master

parents 45eed29e f766507e
......@@ -92,7 +92,7 @@ option (FLAG_ADAPTIVE_TIME_STEP
# SkyWalker : Rigid rounded feet hung with two ropes
#set(COMAN_VERSION "Basic_version")
#<set(COMAN_VERSION "Short_feet")
#set(COMAN_VERSION "Short_feet")
#set(COMAN_VERSION "Compliant_feet")
set(COMAN_VERSION "Long_arms")
#set(COMAN_VERSION "SkyWalker")
......@@ -168,7 +168,39 @@ if (FLAG_RELEASE_VERSION)
else (FLAG_RELEASE_VERSION)
set(CMAKE_BUILD_TYPE Debug)
endif (FLAG_RELEASE_VERSION)
## ---- COMAN VERSIONS SYNCHRONIZATION ---- ##
if (FLAG_3D_MODEL)
set(MODEL_STANDALONE "Model_standalone_3D")
else (FLAG_3D_MODEL)
set(MODEL_STANDALONE "Model_standalone_2D")
endif (FLAG_3D_MODEL)
# if different mbs, synchronize version
file(GLOB MBS_SRC "${PROJECT_SOURCE_DIR}/src/other/CoMan_versions/${COMAN_VERSION}/${MODEL_STANDALONE}/dataR/*.mbs")
file(READ ${MBS_SRC} STRING1)
file(GLOB MBS_DST "${PROJECT_SOURCE_DIR}/../dataR/*.mbs")
if(EXISTS ${MBS_DST})
file(READ ${MBS_DST} STRING2)
else(EXISTS ${MBS_DST})
set(STRING2 " ")
set(MBS_DST " ")
endif(EXISTS ${MBS_DST})
if(NOT("${STRING1} " STREQUAL "${STRING2} ")) # if different mbs, synchronize version
message(STATUS "Changing the .mbs : copying ${COMAN_VERSION} mbs")
file(WRITE ${PROJECT_SOURCE_DIR}/../dataR/copy_check "this file is used to check if the mbs has changed")
file(REMOVE_RECURSE ${PROJECT_SOURCE_DIR}/../symbolicR) #otherwise some files are not overwriten
file(COPY ${PROJECT_SOURCE_DIR}/src/other/CoMan_versions/${COMAN_VERSION}/Symbolic_files/ DESTINATION ${PROJECT_SOURCE_DIR}/..)
file(REMOVE ${MBS_DST}) #otherwise some files are not overwriten
file(COPY ${MBS_SRC} DESTINATION ${PROJECT_SOURCE_DIR}/../dataR)
endif(NOT("${STRING1} " STREQUAL "${STRING2} "))
## ---- AUTOMATIC GENERATION ('ControllersStruct.h/.c' and 'user_sf_IO.h/.c') ---- ##
......@@ -213,10 +245,46 @@ endif (FLAG_GENERATE_VARSTATE)
message(STATUS "CMake generator: ${CMAKE_GENERATOR}")
## ---- AUTOMATIC GENERATION ('user_all_id.h' and 'UserModelStruct.h/.c') ---- ##
## change for mds_user
# UserModelStruct.h/.c
set(USER_MODELS_H ${PROJECT_SOURCE_DIR}/src/project/user_files/UserModelStruct.h)
set(USER_MODELS_C ${PROJECT_SOURCE_DIR}/src/project/user_files/UserModelStruct.c)
set(USER_ALL_ID_H ${PROJECT_SOURCE_DIR}/src/project/user_files/user_all_id.h)
# input .mbs file
file(GLOB MBS_FILE "${PROJECT_SOURCE_DIR}/../dataR/*.mbs")
# checking files
set(CHECK_USER_MODELS ${CMAKE_CURRENT_BINARY_DIR}/src/project/user_files/update_check/user_models_check.txt) # these files are actually not created.
set(CHECK_USER_ALL_ID ${CMAKE_CURRENT_BINARY_DIR}/src/project/user_files/update_check/user_all_id_check.txt) # can't use .c/.h as they are deleted at 'clean'
# re-generate user_models.h/.c
add_custom_command (
OUTPUT ${CHECK_USER_MODELS}
COMMAND Gen_mds_user user_models
DEPENDS ${MBS_FILE}
)
# re-generate user_all_id.h/.c
add_custom_command (
OUTPUT ${CHECK_USER_ALL_ID}
COMMAND Gen_mds_user user_all_id
DEPENDS ${MBS_FILE}
)
# check if re-generation needed
add_custom_target(CheckGeneration_2 ALL
DEPENDS ${CHECK_USER_ALL_ID} ${CHECK_USER_MODELS})
## ---- PROHIBITED LIST ---- ##
# Project name in Robotran
file(GLOB_RECURSE ROBOTRAN_ROJECT_NAME "${PROJECT_SOURCE_DIR}/src/other/CoMan_versions/${COMAN_VERSION}/dataR/*.mbs")
file(GLOB_RECURSE ROBOTRAN_ROJECT_NAME "${PROJECT_SOURCE_DIR}/src/other/CoMan_versions/${COMAN_VERSION}/${MODEL_STANDALONE}/dataR/*.mbs")
get_filename_component(ROBOTRAN_ROJECT_NAME ${ROBOTRAN_ROJECT_NAME} NAME_WE)
message(STATUS "Robotran project name: ${ROBOTRAN_ROJECT_NAME}")
......@@ -477,6 +545,18 @@ endif(LIBXML2_FOUND)
message(" -> INC : ${LIBXML2_INCLUDE_PATH}")
message(" -> LIB : ${LIBXML2_LIBRARIES}\n")
# GSL library
find_package(GSL REQUIRED)
if (GSL_FOUND)
include_directories(${GSL_INCLUDE_DIR})
add_definitions( -DGSL_DLL)
message( "\n >> GSL found")
else(GSL_FOUND)
message( "\n >> GSL not found, modify src/other/conf/FindGSL.cmake")
endif(GSL_FOUND)
message(" -> INC : ${GSL_INCLUDE_DIR}")
message(" -> LIB : ${GSL_LIBRARIES}\n")
# real-time features
if (FLAG_REAL_TIME)
......@@ -587,22 +667,11 @@ endif (WIN32)
## ---- COMAN VERSIONS SYNCHRONIZATION ---- ##
if (FLAG_3D_MODEL)
set(MODEL_STANDALONE "Model_standalone_3D")
else (FLAG_3D_MODEL)
set(MODEL_STANDALONE "Model_standalone_2D")
endif (FLAG_3D_MODEL)
file(COPY ${PROJECT_SOURCE_DIR}/src/other/CoMan_versions/${COMAN_VERSION}/Symbolic_files/ DESTINATION ${PROJECT_SOURCE_DIR}/..)
file(COPY ${PROJECT_SOURCE_DIR}/src/other/CoMan_versions/${COMAN_VERSION}/dataR/ DESTINATION ${PROJECT_SOURCE_DIR}/../dataR)
file(COPY ${PROJECT_SOURCE_DIR}/src/other/CoMan_versions/${COMAN_VERSION}/${MODEL_STANDALONE}/ DESTINATION ${PROJECT_SOURCE_DIR}/src/project)
## ---- ADDITIONAL CMAKELISTS.TXT ---- ##
# add locations of other CMakeLists.txt
add_subdirectory (src/)
add_subdirectory (src/other/varState/)
## change for user_models
add_subdirectory (src/other/user_models/)
......@@ -36,6 +36,11 @@ Install [Libxml2](http://xmlsoft.org/) to read the _xml_ files used to initializ
* _sudo apt-get install libxml2-dev_
### GSL: numerical library ###
Install [GSL](http://www.gnu.org/software/gsl/) to perform numerical computations for coordinate partitioning.
* _sudo apt-get install libgsl0ldbl_
### SDL 2.0: Graphs and interactions with the simulator (in real-time) ###
......@@ -106,6 +111,7 @@ Some useful links for the 32-bit version and the corresponding files to download
* [libxml](http://www.xmlsoft.org/downloads.html): libxml2.dll, libxml include folder, libxml2 object file library, also use this [link](http://gnuwin32.sourceforge.net/packages/libiconv.htm) to get iconv.h, iconv object file library
* [SDL 2.0](http://www.libsdl.org/download-2.0.php): SDL2.dll, SDL include folder, SDL2 object file library, SDL2test object file library, SDL2main object file library
* [SDL2_ttf](http://www.libsdl.org/projects/SDL_ttf/): libfreetype-6.dll, SDL2_ttf.dll, zlib1.dll, SDL_ttf.h, SDL2ttf object file library
* [GSL](http://gnuwin32.sourceforge.net/packages/gsl.htm): see _src/other/win64_include_lib_ for more details.
### CMake: create the project ###
......@@ -115,7 +121,7 @@ Download CMake [here](http://www.cmake.org/cmake/resources/software.html).
Run the _cmake-2.8.xx.x-win32-x86.exe_ executable (it also works for 64-bit machines).
### Libxml and SDL 2.0 ###
### Libxml, GSL and SDL 2.0 ###
All the needed files are already located in src/other/win64_include_lib/ for the 64-bit machines (so, you do not have to install them).
For the 32-bit ones, replace these files with the corresponding 32-bit ones (see above).
......
......@@ -82,6 +82,9 @@ endif (UNIX)
# Libxml2 external libray: linkage
target_link_libraries (${Executable} ${LIBXML2_LIBRARIES})
# GSL external libray: linkage
target_link_libraries (${Executable} ${GSL_LIBRARIES})
if (FLAG_REAL_TIME)
# SDL external library: linkage
......
......@@ -21,6 +21,8 @@
#include <sys/timeb.h>
#endif
#define MBS_FILE PROJECT_ABS_PATH"/../dataR/"PROJECT_NAME_MBS
/*
* Simulation initialization
*/
......@@ -45,8 +47,6 @@ Loop_arguments* init_simulation(void)
Save_vectors *save_vectors;
#endif
const char *filein;
struct timeval seed_time;
......@@ -58,18 +58,23 @@ Loop_arguments* init_simulation(void)
// -- Variables initialization -- //
// xml file with the model inputs (initial positions, inertia matrices, degrees of freedom...)
filein = PROJECT_ABS_PATH"/src/project/Model_standalone.mbsdata";
// MBSDataStruct initialization
MBSdata = loadMBSdata_xml(filein);
MBSdata = loadMBSdata_xml(MBS_FILE);
printMbsData(MBSdata);
printMbsData(MBSdata);
if(MBSdata == NULL)
{
printf("error while loading MBSdata from file %s\n", filein);
printf("error while loading MBSdata \n");
}
#ifdef PRINT_REPORT
else
{
printf("MBSdata successfully loaded \n");
}
#endif
// LocalDataStruct initialization
......
/*
* Functions to initialize the MBSdata structure from the <ProjectName>.mbsdata (xml format) file.
* Functions to initialize the MBSdata structure from the <ProjectName>.mbs (xml format) file.
*
* Allan Barrea Feb. 2013
* Timothee Habra Sept. 2014
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include "loadMBSdata_xml.h"
#include "user_sf_IO.h"
#include "MBSfun.h"
#include "sfdef.h"
#include "MBSdef.h"
/*
* loadMBSdata_xml --> opens and parse the .mbsdata (xml) file
* --> calls loadMBSsizes_xml
* --> calls loadMBSelements_xml
* --> calls loadUserModel_xml
*/
MBSdataStruct* loadMBSdata_xml(const char *filein)
MBSdataStruct* loadMBSdata_xml(const char *mbs_xml_name)
{
MBSdataStruct* MBSdata = NULL;
xmlDocPtr doc = NULL;
xmlNodePtr root = NULL;
/*
* This initialize the library and check potential ABI mismatches
* between the version it was compiled for and the actual shared
* library used.
*/
LIBXML_TEST_VERSION
// Parse the file and get the DOM
doc = xmlReadFile(filein, NULL, 0);
if (doc == NULL ) {
fprintf(stderr, "error: could not parse file %s\n", filein);
return NULL;
}
// Get the root element node
root = xmlDocGetRootElement(doc);
if (root == NULL) {
fprintf(stderr, "empty document (file %s)\n", filein);
xmlFreeDoc(doc);
return NULL;
}
MDS_gen_strct *mds = NULL;
MBSdataStruct *MBSdata = NULL;
PART_gen_strct *part = NULL;
if (xmlStrcmp(root->name, (const xmlChar *) "mbsdata")) {
fprintf(stderr,"document of the wrong type, root node != 'mbsdata'\n");
xmlFreeDoc(doc);
return NULL;
}
// retrieve data from xml .mbs
mds = MDS_mbs_reader(mbs_xml_name);
// Print element names
//print_element_names_xml(root);
//load mbsdata struct
MBSdata = MDS_create_MBSdataStruct(mds);
// Load MBSdata sizes
MBSdata = loadMBSsizes_xml(doc, root);
// coordinate partitioning
part = init_PART_gen_strct(mds);
// Load MBSdata elements
loadMBSelements_xml(MBSdata, doc, root);
part->options->rowperm = 1;
//part->options->visualise = 0;
//part->options->treshold = 1e-9;
//part->options->drivers = 0;
//part->options->verbose = 0;
//part->options->clearmbsglobal = 1;
// Free the document
xmlFreeDoc(doc);
PART_run_part(mds, MBSdata, part);
/*
* Free the global variables that may
* have been allocated by the parser.
*/
xmlCleanupParser();
free_MDS_gen_strct(mds);
free_PART_gen_strct(part);
return MBSdata;
}
#ifndef __LOAD_MBSXML_H_INCLUDED__ // guard against multiple/recursive includes
#define __LOAD_MBSXML_H_INCLUDED__
#include "MBSdataStruct.h"
#include "mds_translator.h"
#include "part.h"
MBSdataStruct* loadMBSdata_xml(const char *filein);
#endif
This diff is collapsed.
#ifndef MBS_XML_READER_h
#define MBS_XML_READER_h
#include <libxml/tree.h>
#include <libxml/parser.h>
#include "useful_functions.h"
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////// Init and free functions for MDS structures ///////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
typedef struct MDS_d_data_strct
{
int d_type; // other = 0; simplified = 1, forced = 2, optimized = 3, resulting = 4, related = 5,
double d_0; // initial value for optimization
double d_min; // bounds values for optimization
double d_max;
// the following variables are "comptute" in "MDS_opti_structurer"
int is_related; // unrelated = 0, master = 1, equal salve = 2, opposite slave = 3
struct MDS_d_data_strct *master_d_ptr;
double *d_ptr;
// link in the creation of MBSdata
double *MBSdata_d_ptr;
} MDS_d_data_strct;
typedef struct MDS_ref_point_strct
{
char *bodyname;
char *pointname;
} MDS_ref_point_strct;
typedef struct MDS_sensor_strct
{
char *name;
int Pos;
int Rot;
int Vit;
int Om;
int Acc;
int Omp;
int Jac;
} MDS_sensor_strct;
typedef struct MDS_extforce_strct
{
char *name;
int Pos;
int Rot;
int Vit;
int Om;
int Acc;
int Omp;
} MDS_extforce_strct;
typedef struct MDS_point_strct
{
char *name;
double *pt; // x y z
MDS_sensor_strct *sensor;
MDS_extforce_strct *extforce;
MDS_d_data_strct **d_pt; // x y z
int is_symmmetric; // asymmetric = 0, symmetric master = 1, symmetric salve = 2
char *symmetric_point_name; // the name of the symmetric point (filed if master, NULL if slave or non symetric)
} MDS_point_strct;
typedef struct MDS_base_strct
{
double *gravity; //x y z
int n_base_point;
MDS_point_strct **base_point_list;
} MDS_base_strct;
typedef struct MDS_joint_strct
{
char *name;
int type; // T1=1, T2=2, T3=3, R1=4, R2=5, R3=6
int nature; // independant=1, dependent=2, driven=3
double q0;
double qd0;
double qdd0;
int actuated;
MDS_d_data_strct *d_qf; // d_data for the forced q
int is_symmmetric; // asymmetric = 0, symmetric master = 1, symmetric salve = 2
char *symmetric_joint_name; // the name of the symmetric joint (filed if master, NULL if slave or non symetric)
} MDS_joint_strct;
typedef struct MDS_body_strct
{
char *name;
MDS_ref_point_strct* parent;
int n_joint;
MDS_joint_strct **joint_list;
double mass;
double *com; //x y z
double *inertia; // Ixx Ixy Ixz Iyy Iyz Izz
int n_point;
MDS_point_strct **point_list;
} MDS_body_strct;
typedef struct MDS_bodytree_strct
{
int n_body;
MDS_body_strct **body_list;
int n_joint;
MDS_joint_strct **joint_list;
int n_qu;
int *qu;
int n_qv;
int *qv;
int n_qc;
int *qc;
int n_qlocked;
int *qlocked;
int n_qdriven;
int *qdriven;
int n_qa;
int *qa;
} MDS_bodytree_strct;
typedef struct MDS_ball_strct
{
char *name;
MDS_ref_point_strct *endpoint1;