Robotran C Documentation
Classes | Enumerations | Functions
mbs_saver.h File Reference

Declare required stuffs to update mbs files from MbsData state and user wishes. More...

#include "mbs_data.h"

Go to the source code of this file.

Classes

struct  UpdateInline
 Define modification to be done on a inline. More...
 
struct  UpdateShape
 Define modifications to be done on a basic shape. More...
 
struct  ExtForces_3D
 Define 3D field for showing an external force sensor. More...
 
struct  UpdateExtForces
 Define modifications to be done on external forces, or new to add. More...
 
struct  UpdateLinkForces
 Define modifications to be done on link force (1D), or new to add. More...
 
struct  UserUpdates
 

Enumerations

enum  {
  SHAPE_NONE, SHAPE_BOX, SHAPE_CYLINDER, SHAPE_CONE,
  SHAPE_SPHERE
}
 

Functions

int mbs_update (MbsData *mbs_data, UserUpdates *user_update, const char *filename_in, const char *filename_out, int verbose)
 Open the specified MBS file, update it and save it on the specified name. More...
 
int mbs_synchronize (MbsData *mbs_data, MbsLoader *mbs_loader)
 Synchronize the value of the loaded MBS with the data in the computed MBS. More...
 
int mbs_update_user (UserUpdates *user_update, MbsLoader *mbs_loader)
 Synchronize the value of the loaded MBS with user specific modification. More...
 
int mbs_save (const char *filename, MbsLoader *mbs_loader)
 Save the mbs_info to disk. More...
 
int mbs_data_to_info (MbsData *mbs_data, MbsLoader *mbs_loader)
 Update the MbsInfos with the given MbsData. More...
 
UserUpdatesmbs_update_new_user ()
 Allocate and initialize an user update structure. More...
 
void mbs_update_free_user (UserUpdates *uu)
 Free the provided user update structure. More...
 
UpdateInlinembs_update_new_inline ()
 Initialize and allocate an inline shape modification structure. More...
 
void mbs_update_free_inline (UpdateInline *ui)
 Free the provided inline shape modification structure. More...
 
int mbs_update_insert_inline (UserUpdates *user_update, int on_base, const char *body_name, const char *shape_name, const char *shape_url, double position[3], double scale[3], double rotation[3], double transparency, int prj_relative_url, int visible)
 Insert instruction to update the content of a visualization inline shape. More...
 
UpdateShapembs_update_new_shape ()
 Initialize and allocate an 3D shape modification structure. More...
 
void mbs_update_free_shape (UpdateShape *ui)
 Free the provided 3D shape modification structure. More...
 
int mbs_update_insert_shape (UserUpdates *user_update, int on_base, const char *body_name, const char *shape_name, int shape_nature, double size[3], double *radius, double *height, double position[3], double scale[3], double rotation[3], double transparency, int visible)
 Insert instruction to update the content of a visualization 3D shape. More...
 
ExtForces_3Dmbs_update_new_extforce_3d (int show, int show_x, int show_y, int show_z, int show_resultant, int position_at_end, int color_x[3], int color_y[3], int color_z[3], int color_resultant[3], double diameter, double scale)
 Allocate and initialize a external force/torque visualization parameter. More...
 
void mbs_update_free_link (UpdateLinkForces *link)
 Free the provided link forces modifications structure. More...
 
int mbs_update_insert_link (UserUpdates *user_update, const char *name, const char *first_body, const char *first_point, const char *second_body, const char *second_point, int visible)
 Insert instruction to update the content of an link force. More...
 
ExtForces_3Dmbs_update_dup_extforce_3d (ExtForces_3D *orig, int new_col_x[3], int new_col_y[3], int new_col_z[3], int new_col_res[3])
 Clone an existing 3D forces visualization and apply the colors change. More...
 
void mbs_update_free_extforce_3d (ExtForces_3D *force_3d)
 Free the provided 3D force visualization structure. More...
 
UpdateExtForcesmbs_update_new_extforce ()
 Initialize and allocate an external force modification structure. More...
 
void mbs_update_free_extforce (UpdateExtForces *force)
 Free the provided external forces modifications structure. More...
 
