libhybrid
A library for discretized Hybrid Dynamical Systems
Functions
libhybrid.c File Reference
#include "libhybrid.h"

Go to the source code of this file.

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...
 

Detailed Description

Author
Matteo Ragni, Matteo Cocetti
Date
10 Jan 2018

Definition in file libhybrid.c.

Function Documentation

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.

Warning
This is for internal use only, do not use directly. This callback has been implemented in order to respond to rk4_ode requirements.
Parameters
dxoutput of the callback
tauhybrid time step, is probably different with respect to the evolution time
xthe current state, contains time and jump state
uthe current control
pthe parameter vector of vectors
voptsa void pointer for user space, is used for passing by the options struct

Definition at line 66 of file libhybrid.c.

66  {
67  dx[0] = 1.0;
68  dx[1] = 0.0;
69  HYB_GET_OPTS(vopts)->F(dx + 2, x[0], x[1], x + 2, u, p);
70 }
#define HYB_GET_OPTS(S)
Definition: libhybrid.h:255
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:

  1. Check if stop criteria is reached
  2. Check if the jump conditions are respected.
    • if jump is requsted, it enters a loop of update until no jump should be performed
    • else the execution continues
  3. The
    Parameters
    optspointer to an option structure
    yvector that will contain the next output. It must be already allocated
    xpvector that will contain the next state (already integrated in case of flowing step). It must be already allocated
    tauintegration engine time
    xcurrent state
    ucurrent input
    pparameter vector
    Returns
    an exit codes, as described in hyb_errorcode

Definition at line 31 of file libhybrid.c.

31  {
32 
33  opts->Y(y, x[0], x[1], x + 2, u, p);
34 
35  if (x[0] >= opts->T_horizon)
36  return HYB_TLIMIT;
37  if (x[1] >= opts->J_horizon)
38  return HYB_JLIMIT;
39 
40  hyb_bool d = opts->D(x[0], x[1], x + 2, u, p);
41  #if HYB_JUMP_LOGIC == 2
42  hyb_bool c = opts->C(x[0], x[1], x + 2, u, p);
43  #endif
44 
45  hyb_bool it_jumps;
46  #if HYB_JUMP_LOGIC == 1
47  it_jumps = d;
48  #elif HYB_JUMP_LOGIC == 2
49  it_jumps = d && !c;
50  #endif
51 
52  if (it_jumps) {
53  xp[0] = x[0];
54  xp[1] = x[1] + 1.0;
55  opts->J(xp + 2, x[0], x[1], x + 2, u, p);
56  } else {
57  rk4_opts rk4_o = { opts->Ts, (opts->x_size + 2), hyb_flow_map_wrapper };
58  rk4_errorcode rk4_ret = rk4(&rk4_o, xp, tau, x, u, p, HYB_SEND_OPTS(opts));
59  if (rk4_ret) {
60  return (hyb_errorcode)rk4_ret;
61  }
62  }
63  return HYB_SUCCESS;
64 }
size_t x_size
Definition: libhybrid.h:244
hyb_errorcode
Definition: libhybrid.h:258
hyb_float J_horizon
Definition: libhybrid.h:247
hyb_jump_map J
Definition: libhybrid.h:249
hyb_jump_set D
Definition: libhybrid.h:251
hyb_bool
libhybrid boolean type is actually an enum
Definition: libhybrid.h:73
hyb_float T_horizon
Definition: libhybrid.h:246
hyb_out_map Y
Definition: libhybrid.h:250
#define HYB_SEND_OPTS(S)
Definition: libhybrid.h:256
hyb_flow_set C
Definition: libhybrid.h:252
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.
Definition: libhybrid.c:66
hyb_float Ts
Definition: libhybrid.h:245