Commit 3ad862ba authored by Timothee Habra's avatar Timothee Habra
Browse files

use function pointer to remove dependency of mbs realtime to user fct

parent 95893499
......@@ -22,6 +22,7 @@ extern "C" {
#include "realtime.h"
#include "cmake_config.h"
#include "mbs_project_interface.h"
#include "user_realtime.h"
#ifdef __cplusplus
}
#endif
......@@ -98,6 +99,21 @@ void mbs_get_project_functions(MbsData *mbs_data)
mbs_data->user_cons_hJ = user_cons_hJ;
mbs_data->user_cons_jdqd = user_cons_jdqd;
#ifdef REAL_TIME
mbs_data->user_realtime_options = user_realtime_options;
#ifdef SDL
mbs_data->user_keyboard = user_keyboard;
mbs_data->user_realtime_plot = user_realtime_plot;
mbs_data->user_joystick_axes = user_joystick_axes;
mbs_data->user_joystick_buttons = user_joystick_buttons;
#endif
#ifdef JAVA
mbs_data->user_realtime_visu = user_realtime_visu;
#endif
#endif
// symbolic function pointers
mbs_data->mbs_link = mbs_link;
mbs_data->mbs_link3D = mbs_link3D;
......
......@@ -190,7 +190,7 @@ void update_java(Simu_realtime *realtime)
java = realtime->ext->java;
mbs_data = realtime->ext->mbs_data;
user_realtime_visu(mbs_data, java->nb_q, java->cur_q);
mbs_data->user_realtime_visu(mbs_data, java->nb_q, java->cur_q);
if (java->visu_past_flag)
{
......
......@@ -52,7 +52,7 @@ void update_past_visu(Simu_realtime *realtime, double tsim)
// update the time
tsim_save[min_tsim_index] = tsim;
user_realtime_visu(mbs_data, nb_q, cur_q);
mbs_data->user_realtime_visu(mbs_data, nb_q, cur_q);
// update the vectors
for (i=0; i<nb_q; i++)
......
......@@ -47,7 +47,7 @@ void mbs_realtime_init(MbsData* mbs_data, double t0, double tf, double dt0)
options->dt0 = dt0;
options->nb_q = mbs_data->njoint;
user_realtime_options(options);
mbs_data->user_realtime_options(options);
check_user_realtime_options(options);
compute_buffer_size(options);
......@@ -132,7 +132,7 @@ void mbs_realtime_loop(Simu_realtime *realtime, double tsim)
if (realtime->flag_plot)
{
// assign values for the plot
user_realtime_plot(mbs_data);
mbs_data->user_realtime_plot(mbs_data);
// check maximal values for the plot
update_y_min_max(realtime);
......
......@@ -37,7 +37,7 @@ typedef struct Realtime_extern
/*! \brief user real-time option
*/
typedef struct Realtime_option
struct Realtime_option
{
// simulation
double t0; ///< initial simulation time [s]
......@@ -80,7 +80,7 @@ typedef struct Realtime_option
double fqc_visu; ///< frequence of the java visualization refreshment [Hz]
} Realtime_option;
};
/*! \brief one constraint strcuture
*/
......@@ -94,7 +94,7 @@ typedef struct Realtime_constraint
/*! \brief real-time structure
*/
typedef struct Simu_realtime
struct Simu_realtime
{
// flags
int simu_quit; ///< 1 to quit the simulation, 0 otherwise
......@@ -142,7 +142,7 @@ typedef struct Simu_realtime
Realtime_option *options; ///< user options
} Simu_realtime;
};
// -- Functions prototypes -- //
......
......@@ -149,7 +149,7 @@ Realtime_java* init_realtime_java(void *realtime_options, MbsData* mbs_data)
}
}
user_realtime_visu(mbs_data, nb_q, java->cur_q);
mbs_data->user_realtime_visu(mbs_data, nb_q, java->cur_q);
java->jni_struct = init_jni(nb_q, java->cur_q, options->mbs_file, options->start_viewpoint);
......
......@@ -40,7 +40,7 @@ void events_sdl(Simu_realtime *realtime, int cur_t_usec)
realtime_sdl = realtime->ext->sdl;
mbs_data = realtime->ext->mbs_data;
screen_sdl = realtime_sdl->screen_sdl;
screen_sdl = (Screen_sdl*) realtime_sdl->screen_sdl;
// -- Handles the events -- //
......@@ -52,11 +52,11 @@ void events_sdl(Simu_realtime *realtime, int cur_t_usec)
if (cur_t_usec >= realtime_sdl->next_user_keyboard_event_usec)
{
// user keyboard
user_keyboard(mbs_data, realtime, cur_t_usec, keystates);
mbs_data->user_keyboard(mbs_data, realtime, cur_t_usec, keystates);
}
// user joystick axes
user_joystick_axes(mbs_data, realtime, screen_sdl->nb_joysticks);
mbs_data->user_joystick_axes(mbs_data, realtime, screen_sdl->nb_joysticks);
// get event (if any)
if (SDL_PollEvent(&event))
......@@ -67,7 +67,7 @@ void events_sdl(Simu_realtime *realtime, int cur_t_usec)
// joystick button pressed
case SDL_JOYBUTTONDOWN:
user_joystick_buttons(mbs_data, event.jbutton.button);
mbs_data->user_joystick_buttons(mbs_data, event.jbutton.button);
break;
......@@ -447,7 +447,7 @@ double get_Joystick_axis(int joystickID, int axisID, Simu_realtime *realtime)
Screen_sdl *screen_sdl;
screen_sdl = realtime->ext->sdl->screen_sdl;
screen_sdl = (Screen_sdl*) realtime->ext->sdl->screen_sdl;
if (joystickID >= screen_sdl->nb_joysticks)
{
......
......@@ -130,6 +130,22 @@ struct MbsData
user_cons_hJ_ptr user_cons_hJ;
user_cons_jdqd_ptr user_cons_jdqd;
#ifdef REAL_TIME
user_realtime_options_ptr user_realtime_options;
#ifdef SDL
user_keyboard_ptr user_keyboard;
user_realtime_plot_ptr user_realtime_plot;
user_joystick_axes_ptr user_joystick_axes;
user_joystick_buttons_ptr user_joystick_buttons;
#endif
#ifdef JAVA
user_realtime_visu_ptr user_realtime_visu;
#endif
#endif
// symbolic function pointers
mbs_link_ptr mbs_link;
mbs_link3D_ptr mbs_link3D;
......
......@@ -17,6 +17,29 @@ typedef void (*user_DrivenJoints_ptr)(MbsData *s, double tsim);
typedef void (*user_cons_hJ_ptr)(double *h, double **Jac, MbsData *s, double tsim);
typedef void (*user_cons_jdqd_ptr)(double *jdqd, MbsData *s, double tsim);
#ifdef REAL_TIME
typedef struct Realtime_option Realtime_option;
typedef void (*user_realtime_options_ptr)(Realtime_option *options);
#ifdef SDL
typedef struct Simu_realtime Simu_realtime;
typedef unsigned __int8 uint8_t; // copied from sdl header
typedef uint8_t Uint8; // copied from sdl header
typedef void (*user_keyboard_ptr)(MbsData* mbs_data, Simu_realtime *realtime, int cur_t_usec, const Uint8 *keystates);
typedef void (*user_realtime_plot_ptr)(MbsData* mbs_data);
typedef void (*user_joystick_axes_ptr)(MbsData* mbs_data, Simu_realtime *realtime, int nb_joysticks);
typedef void (*user_joystick_buttons_ptr)(MbsData* mbs_data, int buttonID);
#endif
#ifdef JAVA
typedef void (*user_realtime_visu_ptr)(MbsData* mbs_data, int nb_q, double *q_vec);
#endif
#endif
typedef void (*mbs_link_ptr)(double **frc,double **trq,double *Flnk,double *Z,double *Zd,MbsData *s, double tsim);
typedef void (*mbs_link3D_ptr)(double **frc,double **trq, MbsData *s, double tsim);
......
Supports Markdown
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