int mbs_update_insert_extforce (UserUpdates *user_update, int on_base, const char *body_name, const char *point_name, char *name, int comp_position, int comp_rotation, int comp_velocity, int comp_acceleration, int comp_jacobian, ExtForces_3D *force_3d, ExtForces_3D *torque_3d)
 Insert instruction to update the content of an external force. More...
 

Detailed Description

Declare required stuffs to update mbs files from MbsData state and user wishes.

Date
Aug. 2023
Author
Robotran Team

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
SHAPE_NONE 
SHAPE_BOX 
SHAPE_CYLINDER 
SHAPE_CONE 
SHAPE_SPHERE 

Function Documentation

◆ mbs_data_to_info()

int mbs_data_to_info ( MbsData mbs_data,
MbsLoader mbs_loader 
)

Update the MbsInfos with the given MbsData.

Parameters
[out]mbs_infosThe structure to be updated.
[in]mbs_dataThe structure containing the data.
Returns
MBS_INFO_SUCCESS or MBS_INFO_FAILURE

◆ mbs_save()

int mbs_save ( const char *  filename,
MbsLoader mbs_loader 
)

Save the mbs_info to disk.

Parameters
[in]filenameName of the file to be written.
[out]mbs_infosPointer to the Mbs state.
Returns
MBS_INFO_SUCCESS or a specific MBSysC error code.

◆ mbs_synchronize()

int mbs_synchronize ( MbsData mbs_data,
MbsLoader mbs_loader 
)

Synchronize the value of the loaded MBS with the data in the computed MBS.

The user model are not updated!

Parameters
[in]mbs_dataPointer to the system state to be considered.
[out]mbs_loaderPointer to the Mbs loader with data to be updated.
Returns
MBS_INFO_SUCCESS or MBS_INFO_FAILURE

◆ mbs_update()

int mbs_update ( MbsData mbs_data,
UserUpdates user_update,
const char *  filename_in,
const char *  filename_out,
int  verbose 
)

Open the specified MBS file, update it and save it on the specified name.

The user model are not updated!

If the input and output mbs_file matches, the file will be replaced inplace.

The extension of the files must matches.

Parameters
[in]mbs_dataPointer to the system state to be saved.
[in]user_updatePointer to the modification that are not related to the computation fields stored in MbsData. Can be NULL.
[in]filename_inName of the mbs file to be loaded.
[in]filename_outName of the mbs file to be written. If NULL is provided, filename_in is considered.
[in]verboseVerbosity level, from only errors (0) to full verbose (2).
Returns
MBS_INFO_SUCCESS or MBS_INFO_FAILURE

◆ mbs_update_dup_extforce_3d()

ExtForces_3D* mbs_update_dup_extforce_3d ( ExtForces_3D orig,
int  new_col_x[3],
int  new_col_y[3],
int  new_col_z[3],
int  new_col_res[3] 
)

Clone an existing 3D forces visualization and apply the colors change.

Parameters
[in]origThe source structure to be cloned.
[in]new_col_xOptional, the new RGB colors (between 0-255) of the vector along x axis. Set NULL to avoid any modification from the source.
[in]new_col_yOptional, the new RGB colors (between 0-255) of the vector along y axis. Set NULL to avoid any modification from the source.
[in]new_col_zOptional, the new RGB colors (between 0-255) of the vector along z axis. Set NULL to avoid any modification from the source.
[in]new_col_resOptional, the new RGB colors (between 0-255) of the resultant vector. Set NULL to avoid any modification from the source.
Returns
The cloned and modified 3D forces visualization structure.

◆ mbs_update_free_extforce()

void mbs_update_free_extforce ( UpdateExtForces force)

Free the provided external forces modifications structure.

Parameters
[in,out]forceThe memory to be freed.

◆ mbs_update_free_extforce_3d()

void mbs_update_free_extforce_3d ( ExtForces_3D force_3d)

Free the provided 3D force visualization structure.

Should not be called by the user: the pointer is stored in the UserUpdates when provided to the function mbs_update_insert_extforce(). Then it is freed with the UserUpdates structure.

Parameters
[in,out]force_3dThe memory to be freed.

◆ mbs_update_free_inline()

