min_time_via_points_cost.h
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * Software License Agreement
4  *
5  * Copyright (c) 2020, Christoph Rösmann, All rights reserved.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  *
20  * Authors: Christoph Rösmann
21  *********************************************************************/
22 
23 #ifndef MIN_TIME_VIA_POINTS_COSTS_H_
24 #define MIN_TIME_VIA_POINTS_COSTS_H_
25 
28 
30 
31 #include <cmath>
32 #include <memory>
33 #include <utility>
34 #include <vector>
35 
36 namespace mpc_local_planner {
37 
50 class MinTimeViaPointsCost : public corbo::StageCost
51 {
52  public:
53  using Ptr = std::shared_ptr<MinTimeViaPointsCost>;
54 
55  using ViaPointContainer = std::vector<teb_local_planner::PoseSE2>;
56 
58  MinTimeViaPointsCost() = default;
59 
68  MinTimeViaPointsCost(const ViaPointContainer& via_points, double position_weight, double orientation_weight, bool via_points_ordered)
69  : _via_points_ordered(via_points_ordered)
70  {
72  setViaPointWeights(position_weight, orientation_weight);
73  }
74 
75  // implements interface method
76  corbo::StageCost::Ptr getInstance() const override { return std::make_shared<MinTimeViaPointsCost>(); }
77 
78  // implements interface method
79  bool hasNonIntegralTerms(int k) const override { return true; }
80  // implements interface method
81  bool hasIntegralTerms(int k) const override { return false; }
82 
83  // implements interface method
84  int getNonIntegralDtTermDimension(int k) const override { return (k == 0 || !_single_dt) ? 1 : 0; }
85  // implements interface method
86  bool isLsqFormNonIntegralDtTerm(int k) const override { return false; }
87  // implements interface method
88  int getNonIntegralStateTermDimension(int k) const override;
89 
90  // implements interface method
91  bool update(int n, double /*t*/, corbo::ReferenceTrajectoryInterface& /*xref*/, corbo::ReferenceTrajectoryInterface& /*uref*/,
92  corbo::ReferenceTrajectoryInterface* /*sref*/, bool single_dt, const Eigen::VectorXd& x0,
93  corbo::StagePreprocessor::Ptr /*stage_preprocessor*/, const std::vector<double>& /*dts*/,
94  const corbo::DiscretizationGridInterface* grid) override;
95 
96  // implements interface method
97  void computeNonIntegralDtTerm(int k, double dt, Eigen::Ref<Eigen::VectorXd> cost) const override;
98  // implements interface method
100 
102  void setViaPointContainer(const ViaPointContainer& via_points) { _via_points = &via_points; }
104  void setViaPointOrderedMode(bool ordered) { _via_points_ordered = ordered; }
106  void setViaPointWeights(double position_weight, double orientation_weight)
107  {
108  _vp_position_weight = position_weight;
109  _vp_orientation_weight = orientation_weight;
110  }
111 
112  protected:
113  bool _single_dt = false;
114  double _time_weight = 1;
115 
116  bool _via_points_ordered = false;
117  double _vp_position_weight = 1e-3;
118  double _vp_orientation_weight = 0;
119 
120  const ViaPointContainer* _via_points = nullptr;
121  std::vector<std::pair<std::vector<const teb_local_planner::PoseSE2*>, std::size_t>> _vp_association;
122  // also store previous number of associated points to detect structure changes
123 };
124 
125 } // namespace mpc_local_planner
126 
127 #endif // MIN_TIME_VIA_POINTS_COSTS_H_
mpc_local_planner::MinTimeViaPointsCost::_via_points_ordered
bool _via_points_ordered
Definition: min_time_via_points_cost.h:156
mpc_local_planner::MinTimeViaPointsCost::_vp_association
std::vector< std::pair< std::vector< const teb_local_planner::PoseSE2 * >, std::size_t > > _vp_association
Definition: min_time_via_points_cost.h:161
mpc_local_planner::MinTimeViaPointsCost::getInstance
corbo::StageCost::Ptr getInstance() const override
Definition: min_time_via_points_cost.h:116
corbo::StageCost
corbo::StagePreprocessor::Ptr
std::shared_ptr< StagePreprocessor > Ptr
via_points
ViaPointContainer via_points
corbo::ReferenceTrajectoryInterface
mpc_local_planner::MinTimeViaPointsCost::ViaPointContainer
std::vector< teb_local_planner::PoseSE2 > ViaPointContainer
Definition: min_time_via_points_cost.h:95
mpc_local_planner::MinTimeViaPointsCost::getNonIntegralStateTermDimension
int getNonIntegralStateTermDimension(int k) const override
Definition: min_time_via_points_cost.cpp:53
mpc_local_planner::MinTimeViaPointsCost::getNonIntegralDtTermDimension
int getNonIntegralDtTermDimension(int k) const override
Definition: min_time_via_points_cost.h:124
mpc_local_planner::MinTimeViaPointsCost::setViaPointWeights
void setViaPointWeights(double position_weight, double orientation_weight)
Set weights for via-point attraction.
Definition: min_time_via_points_cost.h:146
mpc_local_planner
Definition: controller.h:44
mpc_local_planner::MinTimeViaPointsCost::MinTimeViaPointsCost
MinTimeViaPointsCost()=default
Default constructor.
corbo::StageCost::Ptr
std::shared_ptr< StageCost > Ptr
mpc_local_planner::MinTimeViaPointsCost::computeNonIntegralStateTerm
void computeNonIntegralStateTerm(int k, const Eigen::Ref< const Eigen::VectorXd > &x_k, Eigen::Ref< Eigen::VectorXd > cost) const override
Definition: min_time_via_points_cost.cpp:150
mpc_local_planner::MinTimeViaPointsCost::_vp_orientation_weight
double _vp_orientation_weight
Definition: min_time_via_points_cost.h:158
mpc_local_planner::MinTimeViaPointsCost::_vp_position_weight
double _vp_position_weight
Definition: min_time_via_points_cost.h:157
stage_functions.h
mpc_local_planner::MinTimeViaPointsCost::isLsqFormNonIntegralDtTerm
bool isLsqFormNonIntegralDtTerm(int k) const override
Definition: min_time_via_points_cost.h:126
reference_trajectory.h
pose_se2.h
mpc_local_planner::MinTimeViaPointsCost::hasIntegralTerms
bool hasIntegralTerms(int k) const override
Definition: min_time_via_points_cost.h:121
mpc_local_planner::MinTimeViaPointsCost::_single_dt
bool _single_dt
Definition: min_time_via_points_cost.h:153
Eigen::Ref
mpc_local_planner::MinTimeViaPointsCost::_time_weight
double _time_weight
Definition: min_time_via_points_cost.h:154
mpc_local_planner::MinTimeViaPointsCost::_via_points
const ViaPointContainer * _via_points
Definition: min_time_via_points_cost.h:160
mpc_local_planner::MinTimeViaPointsCost::setViaPointContainer
void setViaPointContainer(const ViaPointContainer &via_points)
Set reference to via-point container (warning, object must remain allocated)
Definition: min_time_via_points_cost.h:142
mpc_local_planner::MinTimeViaPointsCost::hasNonIntegralTerms
bool hasNonIntegralTerms(int k) const override
Definition: min_time_via_points_cost.h:119
mpc_local_planner::MinTimeViaPointsCost::Ptr
std::shared_ptr< MinTimeViaPointsCost > Ptr
Definition: min_time_via_points_cost.h:93
mpc_local_planner::MinTimeViaPointsCost::setViaPointOrderedMode
void setViaPointOrderedMode(bool ordered)
Set if the optimzier should try to match the via-point ordering.
Definition: min_time_via_points_cost.h:144
mpc_local_planner::MinTimeViaPointsCost::update
bool update(int n, double, corbo::ReferenceTrajectoryInterface &, corbo::ReferenceTrajectoryInterface &, corbo::ReferenceTrajectoryInterface *, bool single_dt, const Eigen::VectorXd &x0, corbo::StagePreprocessor::Ptr, const std::vector< double > &, const corbo::DiscretizationGridInterface *grid) override
Definition: min_time_via_points_cost.cpp:60
ViaPointContainer
std::vector< Eigen::Vector2d, Eigen::aligned_allocator< Eigen::Vector2d > > ViaPointContainer
mpc_local_planner::MinTimeViaPointsCost::computeNonIntegralDtTerm
void computeNonIntegralDtTerm(int k, double dt, Eigen::Ref< Eigen::VectorXd > cost) const override
Definition: min_time_via_points_cost.cpp:140
corbo::DiscretizationGridInterface


mpc_local_planner
Author(s): Christoph Rösmann
autogenerated on Wed Mar 2 2022 00:35:06