GMRDynamics.cpp
Go to the documentation of this file.
1 /*
2  * GMRDynamics.cpp
3  *
4  * Created on: Nov 20, 2011
5  * Author: Seungsu KIM
6  */
7 
8 #include "GMRDynamics.h"
9 
10 #include <math.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 
14 
16  int nVar,
17  double delta_t,
18  const char* f_mu,
19  const char* f_sigma,
20  const char* f_prio)
21 {
22  this->delta_t = delta_t;
23  GMM = new Gaussians(nStates, nVar, f_mu, f_sigma, f_prio);
24 }
25 
27  int nVar,
28  double delta_t,
29  const vector<double> pri_vec,
30  const vector<double> mu_vec,
31  const vector<double> sig_vec)
32 {
33  this->delta_t = delta_t;
34  GMM = new Gaussians(nStates, nVar, pri_vec, mu_vec, sig_vec);
35 }
36 
37 
38 void
39 GMRDynamics::initGMR(int first_inindex, int last_inindex, int first_outindex, int last_outindex)
40 {
41  GMM->InitFastGMR(first_inindex, last_inindex, first_outindex, last_outindex);
42 
43  gDim = last_inindex - first_inindex + 1;
44  if (gDim != static_cast<unsigned int>(last_outindex - first_outindex + 1))
45  {
46  cout << "dynamics dimension is not matching" << endl;
47  }
48 
49  gXi.Resize(gDim);
50  target.Resize(gDim);
51 
52  gXi.Zero();
53  target.Zero();
54 }
55 
56 void
58 {
59  setTarget(target);
60  setState(state);
61 }
62 
63 void
65 {
66  this->target_t = target_t;
67 
68  //gXi += (this->target - target);
69  this->target = target;
70 }
71 
74 {
75  return target;
76 }
77 
78 double
80 {
81  return target_t;
82 }
83 
84 void
86 {
87  gXi = state;
88 }
89 
92 {
93  return gXi;
94 }
95 
96 void
97 GMRDynamics::setCurrentTime(double current_t)
98 {
99  this->current_t = current_t;
100 }
101 
102 double
104 {
105  return current_t;
106 }
107 
110 {
111  return GMM->Regression(x);
112 }
113 
114 
117 {
118  return getNextState(1.0);
119 }
120 
123 {
124  // target time
125  target_t -= (delta_t * lamda);
126 
127  gXi += (getVelocity(gXi - target) * (delta_t * lamda));
128 
129  return gXi;
130 }
131 
132 double
134 {
135  unsigned int frame = 0;
136  unsigned int li = 0;
137  MathLib::Vector xi(3);
138  xi.Set(gXi);
139 
140  for (frame = 0; frame < REACHING_ITERATION_MAX; frame++)
141  {
142  for (li = 0; li < INTEGRATION_L; li++)
143  {
144  xi += getVelocity(xi - target) * delta_t / (double)INTEGRATION_L * lamda;
145 
146  if ((xi - target).Norm() < GMR_ERROR_TOLERANCE)
147  {
148  return (double)(frame * INTEGRATION_L + li) * delta_t / (double)INTEGRATION_L;
149  }
150  }
151  }
152  return (double)(frame * INTEGRATION_L + li) * delta_t / (double)INTEGRATION_L;
153 }
GMRDynamics::setCurrentTime
void setCurrentTime(double current_t)
Definition: GMRDynamics.cpp:97
GMRDynamics::getState
MathLib::Vector getState(void)
Definition: GMRDynamics.cpp:91
GMRDynamics::getTarget
MathLib::Vector getTarget(void)
Definition: GMRDynamics.cpp:73
Vector
Eigen::Matrix< T, 3, 1 > Vector
Definition: UnscentedKalmanFilterTest.cpp:36
GMR_ERROR_TOLERANCE
#define GMR_ERROR_TOLERANCE
Definition: GMRDynamics.h:14
GMRDynamics::setState
void setState(MathLib::Vector state)
Definition: GMRDynamics.cpp:85
GMRDynamics::getNextState
MathLib::Vector getNextState(void)
Definition: GMRDynamics.cpp:116
boost::target
Vertex target(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:688
Gaussians
Definition: Gaussians.h:43
GMRDynamics::getCurrentTime
double getCurrentTime(void)
Definition: GMRDynamics.cpp:103
GMRDynamics::getTargetT
double getTargetT(void)
Definition: GMRDynamics.cpp:79
GMRDynamics::GMRDynamics
GMRDynamics(int nStates, int nVar, double delta_t, const char *f_mu, const char *f_sigma, const char *f_prio)
Definition: GMRDynamics.cpp:15
INTEGRATION_L
#define INTEGRATION_L
Definition: GMRDynamics.h:15
GMRDynamics::setTarget
void setTarget(MathLib::Vector target, double target_t=-1.0)
Definition: GMRDynamics.cpp:64
GMRDynamics::getVelocity
MathLib::Vector getVelocity(MathLib::Vector x)
Definition: GMRDynamics.cpp:109
GMRDynamics::setStateTarget
void setStateTarget(MathLib::Vector state, MathLib::Vector target)
Definition: GMRDynamics.cpp:57
REACHING_ITERATION_MAX
#define REACHING_ITERATION_MAX
Definition: GMRDynamics.h:16
Gaussians::InitFastGMR
void InitFastGMR(int first_inindex, int last_inindex, int first_outindex, int last_outindex)
Definition: Gaussians.cpp:290
GMRDynamics::initGMR
void initGMR(int first_inindex, int last_inindex, int first_outindex, int last_outindex)
Definition: GMRDynamics.cpp:39
GMRDynamics.h
GMRDynamics::getReachingTime
double getReachingTime(double lamda)
Definition: GMRDynamics.cpp:133
Gaussians::Regression
void Regression(const MathLib::Vector &indata, MathLib::Vector &outdata, MathLib::Matrix &derGMR)
Definition: Gaussians.cpp:348