void mbs_update_free_inline ( UpdateInline ui)

Free the provided inline shape modification structure.

Parameters
[in,out]uiThe memory to be freed.

◆ mbs_update_free_link()

void mbs_update_free_link ( UpdateLinkForces link)

Free the provided link forces modifications structure.

Parameters
[in,out]forceThe memory to be freed.

◆ mbs_update_free_shape()

void mbs_update_free_shape ( UpdateShape ui)

Free the provided 3D shape modification structure.

Parameters
[in,out]uiThe memory to be freed.

◆ mbs_update_free_user()

void mbs_update_free_user ( UserUpdates uu)

Free the provided user update structure.

Parameters
[in,out]uuThe memory to be freed.

◆ mbs_update_insert_extforce()

int mbs_update_insert_extforce ( UserUpdates user_update,
int  on_base,
const char *  body_name,
const char *  point_name,
char *  name,
int  comp_position,
int  comp_rotation,
int  comp_velocity,
int  comp_acceleration,
int  comp_jacobian,
ExtForces_3D force_3d,
ExtForces_3D torque_3d 
)

Insert instruction to update the content of an external force.

A new external force sensor can be created if the value of UserUpdates::allow_new is True.

WARNING: MEMORY POINTER FOR FORCE/TORQUE VISUALIZATION CANNOT BE PROVIDED TO MULTIPLE CALL OF THE FUNCTION. DOING SO WILL LEAD TO UNDEFINED BEHAVIOR. THE PROVIDED MEMORY WILL BE FREED ALONGSIDE WITH THE UserUpdates STRUCTURE. FREEING THEM OUTSIDE WILL LEAD TO UNDEFINED BEHAVIOR.

Parameters
[in,out]user_updatePointer to the structure collecting all modification to be done on the model.
[in]on_baseIf the shape is not on the base body set the flag to 0. Otherwise set to 1, and then the body_name is disregarded.
[in]body_nameThe name of the body on which the force sensor is placed. Can be NULL if the shape is on the base.
[in]point_nameThe name of the point, on the body, on which the sensor is located. If the sensor is at the origin of the body (not on a anchor point), set the name as "origin".
[in]nameThe name of the external force sensor. In case of adding new sensor(s), the name must be unique (not checked by the function). Specifying a sensor with an existing name will lead to undefined behavior at model loading and simulation execution.
[in]comp_positionOptional, enable the symbolic generation of sensor position if greater than 0. Disable it if set to 0. Set it to a negative value to avoid any modification.
[in]comp_rotationOptional, enable the symbolic generation of sensor rotation if greater than 0. Disable it if set to 0. Set it to a negative value to avoid any modification.
[in]comp_velocityOptional, enable the symbolic generation of sensor velocity if greater than 0. Disable it if set to 0. Set it to a negative value to avoid any modification.
[in]comp_accelerationOptional, enable the symbolic generation of sensor acceleration if greater than 0. Disable it if set to 0. Set it to a negative value to avoid any modification.
[in]comp_jacobianOptional, enable the symbolic generation of sensor Jacobian matrix if greater than 0. Disable it if set to 0. Set it to a negative value to avoid any modification.
[in,out]force_3dOptional, structure specifying the visualization parameters of the forces vectors. The memory pointed is set in the UserUpdates structure and will be freed automatically. The same memory provided multiple time will lead to UNDEFINED behavior. Set to NULL to avoid modification.
[in,out]torque_3dOptional, structure specifying the visualization parameters of the forces vectors. The memory pointed is set in the UserUpdates structure and will be freed automatically. The same memory provided multiple time will lead to UNDEFINED behavior. Set to NULL to avoid modification.
Returns
MBS_INFO_FAILURE for error, MBS_INFO_SUCCESS for success.

◆ mbs_update_insert_inline()

int mbs_update_insert_inline ( UserUpdates user_update,
int  on_base,
const char *  body_name,
const char *  shape_name,
const char *  shape_url,
double  position[3],
double  scale[3],
double  rotation[3],
double  transparency,
int  prj_relative_url,
int  visible 
)

Insert instruction to update the content of a visualization inline shape.

A new inline can be created if the value of UserUpdates::allow_new is True.

