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
36void
37GMRDynamics::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
54void
55GMRDynamics::setStateTarget(MathLib::Vector state, MathLib::Vector target)
56{
57 setTarget(target);
58 setState(state);
59}
60
61void
62GMRDynamics::setTarget(MathLib::Vector target, double target_t)
63{
64 this->target_t = target_t;
65
66 //gXi += (this->target - target);
67 this->target = target;
68}
69
70MathLib::Vector
72{
73 return target;
74}
75
76double
78{
79 return target_t;
80}
81
82void
83GMRDynamics::setState(MathLib::Vector state)
84{
85 gXi = state;
86}
87
88MathLib::Vector
90{
91 return gXi;
92}
93
94void
96{
97 this->current_t = current_t;
98}
99
100double
102{
103 return current_t;
104}
105
106MathLib::Vector
108{
109 return GMM->Regression(x);
110}
111
112MathLib::Vector
114{
115 return getNextState(1.0);
116}
117
118MathLib::Vector
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
129double
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}
#define REACHING_ITERATION_MAX
Definition GMRDynamics.h:17
#define INTEGRATION_L
Definition GMRDynamics.h:16
#define GMR_ERROR_TOLERANCE
Definition GMRDynamics.h:15
MathLib::Vector getVelocity(MathLib::Vector x)
void setStateTarget(MathLib::Vector state, MathLib::Vector target)
double getCurrentTime(void)
void setTarget(MathLib::Vector target, double target_t=-1.0)
double getReachingTime(double lamda)
void initGMR(int first_inindex, int last_inindex, int first_outindex, int last_outindex)
void setCurrentTime(double current_t)
MathLib::Vector getTarget(void)
MathLib::Vector getState(void)
GMRDynamics(int nStates, int nVar, double delta_t, const char *f_mu, const char *f_sigma, const char *f_prio)
MathLib::Vector getNextState(void)
void setState(MathLib::Vector state)
double getTargetT(void)
This file offers overloads of toIce() and fromIce() functions for STL container types.