Robotran C Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Classes | Macros | Functions | Variables
visu_websocket.cc File Reference
#include "mbs_path.h"
#include "mbs_define.h"
#include "mbs_message.h"
#include "useful_functions.h"
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <iostream>
#include <string>
#include <sstream>
#include <chrono>
#include <thread>
#include <sys/time.h>
#include <ctime>
#include "visu_websocket.h"
#include <fcntl.h>
#include <ws.h>

Classes

struct  VisuIn
 input of the 3D window More...
 

Macros

#define MSG_ERR   ">> REALTIME >> "
 
#define MSG_PRE   " >> "
 

Functions

void onopen (ws_cli_conn_t *c)
 This function is called whenever a new connection is opened. More...
 
void onclose (ws_cli_conn_t *client)
 This function is called whenever a connection is closed. More...
 
void onmessage (ws_cli_conn_t *client, const unsigned char *msg, uint64_t size, int type)
 Message events goes here. More...
 
int init_websocket (Realtime_visu *visu, MbsData *mbs_data, int nb_models, int *nb_q, double **q_vec, char **mbs_file, char *mbsz_path, int start_viewpoint, int init_break)
 Initialize the communication with the webserver. More...
 
void joints_update (Simu_realtime *realtime, int nb_models, int *nb_q, double **q_vec)
 update the joint values for visualization More...
 
void pause_routine (Simu_realtime *realtime)
 
void update_websocket (Simu_realtime *realtime)
 
void update_plot (Simu_realtime *realtime, double tsim)
 
void free_websocket (void *visu_class)
 close the socket connection More...
 

Variables

static uint8_t key_states [KEYS_LEN]
 
static ws_cli_conn_t * client
 
static bool is_connected = false
 
static bool is_updated = false
 
static Simu_realtimert
 
bool pause_sim = false
 
static char * project_data
 
long project_data_size
 
VisuInvisu_in
 
double t_last_update = 0
 main update loop for the visualization More...
 
static double t_last_plot = 0
 update the realtime plot data More...
 

Macro Definition Documentation

◆ MSG_ERR

#define MSG_ERR   ">> REALTIME >> "

◆ MSG_PRE

#define MSG_PRE   " >> "

Function Documentation

◆ free_websocket()

void free_websocket ( void *  visu_class)

close the socket connection

Parameters
[in]visudata

◆ init_websocket()

int init_websocket ( Realtime_visu visu,
MbsData mbs_data,
int  nb_models,
int *  nb_q,
double **  q_vec,
char **  mbs_file,
char *  mbsz_file,
int  start_viewpoint,
int  init_break 
)

Initialize the communication with the webserver.

The simulation starts in pause or runing according to the option in MbsData::realtime::options::init_break.

Parameters
[in]visuThe visualization structure, describing the project.
[in]mbs_dataThe multibody system, used to retrieve realtime options.
[in]nb_modelsThe number of multibody system in the simulation.
[in]nb_qThe number of joint in each multibody system.
[in]q_vecThe initial joints value for each multibody system.
[in]mbs_fileThe multibody files to be loaded.
[in]mbsz_pathThe multibody project file at mbsz project.
[in]start_viewpointThe initia viewpoint index.
[in]init_breakInitialize the simulation paused (!0) or running (1).
Returns
MBS_INFO_SUCCESS, MBS_INFO_WARNING (no mbsz file provided) or MBS_INFO_FAILURE (macro in "mbs_define.h").

◆ joints_update()

void joints_update ( Simu_realtime realtime,
int  nb_models,
int *  nb_q,
double **  q_vec 
)

update the joint values for visualization

◆ onclose()

void onclose ( ws_cli_conn_t *  client)

This function is called whenever a connection is closed.

Parameters
clientClient connection.

◆ onmessage()

void onmessage ( ws_cli_conn_t *  client,
const unsigned char *  msg,
uint64_t  size,
int  type 
)

Message events goes here.

Parameters
clientClient connection.
msgMessage content.
sizeMessage size.
typeMessage type.

◆ onopen()

void onopen ( ws_cli_conn_t *  c)

This function is called whenever a new connection is opened.

Parameters
clientClient connection.

◆ pause_routine()

void pause_routine ( Simu_realtime realtime)

◆ update_plot()

void update_plot ( Simu_realtime realtime,
double  tsim 
)

◆ update_websocket()

void update_websocket ( Simu_realtime realtime)

Variable Documentation

◆ client

ws_cli_conn_t* client
static

◆ is_connected

bool is_connected = false
static

◆ is_updated

bool is_updated = false
static

◆ key_states

uint8_t key_states[KEYS_LEN]
static

◆ pause_sim

bool pause_sim = false

◆ project_data

char* project_data
static

◆ project_data_size

long project_data_size

◆ rt

Simu_realtime* rt
static

◆ t_last_plot

double t_last_plot = 0
static

update the realtime plot data

◆ t_last_update

double t_last_update = 0

main update loop for the visualization

◆ visu_in

VisuIn* visu_in