Parameters
[in,out]user_updatePointer to the structure collecting all modification to be done on the model.
[in]on_baseIf the shape is not on the base body set the flag to 0. Otherwise set to 1, and then the body_name is disregarded.
[in]body_nameThe name of the body on which the shape is placed. Can be NULL if the shape is on the base.
[in]shape_nameThe name of the shape.
[in]shape_urlOptional, the filepath to the inline file. If the path is relative to the project path, set prj_relative_url and do not start the path with a path separator (ie: "/"). Set to NULL to keep existing file/url.
[in]positionOptional, array of size 3 containing the new x, y, z position of the shape on the body. Provide NULL to avoid any modification.
[in]scaleOptional, array of size 3 containing the new x, y, z scale of the shape on the body. Provide NULL to avoid any modification.
[in]rotationOptional, array of size 3 containing the new rotation around x, y, z axis of the shape on the body. The rotation are in radians. Provide NULL to avoid any modification.
[in]transparencyOptional, the transparency value of the shape, 1 is fully transparent, 0 is fully visible. Set a negative value to avoid any modification.
[in]prj_relative_urlSet to 1 if the provided shape_url is a relative path from the project path. Then "PRJPATH/" is append to the provided url. Set to 0 if no modification to the url is required.
[in]visibleOptional, the visibility flag of the shape: 1 is visible while 0 is invisible. Set a negative value to avoid any modification.
Returns
MBS_INFO_FAILURE for error, MBS_INFO_SUCCESS for success.

◆ mbs_update_insert_link()

int mbs_update_insert_link ( UserUpdates user_update,
const char *  name,
const char *  first_body,
const char *  first_point,
const char *  second_body,
const char *  second_point,
int  visible 
)

Insert instruction to update the content of an link force.

A new link force can be created if the value of UserUpdates::allow_new is True. Changing the ends of the link force also requires to set this flag.

Parameters
[in,out]user_updatePointer to the structure collecting all modification to be done on the model.
[in]nameThe name of the link force. In case of adding new link(s), the name must be unique (not checked by the function). Specifying a link with an existing name will lead to undefined behavior at model loading and simulation execution.
[in]first_bodyName of the body located at the first extremity.
[in]first_pointName of the point located at the first extremity.
[in]second_bodyName of the body located at the second extremity.
[in]second_pointName of the point located at the second extremity.
[in]visibleFlag to set the visible property of the link in the 3D visualization.
Returns
MBS_INFO_FAILURE for error, MBS_INFO_SUCCESS for success.

◆ mbs_update_insert_shape()

int mbs_update_insert_shape ( UserUpdates user_update,
int  on_base,
const char *  body_name,
const char *  shape_name,
int  shape_nature,
double  size[3],
double *  radius,
double *  height,
double  position[3],
double  scale[3],
double  rotation[3],
double  transparency,
int  visible 
)

Insert instruction to update the content of a visualization 3D shape.

The specified shape must already exists with the same shape (box, sphere...). If multiple shape with the same name and nature exist, only the first found is modified.

Parameters
[in,out]user_updatePointer to the structure collecting all modification to be done on the model.
[in]on_baseIf the shape is not on the base body set the flag to 0. Otherwhise set to 1, and then the body_name is disregarded.
[in]body_nameThe name of the body on which the shape is placed. Can be NULL if the shape is on the base.
[in]shape_nameThe name of the shape.
[in]shape_natureThe nature of the shape among:
  • SHAPE_BOX
  • SHAPE_CYLINDER
  • SHAPE_CONE
  • SHAPE_SPHERE
[in]sizeOptional, set to NULL to avoid any modification. Disregarded for all shape except boxes. This is the size of the box along x, y and z axis
[in]radiusOptional, set to NULL to avoid any modification. Disregarded for boxes. This is the size of the radius of the shape (sphere, cone base, cylinder).
[in]heightOptional, set to NULL to avoid any modification. Disregarded for boxes and spheres. This is the length of the cylinder or the cone.
[in]positionOptional, array of size 3 containing the new x, y, z position of the shape on the body. Provide NULL to avoid any modification.
[in]scaleOptional, array of size 3 containing the new x, y, z scale of the shape on the body. Provide NULL to avoid any modification.
[in]rotationOptional, array of size 3 containing the new rotation around x, y, z axis of the shape on the body. The rotation are in radians. Provide NULL to avoid any modification.
[in]transparencyOptional, the transparency value of the shape, 1 is fully transparent, 0 is fully visible. Set a negative value to avoid any modification.
[in]visibleOptional, the visibility flag of the shape: 1 is visible while 0 is invisible. Set a negative value to avoid any modification.
Returns
MBS_INFO_FAILURE for error, MBS_INFO_SUCCESS for success.

