88 #include <dynamical_systems/base/DynamicsBase.hpp>
89 #include <dynamical_systems/base/DerivativesBaseDS.hpp>
103 #ifndef INCLUDE_DIRECT_TRAJECTORY_OPTIMIZATION_PROBLEM_HPP_
104 #define INCLUDE_DIRECT_TRAJECTORY_OPTIMIZATION_PROBLEM_HPP_
109 namespace DirectTrajectoryOptimization {
139 template <
typename DIMENSIONS>
143 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
145 typedef typename DIMENSIONS::state_vector_t state_vector_t;
146 typedef typename DIMENSIONS::control_vector_t control_vector_t;
147 typedef typename DIMENSIONS::state_vector_array_t state_vector_array_t;
148 typedef typename DIMENSIONS::control_vector_array_t control_vector_array_t;
166 std::vector<std::shared_ptr<DynamicsBase<DIMENSIONS> > > dynamics,
167 std::vector<std::shared_ptr<DerivativesBaseDS<DIMENSIONS> > > derivatives,
168 std::shared_ptr<BaseClass::CostFunctionBase<DIMENSIONS> > costFunction,
170 Eigen::Vector2d duration,
int numberOfNodes,
172 bool solverVerbose,
bool methodVerbose,
bool feasiblePointOnly=
false) {
182 dynamics, derivatives, costFunction, constraints,
183 duration, numberOfNodes, methodVerbose));
189 dynamics, derivatives, costFunction, constraints,
190 duration, numberOfNodes, methodVerbose));
194 std::cout <<
"METHOD NOT Implemented" << std::endl;
204 problem->_method, solverVerbose,feasiblePointOnly));
211 problem->_method, solverVerbose));
216 std::cout <<
"SOLVER NOT Available" << std::endl;
238 static std::unique_ptr<DirectTrajectoryOptimizationProblem<DIMENSIONS> >
Create(
239 std::shared_ptr<DynamicsBase<DIMENSIONS> > dynamics,
240 std::shared_ptr<DerivativesBaseDS<DIMENSIONS> > derivatives,
241 std::shared_ptr<BaseClass::CostFunctionBase<DIMENSIONS> > costFunction,
243 Eigen::Vector2d duration,
int numberOfNodes,
245 bool solverVerbose,
bool methodVerbose,
bool feasiblePointOnly=
false) {
246 std::vector<std::shared_ptr<DynamicsBase<DIMENSIONS> > > dynamicsVector;
247 std::vector<std::shared_ptr<DerivativesBaseDS<DIMENSIONS> > > derivativesVector;
248 std::vector<std::shared_ptr<BaseClass::ConstraintsBase<DIMENSIONS> > > constraintsVector;
250 dynamicsVector.push_back(dynamics);
251 derivativesVector.push_back(derivatives);
252 constraintsVector.push_back(constraints);
255 numberOfNodes, solverType, methodType, solverVerbose, methodVerbose,feasiblePointOnly);
271 const std::string & problemName,
272 const std::string & outputFile,
273 const std::string & paramFile ,
274 const bool &computeJacobian) {
275 _solver->InitializeSolver(problemName, outputFile, paramFile, computeJacobian);
278 void InitializeNLPvector(Eigen::VectorXd & x,
279 const state_vector_array_t & state_initial,
280 const control_vector_array_t & control_initial,
281 const Eigen::VectorXd & h_initial) {
283 _method->InitializeNLPvector(x, state_initial, control_initial, h_initial);
291 _method->SetInitialState(state);
306 _method->SetFinalVelocityZero(vel_indexes);
313 _method->SetInitialControl(control);
320 _method->SetFinalControl(control);
327 _method->SetEvenTimeIncrements(opt);
335 _method->SetPercentageNodesPerDynamics(nodeSplit);
343 _method->SetGuardFunction(fcnVector);
359 _solver->SetVerbosity(verbose);
360 _method->SetVerbosity(verbose);
370 state_vector_array_t &yTraj,
371 control_vector_array_t &uTraj,
372 Eigen::VectorXd &hTraj) {
373 _solver->GetDTOSolution(yTraj, uTraj, hTraj);
384 state_vector_array_t &yTraj,
385 control_vector_array_t &uTraj,
386 Eigen::VectorXd &hTraj,
387 std::vector<int> &phaseId){
388 _solver->GetDTOSolution(yTraj, uTraj, hTraj, phaseId);
392 state_vector_array_t &yTraj,
393 state_vector_array_t &ydotTraj,
394 control_vector_array_t &uTraj,
395 Eigen::VectorXd & hTraj,
396 std::vector<int> &phaseId) {
398 _solver->GetDTOSolution(yTraj, ydotTraj, uTraj, hTraj,phaseId);
414 return(
_method->ChangeNumberOfpoints());
423 _method->SetStateBounds(lb,ub);
431 void SetStateBounds(
const state_vector_array_t & lb,
const state_vector_array_t & ub){
432 _method->SetStateBounds(lb,ub);
441 _method->SetControlBounds(lb,ub);
449 void SetControlBounds(
const control_vector_array_t & lb,
const control_vector_array_t & ub) {
450 _method->SetControlBounds(lb,ub);
458 _method->SetFreeFinalState(state_number);
467 _method->setTimeIncrementsBounds(h_min,h_max);
479 std::shared_ptr<DTOMethodInterface<DIMENSIONS> >
_method;
480 std::shared_ptr<DTOSolverInterface<DIMENSIONS> >
_solver;
This class implements Direct transcription.
Definition: direct_transcription.hpp:55
void SetControlBounds(const control_vector_array_t &lb, const control_vector_array_t &ub)
Set trajectory of control bounds.
Definition: direct_trajectory_optimization_problem.hpp:449
void GetDTOSolution(state_vector_array_t &yTraj, control_vector_array_t &uTraj, Eigen::VectorXd &hTraj)
Get state control and time solution.
Definition: direct_trajectory_optimization_problem.hpp:369
std::shared_ptr< DTOSolverInterface< DIMENSIONS > > _solver
Definition: direct_trajectory_optimization_problem.hpp:480
void GetFVector(Eigen::VectorXd &fVec)
Get final value of constraint vector.
Definition: direct_trajectory_optimization_problem.hpp:406
void SetFinalVelocityZero(const Eigen::VectorXi &vel_indexes)
Set final velocity zero as hard constraint.
Definition: direct_trajectory_optimization_problem.hpp:304
~DirectTrajectoryOptimizationProblem()
Destruct the given DTOSolver instance.
Definition: direct_trajectory_optimization_problem.hpp:261
std::shared_ptr< DTOMethodInterface< DIMENSIONS > > _method
Definition: direct_trajectory_optimization_problem.hpp:479
Method
Definition: direct_trajectory_optimization_problem.hpp:117
Definition: direct_trajectory_optimization_problem.hpp:129
void SetDircolMethod(const int &dcm)
SetDircolMethod.
Definition: direct_trajectory_optimization_problem.hpp:474
Base class for NLP Solvers interface.
Definition: direct_trajectory_optimization_problem.hpp:118
void Solve(bool warminit=false)
Solves the DTO problem.
Definition: direct_trajectory_optimization_problem.hpp:350
Class interfacing Ipopt NLP with a DirecTrajectoryOptimization problem.
void SetStateBounds(const state_vector_t &lb, const state_vector_t &ub)
Set constant state trajectory bounds.
Definition: direct_trajectory_optimization_problem.hpp:422
enum DirectTrajectoryOptimization::Solvers::Solver solver_t
void SetInitialControl(const control_vector_t &control)
Set initial control.
Definition: direct_trajectory_optimization_problem.hpp:312
void SetStateBounds(const state_vector_array_t &lb, const state_vector_array_t &ub)
Set trajectory of state bounds.
Definition: direct_trajectory_optimization_problem.hpp:431
Solver
Definition: direct_trajectory_optimization_problem.hpp:128
Base class for TO constraints.
Definition: ConstraintsBase.hpp:46
Class interfacing SNOPT NLP with DTO Problem.
Definition: snopt.hpp:49
This class implements Direct Multiple Shooting.
Definition: multiple_shooting.hpp:44
void SetControlBounds(const control_vector_t &lb, const control_vector_t &ub)
Set constant control trajectory bounds.
Definition: direct_trajectory_optimization_problem.hpp:440
void SetEvenTimeIncrements(const bool &opt)
Set even time increments as hard constraint.
Definition: direct_trajectory_optimization_problem.hpp:326
void SetTimeIncrementsBounds(const double &h_min, const double &h_max)
Set bounds for the time increments between nodes.
Definition: direct_trajectory_optimization_problem.hpp:466
This class allows users to solve direct trajectory optimization problems. using different solvers (ip...
Definition: direct_trajectory_optimization_problem.hpp:140
void SetFinalControl(const control_vector_t &control)
Set final control.
Definition: direct_trajectory_optimization_problem.hpp:319
static std::unique_ptr< DirectTrajectoryOptimizationProblem< DIMENSIONS > > CreateWithMultipleDynamics(std::vector< std::shared_ptr< DynamicsBase< DIMENSIONS > > > dynamics, std::vector< std::shared_ptr< DerivativesBaseDS< DIMENSIONS > > > derivatives, std::shared_ptr< BaseClass::CostFunctionBase< DIMENSIONS > > costFunction, std::vector< std::shared_ptr< BaseClass::ConstraintsBase< DIMENSIONS > > > constraints, Eigen::Vector2d duration, int numberOfNodes, Solvers::solver_t solverType, Methods::method_t methodType, bool solverVerbose, bool methodVerbose, bool feasiblePointOnly=false)
Create a new DTOSolver instance.
Definition: direct_trajectory_optimization_problem.hpp:165
Direct transcription class for trajectory optimization.
Class interfacing SNOPT with a DTO Problem.
static std::unique_ptr< DirectTrajectoryOptimizationProblem< DIMENSIONS > > Create(std::shared_ptr< DynamicsBase< DIMENSIONS > > dynamics, std::shared_ptr< DerivativesBaseDS< DIMENSIONS > > derivatives, std::shared_ptr< BaseClass::CostFunctionBase< DIMENSIONS > > costFunction, std::shared_ptr< BaseClass::ConstraintsBase< DIMENSIONS > > constraints, Eigen::Vector2d duration, int numberOfNodes, Solvers::solver_t solverType, Methods::method_t methodType, bool solverVerbose, bool methodVerbose, bool feasiblePointOnly=false)
Create a new DTOSolver instance for single phase problem.
Definition: direct_trajectory_optimization_problem.hpp:238
void SetInitialState(const state_vector_t &state)
Set initial state as hard constraint.
Definition: direct_trajectory_optimization_problem.hpp:290
void SetPercentageNodesPerDynamics(Eigen::VectorXd nodeSplit)
Set percentages of nodes per phase.
Definition: direct_trajectory_optimization_problem.hpp:334
void GetDTOSolution(state_vector_array_t &yTraj, control_vector_array_t &uTraj, Eigen::VectorXd &hTraj, std::vector< int > &phaseId)
Get state control , time and phaseId solution.
Definition: direct_trajectory_optimization_problem.hpp:383
void SetVerbosity(bool verbose)
Change Verbosity level for solver and method.
Definition: direct_trajectory_optimization_problem.hpp:358
enum DirectTrajectoryOptimization::Methods::Method method_t
int ChangeNumberOfPoints()
Change the number of points after construction.
Definition: direct_trajectory_optimization_problem.hpp:413
void InitializeSolver(const std::string &problemName, const std::string &outputFile, const std::string ¶mFile, const bool &computeJacobian)
Initialize the DTOSolver problem.
Definition: direct_trajectory_optimization_problem.hpp:270
Class interfacing Ipopt NLP with a DirectTrajectoryOptimization problem.
Definition: ipopt.hpp:50
void SetGuardFunction(std::vector< double(*)(state_vector_t &)> fcnVector)
Set pointer to function evaluating guard function.
Definition: direct_trajectory_optimization_problem.hpp:342
Definition: direct_trajectory_optimization_problem.hpp:119
void SetFinalState(const state_vector_t &state)
Set final state as hard constraint.
Definition: direct_trajectory_optimization_problem.hpp:297
Base class for direct methods.
void SetFreeFinalState(int state_number)
Set final state free of bounds.
Definition: direct_trajectory_optimization_problem.hpp:457
Class implementing multiple shooting for direct trajectory optimizaion.
Definition: direct_trajectory_optimization_problem.hpp:130