1 |
|
|
#ifndef COSTFUNCTION_H |
2 |
|
|
#define COSTFUNCTION_H |
3 |
|
|
|
4 |
|
|
#include <Eigen/Core> |
5 |
|
|
|
6 |
|
|
template <typename precision, int stateSize, int commandSize> |
7 |
|
|
class CostFunction { |
8 |
|
|
public: |
9 |
|
|
typedef Eigen::Matrix<precision, stateSize, 1> stateVec_t; // 1 x stateSize |
10 |
|
|
typedef Eigen::Matrix<precision, 1, stateSize> |
11 |
|
|
stateVecTrans_t; // 1 x stateSize |
12 |
|
|
typedef Eigen::Matrix<precision, stateSize, stateSize> |
13 |
|
|
stateMat_t; // stateSize x stateSize |
14 |
|
|
typedef Eigen::Matrix<precision, stateSize, stateSize> |
15 |
|
|
stateTens_t[stateSize]; // stateSize x stateSize x stateSize |
16 |
|
|
|
17 |
|
|
// typedef for commandSize types |
18 |
|
|
typedef Eigen::Matrix<precision, commandSize, 1> |
19 |
|
|
commandVec_t; // commandSize x 1 |
20 |
|
|
typedef Eigen::Matrix<precision, 1, commandSize> |
21 |
|
|
commandVecTrans_t; // 1 x commandSize |
22 |
|
|
typedef Eigen::Matrix<precision, commandSize, commandSize> |
23 |
|
|
commandMat_t; // commandSize x commandSize |
24 |
|
|
typedef Eigen::Matrix<precision, commandSize, commandSize> |
25 |
|
|
commandTens_t[commandSize]; // stateSize x commandSize x commandSize |
26 |
|
|
|
27 |
|
|
// typedef for mixed stateSize and commandSize types |
28 |
|
|
typedef Eigen::Matrix<precision, stateSize, commandSize> |
29 |
|
|
stateR_commandC_t; // stateSize x commandSize |
30 |
|
|
typedef Eigen::Matrix<precision, stateSize, commandSize> |
31 |
|
|
stateR_commandC_stateD_t[stateSize]; // stateSize x commandSize x |
32 |
|
|
// stateSize |
33 |
|
|
typedef Eigen::Matrix<precision, stateSize, commandSize> |
34 |
|
|
stateR_commandC_commandD_t[commandSize]; // stateSize x commandSize x |
35 |
|
|
// commandSize |
36 |
|
|
typedef Eigen::Matrix<precision, commandSize, stateSize> |
37 |
|
|
commandR_stateC_t; // commandSize x stateSize |
38 |
|
|
typedef Eigen::Matrix<precision, commandSize, stateSize> |
39 |
|
|
commandR_stateC_stateD_t[stateSize]; // commandSize x stateSize x |
40 |
|
|
// stateSize |
41 |
|
|
typedef Eigen::Matrix<precision, commandSize, stateSize> |
42 |
|
|
commandR_stateC_commandD_t[commandSize]; // commandSize x stateSize x |
43 |
|
|
// commandSize |
44 |
|
|
typedef Eigen::Matrix<precision, stateSize, stateSize> |
45 |
|
|
stateR_stateC_commandD_t[commandSize]; // stateSize x stateSize x |
46 |
|
|
// commandSize |
47 |
|
|
typedef Eigen::Matrix<precision, commandSize, commandSize> |
48 |
|
|
commandR_commandC_stateD_t[stateSize]; // commandSize x commandSize x |
49 |
|
|
// stateSize |
50 |
|
|
|
51 |
|
|
public: |
52 |
|
|
private: |
53 |
|
|
protected: |
54 |
|
|
// attributes // |
55 |
|
|
public: |
56 |
|
|
private: |
57 |
|
|
protected: |
58 |
|
|
double dt; |
59 |
|
|
double final_cost; |
60 |
|
|
double running_cost; |
61 |
|
|
stateVec_t lx; |
62 |
|
|
stateMat_t lxx; |
63 |
|
|
commandVec_t lu; |
64 |
|
|
commandMat_t luu; |
65 |
|
|
commandR_stateC_t lux; |
66 |
|
|
stateR_commandC_t lxu; |
67 |
|
|
// methods // |
68 |
|
|
public: |
69 |
|
|
virtual void computeCostAndDeriv(const stateVec_t& X, const stateVec_t& Xdes, |
70 |
|
|
const commandVec_t& U) = 0; |
71 |
|
|
virtual void computeFinalCostAndDeriv(const stateVec_t& X, |
72 |
|
|
const stateVec_t& Xdes) = 0; |
73 |
|
|
|
74 |
|
|
private: |
75 |
|
|
protected: |
76 |
|
|
// accessors // |
77 |
|
|
public: |
78 |
|
|
double& getRunningCost() { return running_cost; } |
79 |
|
|
double& getFinalCost() { return final_cost; } |
80 |
|
|
stateVec_t& getlx() { return lx; } |
81 |
|
|
stateMat_t& getlxx() { return lxx; } |
82 |
|
|
commandVec_t& getlu() { return lu; } |
83 |
|
|
commandMat_t& getluu() { return luu; } |
84 |
|
|
commandR_stateC_t& getlux() { return lux; } |
85 |
|
|
stateR_commandC_t& getlxu() { return lxu; } |
86 |
|
|
}; |
87 |
|
|
|
88 |
|
|
#endif // COSTFUNCTION_H |