hysteresis_model
RK4Integrator.hpp
Go to the documentation of this file.
1 /*
2  * PURPOSE --- Header file for a class for a 4'th order Runge-Kutta
3  * method for solving a system of n first order differential equations.
4  * If the initial equation is in the form of n'th order differential equation
5  * it must be converted to a system of n first order differential
6  * equations.
7  *
8  */
9 
10 #ifndef RK4_INTEGRATOR_HPP
11 #define RK4_INTEGRATOR_HPP
12 
13 #include <stdlib.h>
14 #include <vector>
15 
16 class RK4_SIM
17 {
18  public:
19  // Constructor
20  // The arguments are self-explanatory
21  // If you specify initial conditions, the parameter _initial_state
22  // should point to a vector of size _plant_order, so that correct
23  // initialization could be performed.
24  RK4_SIM(int _plant_order,
25  int _ctrl_order,
26  double _integration_step = 0.0001,
27  double _initial_time = 0.0,
28  double *_initial_state = NULL);
29 
30  // Destructor
31  virtual ~RK4_SIM();
32 
33  // Initilaizes simulation parameters
34  void init_param(double _integration_step,
35  double _initial_time,
36  double *_initial_state);
37 
38  void solve (void); // Performs one step simulation
39 
40  // DERIV contains the dynamic equations of the system in the
41  // form: xdot = f(t,x,u); arguments are the time t, present state
42  // values x, the present control value u, and values of the derivatives
43  // of the states xdot (calculated inside of the funtcion).
44  // It is overloaded in the derived class!!!
45  virtual void DERIV(const double t, const double *x,
46  const double *u, double *xdot) {};
47 
48  protected:
49  int plant_order; // Num of plant states
50  int ctrl_order; // Num of control inputs
51  double integration_step; // Integration step size
52 
53  public:
54 
55  std::vector<double> plant_state; // Current System states
56  std::vector<double> ctrl_input; // Current Controller output
57 
58  double current_time; // Current time
59  int rk4_sim_err; // Variable to hold an error number
60 
61  private:
62  std::vector<double> f1;
63  std::vector<double> f2;
64  std::vector<double> f3;
65  std::vector<double> f4;
66  std::vector<double> temp; // Runge-Kutta Coefficients
67 
68  // Functions which calculate RK coefficients
69  inline void F1 (void);
70  inline void F2 (void);
71  inline void F3 (void);
72  inline void F4 (void);
73 };
74 #endif
75 
76 
void solve(void)
Definition: RK4Integrator.cpp:77
Definition: RK4Integrator.hpp:16
std::vector< double > plant_state
Definition: RK4Integrator.hpp:55
int ctrl_order
Definition: RK4Integrator.hpp:50
int plant_order
Definition: RK4Integrator.hpp:46
int rk4_sim_err
Definition: RK4Integrator.hpp:59
double current_time
Definition: RK4Integrator.hpp:58
virtual void DERIV(const double t, const double *x, const double *u, double *xdot)
Definition: RK4Integrator.hpp:45
double integration_step
Definition: RK4Integrator.hpp:51
void init_param(double _integration_step, double _initial_time, double *_initial_state)
Definition: RK4Integrator.cpp:48
virtual ~RK4_SIM()
Definition: RK4Integrator.cpp:45
RK4_SIM(int _plant_order, int _ctrl_order, double _integration_step=0.0001, double _initial_time=0.0, double *_initial_state=NULL)
Definition: RK4Integrator.cpp:27
std::vector< double > ctrl_input
Definition: RK4Integrator.hpp:56