11 template <
class FIX_BASE_FD_SYSTEM>
15 std::shared_ptr<FBSystem> system,
17 std::shared_ptr<LinearizedSystem> linearizedSystem)
19 linearizedSystem_(linearizedSystem),
20 costFunction_(costFun),
21 optConProblem_(system_, costFunction_, linearizedSystem_),
24 optConProblem_.verify();
25 nlocSolver_ = std::shared_ptr<NLOptConSolver>(
new NLOptConSolver(optConProblem_, nlocSettings));
28 template <
class FIX_BASE_FD_SYSTEM>
35 std::shared_ptr<FBSystem> system,
37 std::shared_ptr<LinearizedSystem> linearizedSystem)
39 linearizedSystem_(linearizedSystem),
40 inputBoxConstraints_(inputBoxConstraints),
41 stateBoxConstraints_(stateBoxConstraints),
42 generalConstraints_(generalConstraints),
43 costFunction_(costFun),
44 optConProblem_(system_, costFunction_, linearizedSystem_),
47 if (inputBoxConstraints_ !=
nullptr)
48 optConProblem_.setInputBoxConstraints(inputBoxConstraints_);
49 if (stateBoxConstraints_ !=
nullptr)
50 optConProblem_.setStateBoxConstraints(stateBoxConstraints_);
51 if (generalConstraints_ !=
nullptr)
52 optConProblem_.setGeneralConstraints(generalConstraints_);
54 optConProblem_.verify();
55 nlocSolver_ = std::shared_ptr<NLOptConSolver>(
new NLOptConSolver(optConProblem_, nlocSettings));
58 template <
class FIX_BASE_FD_SYSTEM>
67 nlocSolver_->changeTimeHorizon(tf);
68 nlocSolver_->setInitialGuess(policy);
69 nlocSolver_->changeInitialState(x0.toImplementation());
72 template <
class FIX_BASE_FD_SYSTEM>
96 nlocSolver_->changeTimeHorizon(tf);
97 nlocSolver_->setInitialGuess(policy);
98 nlocSolver_->changeInitialState(x_ref.front());
101 template <
class FIX_BASE_FD_SYSTEM>
115 template <
class FIX_BASE_FD_SYSTEM>
125 x_array.resize(N + 1);
130 for (
int i = 0;
i < N + 1;
i++)
139 uff_torque = system_->computeIDTorques(state_temp.
joints());
142 uff_array[
i].setZero();
146 uff_array[
i] = uff_torque;
154 system_->getActuatorDynamics()->computeStateFromOutput(state_temp.
joints(), uff_torque);
164 std::cout <<
"init with " << x0.
toStateVector() << std::endl;
167 nlocSolver_->changeTimeHorizon(tf);
168 nlocSolver_->setInitialGuess(policy);
171 template <
class FIX_BASE_FD_SYSTEM>
174 bool foundBetter = nlocSolver_->runIteration();
181 template <
class FIX_BASE_FD_SYSTEM>
184 return nlocSolver_->solve();
187 template <
class FIX_BASE_FD_SYSTEM>
190 return nlocSolver_->getSolution();
193 template <
class FIX_BASE_FD_SYSTEM>
196 return nlocSolver_->getStateTrajectory().getTimeArray();
199 template <
class FIX_BASE_FD_SYSTEM>
202 return nlocSolver_->getSolution().K();
205 template <
class FIX_BASE_FD_SYSTEM>
209 return nlocSolver_->getSolution().uff();
212 template <
class FIX_BASE_FD_SYSTEM>
215 return nlocSolver_->getSolution().x_ref();
218 template <
class FIX_BASE_FD_SYSTEM>
222 return nlocSolver_->getSettings();
225 template <
class FIX_BASE_FD_SYSTEM>
228 nlocSolver_->changeCostFunction(costFunction);
231 template <
class FIX_BASE_FD_SYSTEM>
void initializeDirectInterpolation(const RobotState_t &x0, const RobotState_t &xf, const core::Time &tf, const int N, FeedbackMatrix K=FeedbackMatrix::Zero())
initialize fixed-base robot with a directly interpolated state trajectory and corresponding ID torque...
Definition: FixBaseNLOC-impl.h:102
void initialize(const RobotState_t &x0, const core::Time &tf, StateVectorArray x_ref=StateVectorArray(), FeedbackArray u0_fb=FeedbackArray(), ControlVectorArray u0_ff=ControlVectorArray())
Definition: FixBaseNLOC-impl.h:59
const NLOptConSolver::Settings_t & getSettings() const
Definition: FixBaseNLOC-impl.h:220
std::enable_if<(ACT_STATE_DIM==0), T >::type toStateVector() const
conversion from RobotState to dense state vector
Definition: FixBaseRobotState.h:129
bool runIteration()
Definition: FixBaseNLOC-impl.h:172
const StateVectorArray & getStateVectorArray()
Definition: FixBaseNLOC-impl.h:213
NLOCAlgorithm_t::Policy_t Policy_t
std::shared_ptr< NLOptConSolver > getSolver()
Definition: FixBaseNLOC-impl.h:232
void initializeSteadyPose(const RobotState_t &x0, const core::Time &tf, const int N, ControlVector &u_ref, FeedbackMatrix K=FeedbackMatrix::Zero())
initialize fixed-base robot with a steady pose using inverse dynamics torques as feedforward ...
Definition: FixBaseNLOC-impl.h:73
typename FBSystem::SCALAR SCALAR
Definition: FixBaseNLOC.h:30
actuator_state_vector_t & actuatorState()
accessor to actuator state
Definition: FixBaseRobotState.h:94
FixBaseNLOC()=default
default constructor
typename core::FeedbackArray< STATE_DIM, CONTROL_DIM, SCALAR > FeedbackArray
Definition: FixBaseNLOC.h:44
bool verbose
Definition: rbdJITtests.h:15
typename core::StateVectorArray< STATE_DIM, SCALAR > StateVectorArray
Definition: FixBaseNLOC.h:42
typename core::StateFeedbackController< STATE_DIM, CONTROL_DIM, SCALAR > StateFeedbackController
Definition: FixBaseNLOC.h:45
const StateFeedbackController & getSolution()
Definition: FixBaseNLOC-impl.h:188
ct::optcon::NLOptConSolver< STATE_DIM, CONTROL_DIM, STATE_DIM/2, STATE_DIM/2, SCALAR > NLOptConSolver
@ todo: introduce templates for P_DIM and V_DIM
Definition: FixBaseNLOC.h:36
bool solve()
Definition: FixBaseNLOC-impl.h:182
const FeedbackArray & getFeedbackArray()
Definition: FixBaseNLOC-impl.h:200
typename core::ControlVector< CONTROL_DIM, SCALAR > ControlVector
Definition: FixBaseNLOC.h:40
whole fix base robot state, i.e. Joint state, Actuator Dynamics (and fix-base pose) ...
Definition: FixBaseRobotState.h:26
static const size_t ACTUATOR_STATE_DIM
Definition: FixBaseNLOC.h:29
joint_state_vector_t & toImplementation()
Definition: JointState.h:159
typename core::FeedbackMatrix< STATE_DIM, CONTROL_DIM, SCALAR > FeedbackMatrix
Definition: FixBaseNLOC.h:41
void changeCostFunction(std::shared_ptr< CostFunction > costFunction)
Definition: FixBaseNLOC-impl.h:226
typename core::ControlVectorArray< CONTROL_DIM, SCALAR > ControlVectorArray
Definition: FixBaseNLOC.h:43
const ControlVectorArray & getControlVectorArray()
Definition: FixBaseNLOC-impl.h:207
JointState_t & joints()
accessor to joint state
Definition: FixBaseRobotState.h:102
const core::TimeArray & getTimeArray()
Definition: FixBaseNLOC-impl.h:194