libhybrid
A library for discretized Hybrid Dynamical Systems
|
#include "librk4.h"
Go to the source code of this file.
Data Structures | |
struct | hyb_opts |
Options structure for the hybrid system. More... | |
Macros | |
#define | HYB_FLOAT_TYPE double |
#define | RK4_FLOAT_TYPE HYB_FLOAT_TYPE |
#define | HYB_JUMP_LOGIC 1 |
Jump logic implementation. More... | |
#define | HYB_GET_OPTS(S) ((hyb_opts *)S) |
#define | HYB_SEND_OPTS(S) ((void *)S) |
Typedefs | |
typedef HYB_FLOAT_TYPE | hyb_float |
typedef enum hyb_bool | hyb_bool |
libhybrid boolean type is actually an enum More... | |
typedef void(* | hyb_flow_map) (hyb_float *xdot, hyb_float t, hyb_float j, const hyb_float *x, const hyb_float *u, const hyb_float **p) |
Callback definition for the Flow Map. More... | |
typedef void(* | hyb_jump_map) (hyb_float *xp, hyb_float t, hyb_float j, const hyb_float *x, const hyb_float *u, const hyb_float **p) |
Callback definition for the Jump Map. More... | |
typedef hyb_bool(* | hyb_jump_set) (hyb_float t, hyb_float j, const hyb_float *x, const hyb_float *u, const hyb_float **p) |
Callback definition for the Jump Set. More... | |
typedef hyb_bool(* | hyb_flow_set) (hyb_float t, hyb_float j, const hyb_float *x, const hyb_float *u, const hyb_float **p) |
Callback definition for the Flow Set. More... | |
typedef void(* | hyb_out_map) (hyb_float *y, hyb_float t, hyb_float j, const hyb_float *x, const hyb_float *u, const hyb_float **p) |
typedef struct hyb_opts | hyb_opts |
Options structure for the hybrid system. More... | |
typedef enum hyb_errorcode | hyb_errorcode |
Enumerations | |
enum | hyb_bool { hyb_false = 0, hyb_true } |
libhybrid boolean type is actually an enum More... | |
enum | hyb_errorcode { HYB_SUCCESS = 0, HYB_EMALLOC, HYB_NULLPTR, HYB_GENERIC, HYB_TLIMIT, HYB_JLIMIT, HYB_NOJUMP } |
Functions | |
hyb_errorcode | hyb_main_loop (hyb_opts *opts, hyb_float *y, hyb_float *xp, hyb_float tau, const hyb_float *x, const hyb_float *u, const hyb_float **p) |
Hybrid system main loop. More... | |
void | hyb_flow_map_wrapper (hyb_float *dx, hyb_float tau, const hyb_float *x, const hyb_float *u, const hyb_float **p, void *vopts) |
Internal callback for discretization step. More... | |
struct hyb_opts |
Options structure for the hybrid system.
Definition at line 242 of file libhybrid.h.
Data Fields | ||
---|---|---|
hyb_flow_set | C |
Flow set function pointer |
hyb_jump_set | D |
Jump set function pointer |
hyb_flow_map | F |
Flow map function pointer |
hyb_jump_map | J |
Jump map function pointer |
hyb_float | J_horizon |
Maximum discrete step horizon |
hyb_float | T_horizon |
Maximum continuous time horizon |
hyb_float | Ts |
Time step |
size_t | x_size |
State size |
hyb_out_map | Y |
Output map function pointer |
size_t | y_size |
Output size |
#define HYB_FLOAT_TYPE double |
Precision defaut is double
Definition at line 60 of file libhybrid.h.
#define HYB_GET_OPTS | ( | S | ) | ((hyb_opts *)S) |
Converts the void pointer in option struct pointer. For internal use only
Definition at line 255 of file libhybrid.h.
#define HYB_JUMP_LOGIC 1 |
Jump logic implementation.
There are two possible jump logic implementation:
Definition at line 236 of file libhybrid.h.
#define HYB_SEND_OPTS | ( | S | ) | ((void *)S) |
Converts the option struct in void pointer. For internal use only
Definition at line 256 of file libhybrid.h.
#define RK4_FLOAT_TYPE HYB_FLOAT_TYPE |
Forcing consistent types
Definition at line 64 of file libhybrid.h.
libhybrid boolean type is actually an enum
This enum is the returned value for the Jump Set function and the Flow Set function.
typedef enum hyb_errorcode hyb_errorcode |
typedef HYB_FLOAT_TYPE hyb_float |
Precision typedef, used in library
Definition at line 62 of file libhybrid.h.
typedef void(* hyb_flow_map) (hyb_float *xdot, hyb_float t, hyb_float j, const hyb_float *x, const hyb_float *u, const hyb_float **p) |
Callback definition for the Flow Map.
The callback stores the output in the first pointer (xdot). The function does not need to allocate nor free the output vector, but may overflow if exceedes the dimension that is declared in the hyb_opts structure. Please notice that this function will be discretized in a Runge Kutta 4 integrator: librk4.h. When accessing an element of the parameter, please remember that the implementation keeps in mind a MATLAB-like interface. If the parameters (in MATLAB) are passed like:
then, in the C code, p1, p2 and p3 may be accessed in p as:
xdot | an array in which the result will be stored |
t | is the current time |
j | is the discrete time |
x | a constant array with the current state |
u | a constant array with current input |
p | a pointer to arrays of parameters. This allows the compatibility with the MATLAB System Identification Toolbox |
Definition at line 107 of file libhybrid.h.
typedef hyb_bool(* hyb_flow_set) (hyb_float t, hyb_float j, const hyb_float *x, const hyb_float *u, const hyb_float **p) |
Callback definition for the Flow Set.
The callback should return hyb_true if the combination of state, input and parameters enters the flow set. When accessing an element of the parameter, please remember that the implementation keeps in mind a MATLAB-like interface. If the parameters (in MATLAB) are passed like:
then, in the C code, p1, p2 and p3 may be accessed in p as:
t | is the current time |
j | is the discrete time |
x | a constant array with the current state |
u | a constant array with current input |
p | a pointer to arrays of parameters. This allows the compatibility with the MATLAB System Identification Toolbox |
Definition at line 223 of file libhybrid.h.
typedef void(* hyb_jump_map)(hyb_float *xp, hyb_float t, hyb_float j, const hyb_float *x, const hyb_float *u, const hyb_float **p) |
Callback definition for the Jump Map.
Callback definition for the Output Map.
The callback stores the output in the first pointer (xp). The function does not need to allocate nor free the output vector, but may overflow if exceedes the dimension that is declared in the hyb_opts structure. When accessing an element of the parameter, please remember that the implementation keeps in mind a MATLAB-like interface. If the parameters (in MATLAB) are passed like:
then, in the C code, p1, p2 and p3 may be accessed in p as:
xp | an array in which the result will be stored |
t | is the current time |
j | is the discrete time |
x | a constant array with the current state |
u | a constant array with current input |
p | a pointer to arrays of parameters. This allows the compatibility with the MATLAB System Identification Toolbox |
The callback stores the output in the first pointer (y). The function does not need to allocate nor free the input vector, but may overflow if exceedes the dimension that is declared in the hyb_opts structure. When accessing an element of the parameter, please remember that the implementation keeps in mind a MATLAB-like interface. If the parameters (in MATLAB) are passed like:
then, in the C code, p1, p2 and p3 may be accessed in p as:
xp | an array in which the result will be stored |
t | is the current time |
j | is the discrete time |
x | a constant array with the current state |
u | a constant array with current input |
p | a pointer to arrays of parameters. This allows the compatibility with the MATLAB System Identification Toolbox |
Definition at line 137 of file libhybrid.h.
typedef hyb_bool(* hyb_jump_set) (hyb_float t, hyb_float j, const hyb_float *x, const hyb_float *u, const hyb_float **p) |
Callback definition for the Jump Set.
The callback should return hyb_true if the combination of state, input and parameters enters the jump set. When accessing an element of the parameter, please remember that the implementation keeps in mind a MATLAB-like interface. If the parameters (in MATLAB) are passed like:
then, in the C code, p1, p2 and p3 may be accessed in p as:
t | is the current time |
j | is the discrete time |
x | a constant array with the current state |
u | a constant array with current input |
p | a pointer to arrays of parameters. This allows the compatibility with the MATLAB System Identification Toolbox |
Definition at line 195 of file libhybrid.h.
typedef void(* hyb_out_map) (hyb_float *y, hyb_float t, hyb_float j, const hyb_float *x, const hyb_float *u, const hyb_float **p) |
Definition at line 226 of file libhybrid.h.
enum hyb_bool |
libhybrid boolean type is actually an enum
This enum is the returned value for the Jump Set function and the Flow Set function.
Enumerator | |
---|---|
hyb_false |
False value |
hyb_true |
True value |
Definition at line 73 of file libhybrid.h.
enum hyb_errorcode |
Definition at line 258 of file libhybrid.h.
void hyb_flow_map_wrapper | ( | hyb_float * | dx, |
hyb_float | tau, | ||
const hyb_float * | x, | ||
const hyb_float * | u, | ||
const hyb_float ** | p, | ||
void * | vopts | ||
) |
Internal callback for discretization step.
dx | output of the callback |
tau | hybrid time step, is probably different with respect to the evolution time |
x | the current state, contains time and jump state |
u | the current control |
p | the parameter vector of vectors |
vopts | a void pointer for user space, is used for passing by the options struct |
Definition at line 66 of file libhybrid.c.
hyb_errorcode hyb_main_loop | ( | hyb_opts * | opts, |
hyb_float * | y, | ||
hyb_float * | xp, | ||
hyb_float | tau, | ||
const hyb_float * | x, | ||
const hyb_float * | u, | ||
const hyb_float ** | p | ||
) |
Hybrid system main loop.
The main loop of the hybrid system performs the following operations:
opts | pointer to an option structure |
y | vector that will contain the next output. It must be already allocated |
xp | vector that will contain the next state (already integrated in case of flowing step). It must be already allocated |
tau | integration engine time |
x | current state |
u | current input |
p | parameter vector |
Definition at line 31 of file libhybrid.c.