◆ mbs_update_new_extforce()

UpdateExtForces* mbs_update_new_extforce ( )

Initialize and allocate an external force modification structure.

This function should not be called directly. The function mbs_update_insert_extforce() do the same but also check for mandatory fields.

Returns
An empty allocated structure for external forces modifications.

◆ mbs_update_new_extforce_3d()

ExtForces_3D* mbs_update_new_extforce_3d ( int  show,
int  show_x,
int  show_y,
int  show_z,
int  show_resultant,
int  position_at_end,
int  color_x[3],
int  color_y[3],
int  color_z[3],
int  color_resultant[3],
double  diameter,
double  scale 
)

Allocate and initialize a external force/torque visualization parameter.

An unique pointer/structure must be provided for each visualization of torque or force for each external force in the function mbs_update_insert_extforce(). Then the memory will be freed when freeing the UserUpdates structure.

Use mbs_update_dup_extforce_3d() to easily duplicate your force/torque visualization structure.

Parameters
[in]showOptional, flag to disable general vector visualization. Set a negative value to avoid any modification.
[in]show_xOptional, flag to disable visualization of vector along x axis. Set a negative value to avoid any modification.
[in]show_yOptional, flag to disable visualization of vector along y axis. Set a negative value to avoid any modification.
[in]show_zOptional, flag to disable visualization of vector along z axis. Set a negative value to avoid any modification.
[in]show_resultantOptional, flag to disable visualization of resultant vector. Set a negative value to avoid any modification.
[in]position_at_endOptional, if true the tip of the vectors are on the sensor, otherwise the tail are on the sensor. Set a negative value to avoid any modification.
[in]color_xOptional, the RGB colors (between 0-255) of the vector along x axis. Set NULL to avoid any modification.
[in]color_yOptional, the RGB colors (between 0-255) of the vector along y axis. Set NULL to avoid any modification.
[in]color_zOptional, the RGB colors (between 0-255) of the vector along z axis. Set NULL to avoid any modification.
[in]color_resultantOptional, the RGB colors (between 0-255) of the resultant vector. Set NULL to avoid any modification.
[in]diameterOptional, the diameter of the vector. Set zero to avoid any modification.
[in]scaleOptional, the scale between the force/torque value and the length of the vector. Set zero to avoid any modification.
Returns
An initialized 3D forces visualization structure.

◆ mbs_update_new_inline()

UpdateInline* mbs_update_new_inline ( )

Initialize and allocate an inline shape modification structure.

This function should not be called directly. The function mbs_update_insert_inline() do the same but also check for mandatory fields.

Returns
An empty allocated structure for inline shape modifications.

◆ mbs_update_new_shape()

UpdateShape* mbs_update_new_shape ( )

Initialize and allocate an 3D shape modification structure.

This function should not be called directly. The function mbs_update_insert_shape() do the same but also check for mandatory fields.

Returns
An empty allocated structure for 3D shape modifications.

◆ mbs_update_new_user()

UserUpdates* mbs_update_new_user ( )

Allocate and initialize an user update structure.

Returns
Pointer to the initialized memory.

◆ mbs_update_user()

int mbs_update_user ( UserUpdates user_update,
MbsLoader mbs_loader 
)

Synchronize the value of the loaded MBS with user specific modification.

The updatable values are limited to the values that does not interfere with the body dynamics. Such values are not stored in the MbsData structure.

Parameters
[in]user_updatePointer to the user modifications be considered.
[out]mbs_loaderPointer to the Mbs loader with data to be updated.
Returns
MBS_INFO_SUCCESS or MBS_INFO_FAILURE