|
Robotran C Documentation
|
Go to the documentation of this file.
9 #ifndef _PLOT_SDL_H_INCLUDED_
10 #define _PLOT_SDL_H_INCLUDED_
15 #include "SDL_opengl.h"
25 #define SCREEN_UP_HEIGHT_LOSS 40
26 #define SCREEN_BOTTOM_HEIGHT_LOSS 40
27 #define PLOT_Y_START SCREEN_UP_HEIGHT_LOSS
30 #define SCREEN_WIDTH_LOSS 60
31 #define PLOT_X_START 0
32 #define X_ERASE_WIDTH SCREEN_WIDTH_LOSS
35 #define UP_FIRST_Y_INDICATIONS (SCREEN_UP_HEIGHT_LOSS / 3)
36 #define UP_SECOND_Y_INDICATIONS (UP_FIRST_Y_INDICATIONS + ((3*SCREEN_UP_HEIGHT_LOSS) / 8))
37 #define UP_SEPARATION_INDICATION ((UP_FIRST_Y_INDICATIONS + UP_SECOND_Y_INDICATIONS) / 2)
38 #define UP_COLOR_WIDTH_LABEL 15
39 #define UP_COLOR_SPACE_LABEL 5
40 #define UP_COLOR_WIDTH_LOSS_BEGIN (UP_COLOR_SPACE_LABEL + UP_COLOR_SPACE_LABEL + 40)
41 #define UP_COLOR_WIDTH_LOSS_END 20
44 #define LEGEND_SIGNAL_SCALING_X_POS 10
45 #define SIGNAL_SCALING_X_POS 22
46 #define LEGEND_PLOT_SCALING_X_POS 45
47 #define PLOT_SCALING_X_POS 57
48 #define LEGEND_PLOT_MOVE_X_POS_1 93
49 #define LEGEND_PLOT_MOVE_X_POS_1_BIS 110
50 #define LEGEND_PLOT_MOVE_X_POS_2 118
51 #define PLOT_MOVE_X_POS_1 105
52 #define PLOT_MOVE_X_POS_2 130
53 #define LEGEND_SWITCH_HOR_VERT_X_POS 138
54 #define SWITCH_HOR_VERT_X_POS 165
55 #define LEGEND_XY_LABEL_X_POS 210
56 #define XY_LABEL_X_POS 250
57 #define LEGEND_TIME_SPEED_X_POS 385
58 #define TIME_SPEED_X_POS 425
59 #define VISU_PAST_X_POS_1 535
60 #define VISU_PAST_X_POS_2 550
61 #define VISU_PAST_X_POS_3 557
62 #define LEGEND_SPEED_X_POS 580
63 #define SPEED_X_POS 592
64 #define LEGEND_QUIT_X_POS 620
65 #define QUIT_X_POS 632
68 #define FONT_AXIS_SIZE 12
69 #define FONT_LABEL_SIZE 12
70 #define FONT_SMALL_LABEL_SIZE 10
71 #define FONT_SCALING 25
72 #define FONT_ARROWS 15
73 #define FONT_PLAY_BREAK 14
74 #define FONT_HOR_MOUSE 25
80 #define X_LABEL_HEIGHT 10
81 #define X_LABEL_SHIFT_X 2
82 #define X_LABEL_SHIFT_Y 0
86 #define Y_LABEL_WIDTH 10
87 #define Y_LABEL_SHIFT_X 3
88 #define Y_LABEL_SHIFT_Y 2
89 #define Y_LABEL_SHIFT_Y_START (Y_LABEL_SHIFT_Y + 9)
90 #define Y_LABEL_SHIFT_Y_END (Y_LABEL_SHIFT_Y - 10)
92 #define STR_LABEL_MIN 1.0e-9
95 #define PLOT_SCALE_MAX 4.0
96 #define SCALING_MULT_THRESHOLD 4.0
97 #define SCALING_PLOT_TOO_SMALL 0.0
98 #define SCALING_PLOT_TOO_HIGH 0.4
99 #define SCALING_PLOT_OPTIMAL_INCREASE 0.25
100 #define SCALING_PLOT_OPTIMAL_DECREASE 0.15
101 #define SCALING_NUL_DIFF 4.0
102 #define MANUAL_SCALING_PLOT 0.5
103 #define MANUAL_OFFSET_PLOT 0.25
106 #define NUL_AXIS_DASH_WIDTH 8
107 #define X_AXIS_NB_Y_PIXELS_WIDTH 2
108 #define START_VECTOR 12345
111 #define WHEEL_MOUSE_FACTOR 0.9 // [-]
112 #define FQC_MOUSE 30.0 // frequence of the SDL window refresh when using the mouse for translations [Hz]
113 #define TIME_RELEASE_MOUSE_PLOT (1e6 / FQC_MOUSE) // [us]
115 #define TIME_MOUSE_DELAY 5e4
122 typedef struct Screen_sdl
129 TTF_Font *font_label;
130 TTF_Font *font_small_label;
132 TTF_Font *font_scaling;
133 TTF_Font *font_arrows;
135 TTF_Font *font_hor_mouse;
136 TTF_Font *font_mouse;
137 TTF_Font *font_break;
138 TTF_Font *font_speed;
141 SDL_Color text_color;
148 int plot_auto_scaling;
149 int signal_auto_scaling;
150 int last_plot_auto_scaling;
151 int last_signal_auto_scaling;
152 int hor_plot_scaling;
155 int last_x_label_flag;
158 int increase_plot_y_diff_flag;
159 int decrease_plot_y_diff_flag;
161 int bottom_plot_y_flag;
162 int increase_plot_x_diff_flag;
163 int decrease_plot_x_diff_flag;
164 int left_plot_y_flag;
165 int right_plot_y_flag;
168 int last_scaling_flag;
170 int x_label_print_count;
171 int change_mouse_wheel_flag;
175 int flag_buffer_round;
185 double last_y_min, last_y_max;
186 double last_legend_y_min, last_legend_y_max;
187 double last_legend_x_min, last_legend_x_max;
198 int screen_plot_width;
204 int screen_plot_height;
208 int bottom_mid_y_indications;
209 int scaling_indications;
210 int x_axis_indication;
211 int y_axis_indication;
212 int speed_indication_1;
213 int speed_indication_2;
214 int legend_speed_indication_1;
215 int legend_speed_indication_2;
216 int scaling_bottom_indications;
217 int scaling_bottom_arrow_indications_1;
218 int scaling_bottom_arrow_indications_2;
219 int scaling_bottom_arrow_indications_3;
220 int scaling_up_indications;
221 int scaling_up_indications_2;
223 int *scaling_expo_mult;
224 int *last_scaling_expo_mult;
225 int *pixel_pos_label;
230 double *previous_y_vec;
231 double *scaling_offset;
232 double *last_scaling_offset;
243 SDL_Joystick **joysticks;
250 void wait_key_generic(
Simu_realtime *realtime,
int cur_t_usec,
double tsim);
253 void new_curves_save(Screen_sdl *screen_sdl,
int nb_new_curves,
double *y_curves);
254 TTF_Font* init_font(
char *folder,
int font_size,
int *err);
255 void free_screen_sdl(Screen_sdl *screen_sdl);
257 int log_SDL_error(
char *SDL_function);
258 void SDL_set_color(Screen_sdl *screen_sdl,
int color_num);
259 int refresh_screen(Screen_sdl *screen_sdl);
260 void draw_pixel(SDL_Renderer *ren,
int i,
int j);
261 void draw_rectangle(SDL_Renderer *ren,
int x1,
int x2,
int y1,
int y2);
262 void draw_horizontal_line(SDL_Renderer *ren,
int x1,
int x2,
int y);
263 void draw_vertical_line(SDL_Renderer *ren,
int x,
int y1,
int y2);
264 void print_text_sdl(
char *str, TTF_Font *font, SDL_Color txt_col, SDL_Renderer *ren,
int x,
int y,
int pos_flag);
265 void renderTexture(SDL_Texture *tex, SDL_Renderer *ren,
int x,
int y,
int pos_flag);
266 SDL_Texture* renderText(TTF_Font *font,
char *message, SDL_Color text_color, SDL_Renderer *ren);
269 void update_scale_signals(Screen_sdl *screen_sdl,
Simu_realtime *realtime,
int screen_flag);
270 void update_full_vectors(
Simu_realtime *realtime,
double tsim);
271 void update_x_min_max(Screen_sdl *screen_sdl,
Simu_realtime *realtime);
273 void update_y_tab(Screen_sdl *screen_sdl);
274 void update_sdl_legend(
Simu_realtime *realtime,
int new_nb_legends);
275 double bound_diff_min_max(
double min_thres,
double max_thres,
double cur_min,
double cur_max,
double cur_move,
int sign_flag);
276 void mouse_sdl(Screen_sdl *screen_sdl,
Simu_realtime *realtime,
double tsim,
int mouse_flag);
279 void str_scaling(
char *str,
int scaling_expo_mult,
double scaling_offset);
280 int str_label(
char *str,
double low_nb,
double high_nb);
281 void str_axis(
char *str,
double nb,
int expo);
283 void limit_x_limits(Screen_sdl *screen_sdl);
284 double scale_signal(
double no_scale_nb,
int scaling_expo_mult,
double scaling_offset);
285 double unscale_signal(
double scale_nb,
int scaling_expo_mult,
double scaling_offset);
287 void plot_screen_sdl(
Simu_realtime *realtime,
double tsim,
int screen_flag);
291 int last_break_gestion(
Simu_realtime *realtime,
double tsim);
useful functions used by the real-time modules
double real_simu_speed_factor
real speed factor
Definition: realtime.h:109
@ WHITE_SDL
Definition: color_sdl.h:18
@ LIGHT_GREEN_SDL
Definition: color_sdl.h:19
int simu_break
1 to make a break, 0 otherwise
Definition: realtime.h:103
user real-time option
Definition: realtime.h:42
#define NB_COLORS_INIT_SDL
number of initial colors (not available to the user)
Definition: color_sdl.h:14
int screen_width
plot screen width in number of pixels
Definition: realtime.h:61
int max_nb_legends
maximum number of curves legends indicated
Definition: realtime.h:65
functions used to automatically update the user curves plotted
@ BLUE_SDL
Definition: color_sdl.h:18
@ LIGHT_BLUE_SDL
Definition: color_sdl.h:19
int init_t_sec
initial real time [s], without us
Definition: realtime.h:122
Java functions used for the visualization.
@ LIGHT_GRAY_SDL
Definition: color_sdl.h:18
#define _MBS_ERR_MOD_SPEC_13
Generic error number Module specific errors range from -10 to -19 please read the error message a...
Definition: mbs_errors_names.h:174
@ DARK_GREEN_SDL
Definition: color_sdl.h:18
double last_real_simu_speed_factor
last real speed factor
Definition: realtime.h:110
@ PINK_SDL
Definition: color_sdl.h:19
@ TURQUOISE_SDL
Definition: color_sdl.h:18
#define NB_COLORS_SDL
number of colors available to the user
Definition: color_sdl.h:12
double t0
initial simulation time [s]
Definition: realtime.h:116
#define SAFETY_TIME
safety time: difference between min and max time in case of problems [s]
Definition: realtime_ext.h:16
@ GREEN_SDL
Definition: color_sdl.h:19
set_plot function called by the user to plot a curve
void update_realtime_constraints_break(Simu_realtime *realtime, int delta_break_u_sec)
update the real-time constraints after a break
Definition: realtime.c:952
void mbs_msg(char *msg,...)
Send a message.
Definition: mbs_message.c:76
double y_max_init
initial upper bound for the y values plotted
Definition: realtime.h:68
Realtime_extern * ext
external variables
Definition: realtime.h:143
main SDL functions (plot curves and handles keyboard, joystick... inputs)
@ YELLOW_SDL
Definition: color_sdl.h:19
double tf
final simulation time [s]
Definition: realtime.h:117
functions used to get the time expressed in us (micro seconds)
@ BLACK_SDL
Definition: color_sdl.h:18
double y_min_init
initial lower bound for the y values plotted
Definition: realtime.h:67
@ DARK_YELLOW_SDL
Definition: color_sdl.h:19
@ ORANGE_SDL
Definition: color_sdl.h:19
#define NB_COLORS_TOT_SDL
total number of colors
Definition: color_sdl.h:13
int curve_width
plot curve width in number of pixels
Definition: realtime.h:60
int t_usec(int init_t_sec, int init_t_usec)
return the elapsed time (in us) since time 'init_t' (expressed in s and us)
Definition: time_functions.c:25
@ RED_SDL
Definition: color_sdl.h:18
interface to call C++ functions from C code
void guess_tsim_index(double request_tsim, double *tsim_save, int min_ind, int max_ind, double min_tsim, double max_tsim, int buffer_size, int flag_round, int *prev_ind, int *next_ind)
get the indexes for a requested time on a turning vector of time values
Definition: realtime_functions.c:17
double tsim
current simulation time [s]
Definition: realtime.h:114
colors description, used for the SDL plots
int first_break
1 if during the first break, 0 otherwise
Definition: realtime.h:139
int buffer_size
size of the buffer for 3D and sdl
Definition: realtime.h:53
int expo_ten_inf(double nb)
get log with base 10
Definition: useful_functions.c:89
Real-time constraints main header.
real-time structure
Definition: realtime.h:99
double t0
initial simulation time [s]
Definition: realtime.h:45
int screen_height
plot screen height in number of pixels
Definition: realtime.h:62
int max_nb_curves
maximum number of curves plotted
Definition: realtime.h:64
int speed_last_t_usec
last real time [us], to compute the simulation speed
Definition: realtime.h:126
int simu_speed_flag
used to compute the simulation factor
Definition: realtime.h:105
double pow_int(double basis, int expo)
compute efficiently pow with an integer exponent
Definition: useful_functions.c:60
@ PURPLE_SDL
Definition: color_sdl.h:18
double get_simu_speed_factor(int simu_speed_flag)
get simulation factor depending on the 'simu_speed_flag' flag
Definition: realtime.c:903
int init_t_usec
initial real time [us], without s (kind of modulo)
Definition: realtime.h:123
double fqc_screen
frequence of the SDL plots refreshment [Hz]
Definition: realtime.h:72
int flag_visu
1 if Java visualization features activated, 0 otherwise
Definition: realtime.h:137
double last_tsim
last simulation time [s]
Definition: realtime.h:113
int color_tab[NB_COLORS_SDL]
colors of the curves
Definition: realtime.h:70