- 3.0.2 optimal control module.
OptVectorDms.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 
9 #include <Eigen/Core>
10 #include <map>
11 
12 #include "TimeGrid.h"
13 
20 
21 
22 namespace ct {
23 namespace optcon {
24 
25 
36 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
37 class OptVectorDms : public tpl::OptVector<SCALAR>
38 {
39 public:
40  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
41 
44 
45  typedef typename DIMENSIONS::state_vector_t state_vector_t;
46  typedef typename DIMENSIONS::control_vector_t control_vector_t;
47  typedef typename DIMENSIONS::state_vector_array_t state_vector_array_t;
48  typedef typename DIMENSIONS::control_vector_array_t control_vector_array_t;
49  typedef typename DIMENSIONS::control_matrix_t control_matrix_t;
50  typedef typename DIMENSIONS::time_array_t time_array_t;
51 
58  OptVectorDms(size_t n, const DmsSettings& settings);
59 
60  OptVectorDms(const OptVectorDms& arg) = delete;
61 
65  ~OptVectorDms() override = default;
66 
74  state_vector_t getOptimizedState(const size_t pairNum) const;
75 
83  control_vector_t getOptimizedControl(const size_t pairNum) const;
84 
90  const state_vector_array_t& getOptimizedStates();
91 
97  const control_vector_array_t& getOptimizedInputs();
98 
107  size_t getStateIndex(const size_t pairNum) const;
108 
117  size_t getControlIndex(const size_t pairNum) const;
118 
129  void setInitGuess(const state_vector_t& x0, const state_vector_t& x_f, const control_vector_t& u0);
130 
137  void setInitGuess(const state_vector_array_t& x_init, const control_vector_array_t& u_init);
138 
144  void changeInitialState(const state_vector_t& x0);
145 
151  void changeDesiredState(const state_vector_t& xF);
152 
158  size_t numPairs() { return numPairs_; }
162  void printoutSolution();
163 
164 private:
165  DmsSettings settings_;
166 
167  const size_t numPairs_;
168  /* maps the number of a "pair" to the index in w where ... */
169  std::map<size_t, size_t> pairNumToStateIdx_; /* ... its state starts */
170  std::map<size_t, size_t> pairNumToControlIdx_; /* ... its control starts */
171 
172  state_vector_array_t stateSolution_;
173  control_vector_array_t inputSolution_;
174 };
175 
176 } // namespace optcon
177 } // namespace ct
178 
size_t getStateIndex(const size_t pairNum) const
Returns the starting index for the state at shot pairNum inside the optimization vector.
Definition: OptVectorDms-impl.h:66
const control_vector_array_t & getOptimizedInputs()
Returns the optimized control inputs for all shots.
Definition: OptVectorDms-impl.h:56
state_vector_t getOptimizedState(const size_t pairNum) const
Returns the optimized state for a specific shot.
Definition: OptVectorDms-impl.h:29
size_t getControlIndex(const size_t pairNum) const
Returns the starting index for the control input at shot pairNum inside the optimization vector...
Definition: OptVectorDms-impl.h:73
control_vector_t getOptimizedControl(const size_t pairNum) const
Returns the optimized control input for a specific shot.
Definition: OptVectorDms-impl.h:37
void changeDesiredState(const state_vector_t &xF)
Updates the final state.
Definition: OptVectorDms-impl.h:86
This class is a wrapper around the NLP Optvector. It wraps the Vectors from the NLP solvers into stat...
Definition: OptVectorDms.h:37
void printoutSolution()
Prints out the solution trajectories.
Definition: OptVectorDms-impl.h:142
void changeInitialState(const state_vector_t &x0)
Updates the initial state.
Definition: OptVectorDms-impl.h:79
const state_vector_array_t & getOptimizedStates()
Returns the optimized state for all shots.
Definition: OptVectorDms-impl.h:45
DIMENSIONS::control_vector_array_t control_vector_array_t
Definition: OptVectorDms.h:48
~OptVectorDms() override=default
Destructor.
DIMENSIONS::state_vector_array_t state_vector_array_t
Definition: OptVectorDms.h:47
Defines basic types used in the DMS algorithm.
Definition: DmsDimensions.h:18
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef DmsDimensions< STATE_DIM, CONTROL_DIM, SCALAR > DIMENSIONS
Definition: OptVectorDms.h:42
DIMENSIONS::control_matrix_t control_matrix_t
Definition: OptVectorDms.h:49
void setInitGuess(const state_vector_t &x0, const state_vector_t &x_f, const control_vector_t &u0)
Sets an initial guess for the optimal solution. The optimal solution is set as a linear interpolation...
Definition: OptVectorDms-impl.h:93
Class containing and managing all the optimization variables used for in the NLP solver IPOPT and SNO...
Definition: OptVector.h:21
Defines the DMS settings.
Definition: DmsSettings.h:23
DIMENSIONS::time_array_t time_array_t
Definition: OptVectorDms.h:50
tpl::OptVector< SCALAR > Base
Definition: OptVectorDms.h:43
StateVector< state_dim > x0
Definition: ConstrainedNLOCTest.cpp:14
DIMENSIONS::state_vector_t state_vector_t
Definition: OptVectorDms.h:45
DIMENSIONS::control_vector_t control_vector_t
Definition: OptVectorDms.h:46
size_t numPairs()
Returns the number of pairs.
Definition: OptVectorDms.h:158
OptVectorDms(size_t n, const DmsSettings &settings)
Custom constructor.
Definition: OptVectorDms-impl.h:10