- 3.0.2 rigid body dynamics module.
FloatingBaseSLQ.h
Go to the documentation of this file.
1 /**********************************************************************************************************************
2 This file is part of the Control Toolbox (https://github.com/ethz-adrl/control-toolbox), copyright by ETH Zurich.
3 Licensed under the BSD-2 license (see LICENSE file in main directory)
4 **********************************************************************************************************************/
5 
6 #ifndef INCLUDE_CT_RBD_SLQ_FLOATINGBASESLQ_H_
7 #define INCLUDE_CT_RBD_SLQ_FLOATINGBASESLQ_H_
8 
9 #include <ct/core/systems/linear/SystemLinearizer.h>
10 
11 #include <ct/optcon/ilqg/iLQGMP.hpp>
12 
14 
15 
16 namespace ct {
17 namespace rbd {
18 
23 template <class RBDDynamics>
25 {
26 public:
27  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
28 
29  static const bool quatIntegration = false;
30  static const bool eeForcesAreControlInputs = true;
31 
35 
36  typedef ct::optcon::iLQGMP<FBSystem::STATE_DIM, FBSystem::CONTROL_DIM> iLQG;
37  typedef ct::optcon::iLQGMP<FBSystem::STATE_DIM, FBSystem::CONTROL_DIM> iLQGMP;
38 
40  typedef ct::rbd::TermTaskspace<FBSystem::Kinematics, true, FBSystem::STATE_DIM, FBSystem::CONTROL_DIM>
42 
43  typedef iLQG::StateTrajectory StateTrajectory;
44 
45 
46  FloatingBaseSLQ(std::shared_ptr<FBSystem> system,
47  const std::string& costFunctionFile,
48  std::shared_ptr<LinearizedSystem> linearizedSystem = nullptr,
49  bool useMP = true)
50  : system_(system), linearizedSystem_(linearizedSystem), useMP_(useMP), iteration_(0)
51  {
52  // if no linearized system provided, use general system linearizer
53  if (linearizedSystem_ == nullptr)
54  linearizedSystem_ = std::shared_ptr<LinearizedSystem>(new SystemLinearizer(system));
55 
56  setupCostFunction(costFunctionFile);
57 
58  ilqg_ = std::shared_ptr<iLQG>(new iLQG(system_, linearizedSystem_, costFunction_));
59  ilqgMp_ = std::shared_ptr<iLQGMP>(new iLQGMP(system_, linearizedSystem_, costFunction_));
60  }
61 
62  bool runIteration(StateTrajectory& stateTrajectory)
63  {
64  bool foundBetter;
65 
66  if (useMP_)
67  {
68  foundBetter = ilqgMp_->runIteration(ilqg_settings_, line_search_settings_);
69  stateTrajectory = ilqgMp_->retrieveLastRollout();
70  }
71  else
72  {
73  foundBetter = ilqg_->runIteration(ilqg_settings_, line_search_settings_);
74  stateTrajectory = ilqg_->retrieveLastRollout();
75  }
76 
77  iteration_++;
78  return foundBetter;
79  }
80 
81  ilqg_settings_t iLQGSettings() { return ilqg_settings_; }
82 private:
83  void setupCostFunction(const std::string& filename)
84  {
85  costFunction_ = std::shared_ptr<CostFunction>(new CostFunction(filename, true));
86 
87  for (size_t i = 0; i < N_EE; i++)
88  {
89  eePosTerms_.push_back(new TaskSpaceTerm(filename, "eePos" + std::to_string(i), true));
90  costFunction_->addIntermediateTerm(eePosTerms_.back());
91  }
92  }
93 
94  std::shared_ptr<FBSystem> system_;
95  std::shared_ptr<LinearizedSystem> linearizedSystem_;
96 
97  std::shared_ptr<iLQG> ilqg_;
98  std::shared_ptr<iLQG> ilqgMp_;
99 
100  std::shared_ptr<CostFunction> costFunction_;
101  std::vector<std::shared_ptr<TaskSpaceTerm>> eePosTerms_;
102 
103  ilqg_settings_t ilqg_settings_;
104  line_search_settings_t line_search_settings_;
105 
106  bool useMP_;
107 
108  size_t iteration_;
109 };
110 }
111 }
112 
113 #endif /* INCLUDE_CT_RBD_SLQ_FLOATINGBASESLQ_H_ */
ct::optcon::iLQGMP< FBSystem::STATE_DIM, FBSystem::CONTROL_DIM > iLQGMP
Definition: FloatingBaseSLQ.h:37
ct::rbd::TermTaskspace< FBSystem::Kinematics, true, FBSystem::STATE_DIM, FBSystem::CONTROL_DIM > TaskSpaceTerm
Definition: FloatingBaseSLQ.h:41
SLQ for floating base systems without an explicit contact model. The contact constraint is enforced v...
Definition: FloatingBaseSLQ.h:24
static EIGEN_MAKE_ALIGNED_OPERATOR_NEW const bool quatIntegration
Definition: FloatingBaseSLQ.h:29
iLQG::StateTrajectory StateTrajectory
Definition: FloatingBaseSLQ.h:43
ct::optcon::iLQGMP< FBSystem::STATE_DIM, FBSystem::CONTROL_DIM > iLQG
Definition: FloatingBaseSLQ.h:36
A floating base rigid body system that uses forward dynamics. The input vector is assumed to consist ...
Definition: FloatingBaseFDSystem.h:21
ct::core::SystemLinearizer< FBSystem::STATE_DIM, FBSystem::CONTROL_DIM > SystemLinearizer
Definition: FloatingBaseSLQ.h:34
ct::optcon::CostFunctionAnalytical< FBSystem::STATE_DIM, FBSystem::CONTROL_DIM > CostFunction
Definition: FloatingBaseSLQ.h:39
ct::core::LinearSystem< FBSystem::STATE_DIM, FBSystem::CONTROL_DIM > LinearizedSystem
Definition: FloatingBaseSLQ.h:33
for i
FloatingBaseFDSystem< RBDDynamics, false, true > FBSystem
Definition: FloatingBaseSLQ.h:32
FloatingBaseSLQ(std::shared_ptr< FBSystem > system, const std::string &costFunctionFile, std::shared_ptr< LinearizedSystem > linearizedSystem=nullptr, bool useMP=true)
Definition: FloatingBaseSLQ.h:46
ilqg_settings_t iLQGSettings()
Definition: FloatingBaseSLQ.h:81
bool runIteration(StateTrajectory &stateTrajectory)
Definition: FloatingBaseSLQ.h:62
static const bool eeForcesAreControlInputs
Definition: FloatingBaseSLQ.h:30