Commit de30016f authored by Timothee Habra's avatar Timothee Habra
Browse files

mbs_realtime as shared lib to have access to plot in userfct

parent 82563021
......@@ -29,6 +29,8 @@ set(INCLUDE_DIR ${INCLUDE_DIR} ${PROJECT_SOURCE_DIR} PARENT_SCOPE)
include (GenerateExportHeader)
add_library(Project_userfct ${SOURCE_FILES} ${INCLUDE_DIR})
target_link_libraries (Project_userfct MBsysC_realtime)
GENERATE_EXPORT_HEADER( Project_userfct )
include_directories(${CMAKE_CURRENT_BINARY_DIR})
install ( TARGETS Project_userfct DESTINATION ${CMAKE_INSTALL_PREFIX})
......@@ -45,4 +47,5 @@ include_directories(${ROBOTRAN_SOURCE_DIR}/mbs_common/mbs_module)
if (FLAG_PLOT)
sdl_header_lib(userfct)
include_directories(${ROBOTRAN_SOURCE_DIR}/mbs_common/mbs_realtime/sdl)
include_directories(${ROBOTRAN_SOURCE_DIR}/mbs_common/mbs_realtime/sdl/auto_plot)
endif ( )
\ No newline at end of file
......@@ -10,7 +10,7 @@
#include "realtime.h"
#include "events_sdl.h"
#include "user_realtime.h"
//#include "user_realtime.h"
/*! \brief handle inputs comming from the keyboard
*
......
/*!
* \author Nicolas Van der Noot
* \file user_realtime_plot.c
* \brief Configure the SDL screen to plot simulations values
*
* In order to use C++ features, you just need to change the extension of this file (.c) to .cc (or .cpp).
*/
#ifdef SDL
#include "user_realtime.h"
/*! \brief assign values for the SDL functions
*
* \param[in] mbs_data Robotran main structure
*
* To plot a curve, use 'set_plot(value, label)' where 'value' is the value you want to plot
* and 'label' is a string corresponding to the curve label. You can use the 'set_plot' function
* in the following function ('user_realtime_plot') or anywhere in your code, provided you add
* the include '#include "user_realtime.h"' in the corresponding file. Using 'user_realtime_plot' is
* still useful to structure the code, avoiding to put the 'set_plot' function everywhere in the code.
* However, using 'set_plot' in other files can be faster and is especially relevant fot C++ code
* where some internal variables are private and cannot be used outside the corresponding class.
* To plot different curves, you must use different labels (otherwise, some curves won't be plotted).
*
* example:
* set_plot(mbs_data->q[4], "q4 [rad]");
*/
void user_realtime_plot(MbsData* mbs_data)
{
set_plot(mbs_data->q[1], "q1 [rad]");
set_plot(mbs_data->q[2], "q2 [m]");
set_plot(mbs_data->q[3], "q3 [rad]");
set_plot(mbs_data->q[4], "q4 [rad]");
set_plot(mbs_data->q[5], "q5 [rad]");
}
#endif
/*!
* \author Nicolas Van der Noot
* \file user_realtime_plot.c
* \brief Configure the SDL screen to plot simulations values
*
* In order to use C++ features, you just need to change the extension of this file (.c) to .cc (or .cpp).
*/
#ifdef SDL
//#include "user_realtime.h"
#include "set_plot2.h"
#include "mbs_data.h"
/*! \brief assign values for the SDL functions
*
* \param[in] mbs_data Robotran main structure
*
* To plot a curve, use 'set_plot(value, label)' where 'value' is the value you want to plot
* and 'label' is a string corresponding to the curve label. You can use the 'set_plot' function
* in the following function ('user_realtime_plot') or anywhere in your code, provided you add
* the include '#include "user_realtime.h"' in the corresponding file. Using 'user_realtime_plot' is
* still useful to structure the code, avoiding to put the 'set_plot' function everywhere in the code.
* However, using 'set_plot' in other files can be faster and is especially relevant fot C++ code
* where some internal variables are private and cannot be used outside the corresponding class.
* To plot different curves, you must use different labels (otherwise, some curves won't be plotted).
*
* example:
* set_plot(mbs_data->q[4], "q4 [rad]");
*/
void user_realtime_plot(MbsData* mbs_data)
{
set_plot(mbs_data->q[1], "q1 [rad]");
set_plot(mbs_data->q[2], "q2 [m]");
set_plot(mbs_data->q[3], "q3 [rad]");
set_plot(mbs_data->q[4], "q4 [rad]");
set_plot(mbs_data->q[5], "q5 [rad]");
}
#endif
......@@ -13,7 +13,8 @@
#ifdef JAVA
#include "user_realtime.h"
//#include "user_realtime.h"
#include "mbs_data.h"
/*! \brief Java visualization user configuration
*
......
......@@ -22,7 +22,6 @@ extern "C" {
#include "realtime.h"
#include "cmake_config.h"
#include "mbs_project_interface.h"
#include "user_realtime.h"
#ifdef __cplusplus
}
#endif
......@@ -92,6 +91,8 @@ int main(int argc, char const *argv[])
#include <windows.h>
#endif
#include "user_realtime.h"
void mbs_get_project_functions(MbsData *mbs_data)
{
#ifdef UNIX
......@@ -105,8 +106,7 @@ void mbs_get_project_functions(MbsData *mbs_data)
exit(1);
}
#else
//HINSTANCE hInstLibrary = LoadLibrary(PROJECT_SOURCE_DIR"\\build\\symbolicR\\Debug\\libproject_symbolic.dll");
HINSTANCE hInstLibrary = LoadLibrary("D:\\Projects_Ubuntu\\Robotran-dev\\mbsysc\\MBprojects\\PendulumSpringC\\workR\\build\\symbolicR\\Debug\\project_symbolic.dll");
HINSTANCE hInstLibrary = LoadLibrary(PROJECT_SOURCE_DIR"\\build\\symbolicR\\Debug\\project_symbolic.dll");
if(!hInstLibrary)
{
printf("symbolic DLL Failed To Load!\n");
......
......@@ -53,6 +53,7 @@ include_directories(../mbs_struct)
include_directories(../mbs_numerics)
include_directories(../mbs_utilities)
include_directories(../mbs_utilities/auto_output)
include_directories(../mbs_realtime)
include_directories(../mbs_realtime/realtime)
include_directories(../mbs_realtime/sdl)
include_directories(../mbs_load_xml) #this dependencies should be avoided (needed by equil which needs mds)
# Copyright: (C)
# Authors: Timothee Habra
# CopyPolicy: Released under the terms of the LGPLv2.1 or later, see LGPL.TXT
cmake_minimum_required(VERSION 2.8.7)
project(MBsysC_realtime)
# project configuration
set( CMAKE_C_FLAGS_RELEASE "-O3" )
set( CMAKE_CXX_FLAGS_RELEASE "-O3" )
# release of debug
release_debug()
# list source files to compile
init_src()
increment_src( ${PROJECT_SOURCE_DIR}/realtime )
increment_src( ${PROJECT_SOURCE_DIR}/void )
# Get SDL lib and add plot functions to src
if (FLAG_PLOT)
# Find SDL
sdl_lib(mbs_realtime)
set(SDL2_LIBRARIES ${SDL2_LIBRARIES} PARENT_SCOPE)
set(SDL2TTF_LIBRARIES ${SDL2TTF_LIBRARIES} PARENT_SCOPE)
increment_src( ${PROJECT_SOURCE_DIR}/sdl )
# configure a header file to pass some of the CMake settings to the source code
set(SDL_FILES ${CMAKE_CURRENT_SOURCE_DIR}/sdl/SDL_files)
configure_file (
"./sdl/conf/cmake_sdl_config.h.in"
"${PROJECT_BINARY_DIR}/conf/cmake_sdl_config.h"
)
include_directories ("${PROJECT_BINARY_DIR}/conf")
endif ()
# Get java lib and add java functions to src
if (FLAG_VISU)
# find java and java 3d
java_lib(mbs_realtime)
set(JNI_LIBRARIES ${JNI_LIBRARIES} PARENT_SCOPE)
set (J3D_PATH ${J3D_PATH} PARENT_SCOPE)
include_directories("./java")
increment_src( ${PROJECT_SOURCE_DIR}/java )
set(JAR_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../mbsyspad/MBsysPad.jar)
configure_file (
"./java/conf/cmake_java_config.h.in"
"${PROJECT_BINARY_DIR}/conf/cmake_java_config.h"
)
include_directories ("${PROJECT_BINARY_DIR}/conf")
endif ()
# list include directories (to find headers)
init_include()
set(INCLUDE_DIR ${INCLUDE_DIR} ${PROJECT_SOURCE_DIR}/realtime PARENT_SCOPE)
add_library(MBsysC_realtime ${SOURCE_FILES} ${INCLUDE_DIR})
# SDL external library: linkage
if (FLAG_PLOT)
target_link_libraries (MBsysC_realtime ${SDL2_LIBRARIES} ${SDL2TTF_LIBRARIES})
endif ( )
# Java external library: linkage
if (FLAG_VISU)
target_link_libraries (MBsysC_realtime ${JNI_LIBRARIES})
endif ( )
# include directories
include_directories("./")
include_directories("./sdl" "./sdl/auto_plot")
include_directories("./realtime")
include_directories("../mbs_struct")
include_directories("../mbs_utilities")
# Copyright: (C)
# Authors: Timothee Habra
# CopyPolicy: Released under the terms of the LGPLv2.1 or later, see LGPL.TXT
cmake_minimum_required(VERSION 2.8.7)
project(MBsysC_realtime)
# project configuration
set( CMAKE_C_FLAGS_RELEASE "-O3" )
set( CMAKE_CXX_FLAGS_RELEASE "-O3" )
# release of debug
release_debug()
# list source files to compile
init_src()
increment_src( ${PROJECT_SOURCE_DIR}/realtime )
increment_src( ${PROJECT_SOURCE_DIR}/void )
# Get SDL lib and add plot functions to src
if (FLAG_PLOT)
# Find SDL
sdl_lib(mbs_realtime)
set(SDL2_LIBRARIES ${SDL2_LIBRARIES} PARENT_SCOPE)
set(SDL2TTF_LIBRARIES ${SDL2TTF_LIBRARIES} PARENT_SCOPE)
increment_src( ${PROJECT_SOURCE_DIR}/sdl )
# configure a header file to pass some of the CMake settings to the source code
set(SDL_FILES ${CMAKE_CURRENT_SOURCE_DIR}/sdl/SDL_files)
configure_file (
"./sdl/conf/cmake_sdl_config.h.in"
"${PROJECT_BINARY_DIR}/conf/cmake_sdl_config.h"
)
include_directories ("${PROJECT_BINARY_DIR}/conf")
endif ()
# Get java lib and add java functions to src
if (FLAG_VISU)
# find java and java 3d
java_lib(mbs_realtime)
set(JNI_LIBRARIES ${JNI_LIBRARIES} PARENT_SCOPE)
set (J3D_PATH ${J3D_PATH} PARENT_SCOPE)
include_directories("./java")
increment_src( ${PROJECT_SOURCE_DIR}/java )
set(JAR_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../mbsyspad/MBsysPad.jar)
configure_file (
"./java/conf/cmake_java_config.h.in"
"${PROJECT_BINARY_DIR}/conf/cmake_java_config.h"
)
include_directories ("${PROJECT_BINARY_DIR}/conf")
endif ()
# list include directories (to find headers)
init_include()
set(INCLUDE_DIR ${INCLUDE_DIR} ${PROJECT_SOURCE_DIR}/realtime )
add_library(MBsysC_realtime SHARED ${SOURCE_FILES} ${INCLUDE_DIR})
target_link_libraries (MBsysC_realtime MBsysC_utilities)
include (GenerateExportHeader)
GENERATE_EXPORT_HEADER( MBsysC_realtime )
include_directories(${CMAKE_CURRENT_BINARY_DIR})
install (TARGETS MBsysC_realtime DESTINATION ${CMAKE_INSTALL_PREFIX})
# SDL external library: linkage
if (FLAG_PLOT)
target_link_libraries (MBsysC_realtime ${SDL2_LIBRARIES} ${SDL2TTF_LIBRARIES})
endif ( )
# Java external library: linkage
if (FLAG_VISU)
target_link_libraries (MBsysC_realtime ${JNI_LIBRARIES})
endif ( )
# include directories
#include_directories("./")
include_directories("./sdl" "./sdl/auto_plot")
include_directories("./realtime")
include_directories("../mbs_struct")
include_directories("../mbs_utilities")
......@@ -3,7 +3,7 @@
#include "java_functions.h"
#include "cmake_java_config.h"
#include "user_realtime.h"
//#include "user_realtime.h"
#include <stdlib.h>
......
#ifndef MBSYSC_REALTIME_EXPORT_H
#define MBSYSC_REALTIME_EXPORT_H
#ifdef _WIN32
#ifdef MBSYSC_REALTIME_STATIC_DEFINE
# define MBSYSC_REALTIME_EXPORT
# define MBSYSC_REALTIME_NO_EXPORT
#else
# ifndef MBSYSC_REALTIME_EXPORT
# ifdef MBsysC_realtime_EXPORTS
/* We are building this library */
# define MBSYSC_REALTIME_EXPORT __declspec(dllexport)
# else
/* We are using this library */
# define MBSYSC_REALTIME_EXPORT __declspec(dllimport)
# endif
# endif
# ifndef MBSYSC_REALTIME_NO_EXPORT
# define MBSYSC_REALTIME_NO_EXPORT
# endif
#endif
#ifndef MBSYSC_REALTIME_DEPRECATED
# define MBSYSC_REALTIME_DEPRECATED __declspec(deprecated)
# define MBSYSC_REALTIME_DEPRECATED_EXPORT MBSYSC_REALTIME_EXPORT __declspec(deprecated)
# define MBSYSC_REALTIME_DEPRECATED_NO_EXPORT MBSYSC_REALTIME_NO_EXPORT __declspec(deprecated)
#endif
#define DEFINE_NO_DEPRECATED 0
#if DEFINE_NO_DEPRECATED
# define MBSYSC_REALTIME_NO_DEPRECATED
#endif
#else // Unix
# define MBSYSC_REALTIME_EXPORT
#endif
#endif
......@@ -13,6 +13,7 @@
#include "color_sdl.h"
#include "mbs_data.h"
#include "mbsysc_realtime_export.h"
// back in visualization period
#define PERIOD_BACK_IN_VISU 0.03 // [s]
......@@ -149,10 +150,10 @@ struct Simu_realtime
#ifdef __cplusplus
extern "C" {
#endif
void mbs_realtime_init(MbsData* mbs_data, double t0, double tf, double dt0);
void mbs_realtime_loop(Simu_realtime *realtime, double tsim);
void mbs_realtime_update(Simu_realtime *realtime, double tsim);
void mbs_realtime_finish(Simu_realtime *realtime);
MBSYSC_REALTIME_EXPORT void mbs_realtime_init(MbsData* mbs_data, double t0, double tf, double dt0);
MBSYSC_REALTIME_EXPORT void mbs_realtime_loop(Simu_realtime *realtime, double tsim);
MBSYSC_REALTIME_EXPORT void mbs_realtime_update(Simu_realtime *realtime, double tsim);
MBSYSC_REALTIME_EXPORT void mbs_realtime_finish(Simu_realtime *realtime);
#ifdef __cplusplus
}
#endif
......
......@@ -55,7 +55,7 @@ void free_auto_plot(AutoPlot *auto_plot)
* \param[in] value current curve value
* \param[in] label current curve label
*/
void update_auto_plot(AutoPlot *auto_plot, double value, char* label)
void update_auto_plot(AutoPlot *auto_plot, double value, const char* label)
{
int nb;
int index;
......@@ -76,7 +76,7 @@ void update_auto_plot(AutoPlot *auto_plot, double value, char* label)
}
else // add a new curve
{
auto_plot->label_curves[nb] = label;
auto_plot->label_curves[nb] = (char*) label;
auto_plot->y_curves[nb] = value;
auto_plot->nb++;
......@@ -91,7 +91,7 @@ void update_auto_plot(AutoPlot *auto_plot, double value, char* label)
* \param[in] label label of the curve
* \return index of the curve, -1 if not known
*/
int index_plot_string(AutoPlot *auto_plot, char* label)
int index_plot_string(AutoPlot *auto_plot, const char* label)
{
int i;
......
......@@ -27,8 +27,8 @@ typedef struct AutoPlot
// functions prototypes
AutoPlot* init_auto_plot(int max_nb);
void free_auto_plot(AutoPlot *auto_plot);
void update_auto_plot(AutoPlot *auto_plot, double value, char* label);
int index_plot_string(AutoPlot *auto_plot, char* label);
void update_auto_plot(AutoPlot *auto_plot, double value, const char* label);
int index_plot_string(AutoPlot *auto_plot, const char* label);
#endif
#endif
#include "set_plot.h"
#ifdef SDL
#include "auto_plot.h"
static AutoPlot *auto_plot; // static AutoPlot structure with all the current user plots information
int flag_plot = 0; ///< 1 if init_set_plot was called, 0 otherwise
/*! \brief initialize the static auto_plot structure
*
* \param[in,out] screen_sdl SDL gestion main structure
*/
void init_set_plot(Screen_sdl *screen_sdl)
{
flag_plot = 1;
auto_plot = init_auto_plot(screen_sdl->max_nb_curves);
screen_sdl->auto_plot = auto_plot;
}
/*! \brief release memory of auto_plot
*/
void free_set_plot()
{
if (flag_plot)
{
free_auto_plot(auto_plot);
}
}
/*! \brief function called by the user to plot a curve
*
* \param[in] value current value of the curve
* \param[in] label label of the curve
*/
void set_plot(double value, char* label)
{
if (flag_plot)
{
update_auto_plot(auto_plot, value, label);
}
}
#endif
#include "set_plot.h"
#ifdef SDL
#include "auto_plot.h"
static AutoPlot *auto_plot; // static AutoPlot structure with all the current user plots information
int flag_plot = 0; ///< 1 if init_set_plot was called, 0 otherwise
/*! \brief initialize the static auto_plot structure
*
* \param[in,out] screen_sdl SDL gestion main structure
*/
void init_set_plot(Screen_sdl *screen_sdl)
{
flag_plot = 1;
auto_plot = init_auto_plot(screen_sdl->max_nb_curves);
screen_sdl->auto_plot = auto_plot;
}
/*! \brief release memory of auto_plot
*/
void free_set_plot()
{
if (flag_plot)
{
free_auto_plot(auto_plot);
}
}
/*! \brief function called by the user to plot a curve
*
* \param[in] value current value of the curve
* \param[in] label label of the curve
*/
void set_plot(double value, const char* label)
{
if (flag_plot)
{
update_auto_plot(auto_plot, value, label);
}
}
#endif
/*!
* \author Nicolas Van der Noot
* \file set_plot.h
* \brief set_plot function called by the user to plot a curve
*/
#ifndef _SET_PLOT_H_
#define _SET_PLOT_H_
#include "user_realtime.h"
#ifdef SDL
#include "plot_sdl.h"
void init_set_plot(Screen_sdl *screen_sdl);
void free_set_plot();
#endif
#endif
/*!
* \author Nicolas Van der Noot
* \file set_plot.h
* \brief set_plot function called by the user to plot a curve
*/
#ifndef _SET_PLOT_H_
#define _SET_PLOT_H_
//#include "user_realtime.h"
#include "mbsysc_realtime_export.h"
#include "plot_sdl.h"
#include "set_plot2.h"
#ifdef SDL
MBSYSC_REALTIME_EXPORT void init_set_plot(Screen_sdl *screen_sdl);
MBSYSC_REALTIME_EXPORT void free_set_plot();
#endif
#endif
#ifndef _SET_PLOT2_H_
#define _SET_PLOT2_H_
#include "mbsysc_realtime_export.h"
#ifdef __cplusplus
extern "C" {
#endif
MBSYSC_REALTIME_EXPORT void set_plot(double value, const char* label);
#ifdef __cplusplus
}
#endif
#endif
\ No newline at end of file
......@@ -23,7 +23,7 @@
#endif
#include "mbs_data.h"
#include "user_realtime.h"
//#include "user_realtime.h"
// y axis: main parts
#define SCREEN_UP_HEIGHT_LOSS 40
......
#ifndef _USER_REALTIME_H_
#define _USER_REALTIME_H_
#ifdef REAL_TIME
#include "mbs_data.h"
#include "realtime.h"
#include <stdint.h>