00001 /****************************************************************************** 00002 Copyright (c) 2018, Alexander W. Winkler. All rights reserved. 00003 00004 Redistribution and use in source and binary forms, with or without 00005 modification, are permitted provided that the following conditions are met: 00006 00007 * Redistributions of source code must retain the above copyright notice, this 00008 list of conditions and the following disclaimer. 00009 00010 * Redistributions in binary form must reproduce the above copyright notice, 00011 this list of conditions and the following disclaimer in the documentation 00012 and/or other materials provided with the distribution. 00013 00014 * Neither the name of the copyright holder nor the names of its 00015 contributors may be used to endorse or promote products derived from 00016 this software without specific prior written permission. 00017 00018 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00019 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00020 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00021 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00022 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00023 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00024 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00025 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00026 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00027 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00028 ******************************************************************************/ 00029 00030 #ifndef TOWR_NLP_FACTORY_H_ 00031 #define TOWR_NLP_FACTORY_H_ 00032 00033 #include <ifopt/variable_set.h> 00034 #include <ifopt/constraint_set.h> 00035 #include <ifopt/cost_term.h> 00036 00037 #include <towr/variables/spline_holder.h> 00038 00039 #include "robot_model.h" 00040 #include "height_map.h" 00041 #include "parameters.h" 00042 00043 namespace towr { 00044 00051 class NlpFactory { 00052 public: 00053 using VariablePtrVec = std::vector<ifopt::VariableSet::Ptr>; 00054 using ContraintPtrVec = std::vector<ifopt::ConstraintSet::Ptr>; 00055 using CostPtrVec = std::vector<ifopt::CostTerm::Ptr>; 00056 using EEPos = std::vector<Eigen::Vector3d>; 00057 using Vector3d = Eigen::Vector3d; 00058 00059 NlpFactory () = default; 00060 virtual ~NlpFactory () = default; 00061 00065 VariablePtrVec GetVariableSets(); 00066 00070 ContraintPtrVec GetConstraints() const; 00071 00075 ContraintPtrVec GetCosts() const; 00076 00077 00078 BaseState initial_base_; 00079 BaseState final_base_; 00080 EEPos initial_ee_W_; 00081 RobotModel model_; 00082 HeightMap::Ptr terrain_; 00083 Parameters params_; 00084 00085 SplineHolder spline_holder_; 00086 00087 private: 00088 // variables 00089 std::vector<Nodes::Ptr> MakeBaseVariables() const; 00090 std::vector<PhaseNodes::Ptr> MakeEndeffectorVariables() const; 00091 std::vector<PhaseNodes::Ptr> MakeForceVariables() const; 00092 std::vector<PhaseDurations::Ptr> MakeContactScheduleVariables() const; 00093 00094 // constraints 00095 ContraintPtrVec GetConstraint(ConstraintName name) const; 00096 ContraintPtrVec MakeDynamicConstraint() const; 00097 ContraintPtrVec MakeRangeOfMotionBoxConstraint() const; 00098 ContraintPtrVec MakeTotalTimeConstraint() const; 00099 ContraintPtrVec MakeTerrainConstraint() const; 00100 ContraintPtrVec MakeForceConstraint() const; 00101 ContraintPtrVec MakeSwingConstraint() const; 00102 ContraintPtrVec MakeBaseRangeOfMotionConstraint() const; 00103 ContraintPtrVec MakeBaseAccConstraint() const; 00104 00105 // costs 00106 CostPtrVec GetCost(const CostName& id, double weight) const; 00107 CostPtrVec MakeForcesCost(double weight) const; 00108 }; 00109 00110 } /* namespace towr */ 00111 00112 #endif /* TOWR_NLP_FACTORY_H_ */