- 3.0.2 rigid body dynamics module.
FloatingBaseNLOCContactModel-impl.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 #pragma once
7 
8 namespace ct {
9 namespace rbd {
10 
11 template <class RBDDynamics>
13  const std::string& settingsFile,
14  std::shared_ptr<FBSystem> system,
15  std::shared_ptr<LinearizedSystem> linearizedSystem)
16  : system_(system),
17  linearizedSystem_(linearizedSystem),
18  costFunction_(new CostFunction(costFunctionFile, false)),
19  optConProblem_(system_, costFunction_, linearizedSystem_),
20  iteration_(0)
21 {
22  solver_ = std::shared_ptr<NLOptConSolver>(new NLOptConSolver(optConProblem_, settingsFile));
23 }
24 
25 template <class RBDDynamics>
27  const typename NLOptConSolver::Settings_t& settings,
28  std::shared_ptr<FBSystem> system,
29  std::shared_ptr<LinearizedSystem> linearizedSystem)
30  : system_(system),
31  linearizedSystem_(linearizedSystem),
32  costFunction_(new CostFunction(costFunctionFile, false)),
33  optConProblem_(system_, costFunction_, linearizedSystem_),
34  iteration_(0)
35 {
36  solver_ = std::shared_ptr<NLOptConSolver>(new NLOptConSolver(optConProblem_, settings));
37 }
38 
39 template <class RBDDynamics>
40 void FloatingBaseNLOCContactModel<RBDDynamics>::initialize(const typename RBDDynamics::RBDState_t& x0,
41  const core::Time& tf,
42  StateVectorArray x_ref,
43  FeedbackArray u0_fb,
44  ControlVectorArray u0_ff)
45 {
46  typename NLOptConSolver::Policy_t policy(x_ref, u0_ff, u0_fb, getSettings().dt);
47 
48  solver_->changeTimeHorizon(tf);
49  solver_->setInitialGuess(policy);
50  solver_->changeInitialState(x0.toStateVectorEulerXyz());
51 }
52 
53 template <class RBDDynamics>
55 {
56  solver_->configure(settings);
57 }
58 
59 template <class RBDDynamics>
61 {
62  bool foundBetter = solver_->runIteration();
63 
64  iteration_++;
65  return foundBetter;
66 }
67 
68 template <class RBDDynamics>
71 {
72  return solver_->getStates();
73 }
74 
75 template <class RBDDynamics>
78 {
79  return solver_->getSolution().x_ref();
80 }
81 
82 template <class RBDDynamics>
84 {
85  return solver_->getStateTrajectory().getTimeArray();
86 }
87 
88 template <class RBDDynamics>
91 {
92  return solver_->getSolution().K();
93 }
94 
95 template <class RBDDynamics>
98 {
99  return solver_->getSolution().uff();
100 }
101 
102 template <class RBDDynamics>
105 {
106  return solver_->getSettings();
107 }
108 
109 template <class RBDDynamics>
110 void FloatingBaseNLOCContactModel<RBDDynamics>::changeCostFunction(std::shared_ptr<CostFunction> costFunction)
111 {
112  solver_->changeCostFunction(costFunction);
113 }
114 
115 template <class RBDDynamics>
116 std::shared_ptr<typename FloatingBaseNLOCContactModel<RBDDynamics>::NLOptConSolver>
118 {
119  return solver_;
120 }
121 }
122 }
void initialize(const typename RBDDynamics::RBDState_t &x0, const core::Time &tf, StateVectorArray x_ref=StateVectorArray(), FeedbackArray u0_fb=FeedbackArray(), ControlVectorArray u0_ff=ControlVectorArray())
Definition: FloatingBaseNLOCContactModel-impl.h:40
const StateVectorArray & getStateVectorArray()
Definition: FloatingBaseNLOCContactModel-impl.h:77
std::shared_ptr< NLOptConSolver > getSolver()
Definition: FloatingBaseNLOCContactModel-impl.h:117
NLOCAlgorithm_t::Policy_t Policy_t
const NLOptConSolver::Settings_t & getSettings() const
Definition: FloatingBaseNLOCContactModel-impl.h:104
void changeCostFunction(std::shared_ptr< CostFunction > costFunction)
Definition: FloatingBaseNLOCContactModel-impl.h:110
const double dt
const core::TimeArray & getTimeArray()
Definition: FloatingBaseNLOCContactModel-impl.h:83
const StateVectorArray & retrieveLastRollout()
Definition: FloatingBaseNLOCContactModel-impl.h:70
ct::optcon::NLOptConSolver< FBSystem::STATE_DIM, FBSystem::CONTROL_DIM > NLOptConSolver
Definition: FloatingBaseNLOCContactModel.h:31
const ControlVectorArray & getControlVectorArray()
Definition: FloatingBaseNLOCContactModel-impl.h:97
FloatingBaseNLOCContactModel(const std::string &costFunctionFile, const std::string &settingsFile, std::shared_ptr< FBSystem > system=std::shared_ptr< FBSystem >(new FBSystem), std::shared_ptr< LinearizedSystem > linearizedSystem=nullptr)
constructor taking path to the settings file
Definition: FloatingBaseNLOCContactModel-impl.h:12
void configure(const typename NLOptConSolver::Settings_t &settings)
Definition: FloatingBaseNLOCContactModel-impl.h:54
bool runIteration()
Definition: FloatingBaseNLOCContactModel-impl.h:60
const FeedbackArray & getFeedbackArray()
Definition: FloatingBaseNLOCContactModel-impl.h:90
double Time