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