Commit 5e3b7528 authored by Olivier Lantsoght's avatar Olivier Lantsoght

[Test] Issue 170 re-used and updated to test current modifications

parent 1877f875
......@@ -95,7 +95,7 @@ endif()
# MBSysC libraries
if ( FLAG_SEPARATE_BUILD ) # find MBSysC dynamic libraries
find_package( LibRobotranC 1.12.0 REQUIRED )
find_package( LibRobotranC 1.13.0 REQUIRED )
add_definitions(${LIB_MBSYSC_DEFINITIONS})
target_link_libraries(${SYMBOLIC_LIB_NAME} ${LIB_MBSYSC_MODULES})
endif()
......
......@@ -140,7 +140,7 @@ endif()
# MBSysC libraries
if ( FLAG_SEPARATE_BUILD ) # find MBSysC dynamic libraries
find_package( LibRobotranC 1.12.0 REQUIRED )
find_package( LibRobotranC 1.13.0 REQUIRED )
add_definitions(${LIB_MBSYSC_DEFINITIONS})
endif()
......
/*===========================================================================*
*
* user_sf_IO.c
*
* Project: PendulumSpringC
*
* Generation date: 14-Nov-2014 18:28:15
*
* (c) Universite catholique de Louvain
* 2, Place du Levant
* 1348 Louvain-la-Neuve
* http://www.robotran.be//
*
/*===========================================================================*/
/* --------------------------------------------------------
* 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 : Fri Apr 10 14:55:20 2020
* --------------------------------------------------------
*
*/
#include <stdlib.h>
#include "user_IO.h"
#include "user_IO.h"
// ============================================================ //
UserIO* mbs_new_user_IO(UserIoInfo* ioInfo)
UserIO* mbs_new_user_IO(UserIoInfo* ioInfo)
{
UserIO *uvs;
int i=0;
//
uvs = (UserIO*) malloc(sizeof(UserIO));
return uvs;
UserIO *uio;
uio = (UserIO*) malloc(sizeof(UserIO));
return uio;
}
void mbs_delete_user_IO(UserIO *uvs)
void mbs_delete_user_IO(UserIO *uio)
{
free(uvs);
free(uio);
}
void mbs_get_user_IO_size(int *n_in, int *n_out, int *n_user_IO)
......@@ -39,3 +40,6 @@ void mbs_get_user_IO_size(int *n_in, int *n_out, int *n_user_IO)
*n_out = 0;
*n_user_IO = 0;
}
// ============================================================ //
/*===========================================================================*
*
* user_sf_IO.h
*
* Project: PendulumSpringC
*
* Generation date: 14-Nov-2014 18:28:15
*
* (c) Universite catholique de Louvain
*
* http://www.robotran.be//
*
/*===========================================================================*/
/* --------------------------------------------------------
* 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 : Fri Apr 10 14:55:20 2020
* --------------------------------------------------------
*
*/
#ifndef user_IO_h
#define user_IO_h
#ifndef UsersfIO_h
#define UsersfIO_h
/*--------------------*/
#ifdef ACCELRED
#define S_FUNCTION_NAME mbs_sf_accelred_PendulumSpringC
#elif defined DIRDYNARED
#define S_FUNCTION_NAME mbs_sf_dirdynared_PendulumSpringC
#elif defined INVDYNARED
#define S_FUNCTION_NAME mbs_sf_invdynared_PendulumSpringC
#elif defined SENSORKIN
#define S_FUNCTION_NAME mbs_sf_sensorkin_PendulumSpringC
#endif
#define SF_N_USER_INPUT 0
#define SF_N_USER_OUTPUT 0
#include "mbs_user_interface.h"
// ============================================================ //
struct UserIO
{
double Fspring; // empty variable for making the compiler happy! (should be improved)
double dummy; // empty variable for making the compiler happy!
};
/*--------------------*/
#endif
// ============================================================ //
# endif
......@@ -83,24 +83,24 @@ void mbs_delete_user_model(UserModel* um)
free(LUT2_PATH_0_1);
for(ind=0; ind<mbs_infos->user_models->user_model_list[1]->parameter_list[0]->n_value; ind++)
for(ind=1; ind<=mbs_infos->user_models->user_model_list[1]->parameter_list[0]->n_value; ind++)
{
um->nb_values.vector[ind+1] = mbs_infos->user_models->user_model_list[1]->parameter_list[0]->value_list[ind];
um->nb_values.vector[ind] = mbs_infos->user_models->user_model_list[1]->parameter_list[0]->value_list[ind];
}
for(ind=0; ind<mbs_infos->user_models->user_model_list[1]->parameter_list[1]->n_value; ind++)
for(ind=1; ind<=mbs_infos->user_models->user_model_list[1]->parameter_list[1]->n_value; ind++)
{
um->nb_values.state_1[ind+1] = ind_state_value;
um->nb_values.state_1[ind] = ind_state_value;
ind_state_value++;
}
for(ind=0; ind<mbs_infos->user_models->user_model_list[1]->parameter_list[2]->n_value; ind++)
for(ind=1; ind<=mbs_infos->user_models->user_model_list[1]->parameter_list[2]->n_value; ind++)
{
um->nb_values.state_2[ind+1] = ind_state_value;
um->nb_values.state_2[ind] = ind_state_value;
ind_state_value++;
}
um->scalar.real = mbs_infos->user_models->user_model_list[2]->parameter_list[0]->value_list[0];
um->scalar.integer_from_double = (int)lround(mbs_infos->user_models->user_model_list[2]->parameter_list[1]->value_list[0]);
um->scalar.integer = (int)lround(mbs_infos->user_models->user_model_list[2]->parameter_list[2]->value_list[0]);
um->scalar.real = mbs_infos->user_models->user_model_list[2]->parameter_list[0]->value_list[1];
um->scalar.integer_from_double = (int)lround(mbs_infos->user_models->user_model_list[2]->parameter_list[1]->value_list[1]);
um->scalar.integer = (int)lround(mbs_infos->user_models->user_model_list[2]->parameter_list[2]->value_list[1]);
}
......
......@@ -174,7 +174,7 @@ flags_clean()
if ( FLAG_SEPARATE_BUILD ) # find MBSysC dynamic libraries
find_path(LibRobotranC_DIR LibRobotranCConfig.cmake "${ROBOTRAN_SOURCE_DIR}/build")
find_package( LibRobotranC 1.12.0 REQUIRED )
find_package( LibRobotranC 1.13.0 REQUIRED )
target_link_libraries( ${Executable} ${LIB_MBSYSC_MODULES} ${LIB_MBSYSC_LOAD} ${LIB_MBSYSC_UTILITIES} )
add_definitions(${LIB_MBSYSC_DEFINITIONS})
......
......@@ -17,7 +17,8 @@ mbs_c = MBsysPy.MbsData("../dataR/Issue_170.mbs", prj_functions_c='SU',
mbs_p = MBsysPy.MbsData("../dataR/Issue_170.mbs")
# %% Reading
for mbs in [mbs_c, mbs_p]:
for mbs, desc in zip([mbs_c, mbs_p], ["C-library", "Python"]):
print("\n\nTesting the {} user functions.".format(desc))
# 1: float
if mbs.user_model['scalar']['real'] != 13.4:
MBsysPy.mbs_error("Scalar reading value is {} instead of 13.4."
......@@ -39,37 +40,19 @@ for mbs in [mbs_c, mbs_p]:
.format(mbs.user_model['scalar']['real']))
# 2: vector
if len(mbs.user_model['nb_values']['vector']) == 4:
# Pure python
if not np.all(mbs.user_model['nb_values']['vector'] == np.array([1.0, 1.1, 1.2, -2.0])):
MBsysPy.mbs_error("Vector reading value is {} instead of [1.0, 1.1, 1.2, -2.0]."
.format(mbs.user_model['nb_values']['vector']))
mbs.user_model['nb_values']['vector'][0] = 5
if not np.all(mbs.user_model['nb_values']['vector'] == np.array([5.0, 1.1, 1.2, -2.0])):
MBsysPy.mbs_error("Vector setting (value, int) - reading value is {} instead of [5.0, 1.1, 1.2, -2.0]."
.format(mbs.user_model['nb_values']['vector']))
mbs.user_model['nb_values']['vector'] = [1, 2, 3, 4]
if not np.all(mbs.user_model['nb_values']['vector'] == np.array([1.0, 2.0, 3.0, 4.0])):
MBsysPy.mbs_error("Vector setting (vector) - reading value is {} instead of [1.0, 2.0, 3.0, 4.0]."
.format(mbs.user_model['nb_values']['vector']))
elif len(mbs.user_model['nb_values']['vector']) == 5:
# Mix Python-C
if not np.all(mbs.user_model['nb_values']['vector'] == np.array([4.0, 1.0, 1.1, 1.2, -2.0])):
MBsysPy.mbs_error("Vector reading value is {} instead of [4.0, 1.0, 1.1, 1.2, -2.0]."
.format(mbs.user_model['nb_values']['vector']))
mbs.user_model['nb_values']['vector'][1] = 5
if not np.all(mbs.user_model['nb_values']['vector'] == np.array([4.0, 5.0, 1.1, 1.2, -2.0])):
MBsysPy.mbs_error("Vector setting (value, int) - reading value is {} instead of [4.0, 5.0, 1.1, 1.2, -2.0]."
.format(mbs.user_model['nb_values']['vector']))
mbs.user_model['nb_values']['vector'] = [4, 1, 2, 3, 4]
if not np.all(mbs.user_model['nb_values']['vector'] == np.array([4.0, 1.0, 2.0, 3.0, 4.0])):
MBsysPy.mbs_error("Vector setting (vector) - reading value is {} instead of [4.0, 1.0, 2.0, 3.0, 4.0]."
.format(mbs.user_model['nb_values']['vector']))
if not np.all(mbs.user_model['nb_values']['vector'] == np.array([4.0, 1.0, 1.1, 1.2, -2.0])):
MBsysPy.mbs_error("Vector reading value is {} instead of [4.0, 1.0, 1.1, 1.2, -2.0]."
.format(mbs.user_model['nb_values']['vector']))
mbs.user_model['nb_values']['vector'][1] = 5
if not np.all(mbs.user_model['nb_values']['vector'] == np.array([4.0, 5.0, 1.1, 1.2, -2.0])):
MBsysPy.mbs_error("Vector setting (value, int) - reading value is {} instead of [4.0, 5.0, 1.1, 1.2, -2.0]."
.format(mbs.user_model['nb_values']['vector']))
mbs.user_model['nb_values']['vector'] = [4, 1, 2, 3, 4]
if not np.all(mbs.user_model['nb_values']['vector'] == np.array([4.0, 1.0, 2.0, 3.0, 4.0])):
MBsysPy.mbs_error("Vector setting (vector) - reading value is {} instead of [4.0, 1.0, 2.0, 3.0, 4.0]."
.format(mbs.user_model['nb_values']['vector']))
# 3: LUT1D
print(mbs.user_model['lut']['one_D'])
......@@ -78,25 +61,13 @@ for mbs in [mbs_c, mbs_p]:
print(mbs.user_model['lut']['two_D'])
# 5: User state
if len(mbs.user_model['nb_values']['state_1']) == 3:
# Pure python
if not np.all(mbs.user_model['nb_values']['state_1'] == np.array([1, 2, 3])):
MBsysPy.mbs_error("Vector reading value is {} instead of [1, 2, 3]."
.format(mbs.user_model['nb_values']['state_1']))
if not np.all(mbs.user_model['nb_values']['state_2'] == np.array([4, 5])):
MBsysPy.mbs_error("Vector reading value is {} instead of [4, 5]."
.format(mbs.user_model['nb_values']['state_1']))
elif len(mbs.user_model['nb_values']['state_1']) == 4:
# Mix Python-C
if not np.all(mbs.user_model['nb_values']['state_1'] == np.array([3, 1, 2, 3])):
MBsysPy.mbs_error("Vector reading value is {} instead of [3, 1, 2, 3]."
.format(mbs.user_model['nb_values']['state_1']))
if not np.all(mbs.user_model['nb_values']['state_2'] == np.array([2, 4, 5])):
MBsysPy.mbs_error("Vector reading value is {} instead of [2, 4, 5]."
.format(mbs.user_model['nb_values']['state_1']))
if not np.all(mbs.user_model['nb_values']['state_1'] == np.array([3, 1, 2, 3])):
MBsysPy.mbs_error("Vector reading value is {} instead of [3, 1, 2, 3]."
.format(mbs.user_model['nb_values']['state_1']))
if not np.all(mbs.user_model['nb_values']['state_2'] == np.array([2, 4, 5])):
MBsysPy.mbs_error("Vector reading value is {} instead of [2, 4, 5]."
.format(mbs.user_model['nb_values']['state_1']))
# 6: Structure
print(mbs.user_model['structure']['lut_res'])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment