bayesian_ik_solver.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2018, University of Edinburgh
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of nor the names of its contributors may be used to
14 // endorse or promote products derived from this software without specific
15 // prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 // POSSIBILITY OF SUCH DAMAGE.
28 //
29 
30 #ifndef EXOTICA_AICO_SOLVER_BAYESIAN_IK_SOLVER_H_
31 #define EXOTICA_AICO_SOLVER_BAYESIAN_IK_SOLVER_H_
32 
33 #include <iostream>
34 
37 
40 
41 #include <exotica_aico_solver/bayesian_ik_solver_initializer.h>
42 
43 namespace exotica
44 {
47 class BayesianIKSolver : public MotionSolver, public Instantiable<BayesianIKSolverInitializer>
48 {
49 public:
50  void Instantiate(const BayesianIKSolverInitializer& init) override;
51 
54  void Solve(Eigen::MatrixXd& solution) override;
55 
59  void SpecifyProblem(PlanningProblemPtr pointer) override;
60 
61 protected:
65  void InitMessages();
66 
70  void InitTrajectory(const Eigen::VectorXd& q_init);
71 
72 private:
74  double damping = 0.01;
75  double damping_init_ = 100.0;
76  double minimum_step_tolerance_ = 1e-5;
77  double step_tolerance_ = 1e-5;
78  double function_tolerance_ = 1e-5;
80  bool use_bwd_msg_ = false;
81  Eigen::VectorXd bwd_msg_v_;
82  Eigen::MatrixXd bwd_msg_Vinv_;
85 
86  Eigen::VectorXd s;
87  Eigen::MatrixXd Sinv;
88  Eigen::VectorXd v;
89  Eigen::MatrixXd Vinv;
90  Eigen::VectorXd r;
91  Eigen::MatrixXd R;
92  double rhat;
93  Eigen::VectorXd b;
94  Eigen::MatrixXd Binv;
95  Eigen::VectorXd q;
96  Eigen::VectorXd qhat;
97 
98  Eigen::VectorXd s_old;
99  Eigen::MatrixXd Sinv_old;
100  Eigen::VectorXd v_old;
101  Eigen::MatrixXd Vinv_old;
102  Eigen::VectorXd r_old;
103  Eigen::MatrixXd R_old;
104  double rhat_old;
105  Eigen::VectorXd b_old;
106  Eigen::MatrixXd Binv_old;
107  Eigen::VectorXd q_old;
108  Eigen::VectorXd qhat_old;
109 
110  Eigen::VectorXd damping_reference_;
111  double cost_ = 0.0;
112  double cost_old_ = std::numeric_limits<double>::max();
113  double cost_prev_ = std::numeric_limits<double>::max();
114  double b_step_ = 0.0;
115  double b_step_old_;
116 
117  Eigen::MatrixXd W;
118  Eigen::MatrixXd Winv;
119 
120  int sweep_ = 0;
121  int best_sweep_ = 0;
124  {
125  FORWARD = 0,
129  };
130  int sweep_mode_ = 0;
131  int update_count_ = 0;
132 
133  bool verbose_ = false;
134 
142  void UpdateFwdMessage();
143 
151  void UpdateBwdMessage();
152 
159  void UpdateTaskMessage(const Eigen::Ref<const Eigen::VectorXd>& qhat_t, double tolerance,
160  double max_step_size = -1.);
161 
170  void UpdateTimestep(bool update_fwd, bool update_bwd,
171  int max_relocation_iterations, double tolerance, bool force_relocation,
172  double max_step_size = -1.);
173 
188  void UpdateTimestepGaussNewton(bool update_fwd, bool update_bwd,
189  int max_relocation_iterations, double tolerance, double max_step_size = -1.);
193  double EvaluateTrajectory(const Eigen::VectorXd& x, bool skip_update = false);
194 
196  void RememberOldState();
197 
199  void PerhapsUndoStep();
200 
202  void GetTaskCosts();
203 
206  double Step();
207 };
208 } // namespace exotica
209 
210 #endif // EXOTICA_AICO_SOLVER_BAYESIAN_IK_SOLVER_H_
Solves motion planning problem using Approximate Inference Control method.
double cost_
cost of MAP trajectory
bool sweep_improved_cost_
Whether the last sweep improved the cost (for backtrack iterations count)
double rhat
Task message point of linearisation.
Eigen::VectorXd s
Forward message mean.
double b_step_
Squared configuration space step.
Eigen::MatrixXd R
Task message covariance.
double Step()
Compute one step of the AICO algorithm.
Eigen::VectorXd qhat
Point of linearisation.
void UpdateFwdMessage()
Updates the forward message Updates the mean and covariance of the forward message using: ...
Eigen::VectorXd b_old
Belief mean (last most optimal value)
double cost_old_
cost of MAP trajectory (last most optimal value)
void UpdateTimestep(bool update_fwd, bool update_bwd, int max_relocation_iterations, double tolerance, bool force_relocation, double max_step_size=-1.)
Update messages for given time step.
Eigen::VectorXd q_old
Configuration space trajectory (last most optimal value)
Eigen::MatrixXd bwd_msg_Vinv_
Backward message initialisation covariance.
bool use_bwd_msg_
Flag for using backward message initialisation.
void InitTrajectory(const Eigen::VectorXd &q_init)
Initialise AICO messages from an initial trajectory.
Eigen::VectorXd bwd_msg_v_
Backward message initialisation mean.
Eigen::MatrixXd Vinv_old
Backward message covariance inverse (last most optimal value)
void UpdateTimestepGaussNewton(bool update_fwd, bool update_bwd, int max_relocation_iterations, double tolerance, double max_step_size=-1.)
Update messages for given time step using the Gauss Newton method.
void PerhapsUndoStep()
Reverts back to previous state if the cost of the current state is higher.
Eigen::VectorXd s_old
Forward message mean (last most optimal value)
double minimum_step_tolerance_
Update tolerance to stop update of messages if change of maximum coefficient is less than this tolera...
double cost_prev_
previous iteration cost
double EvaluateTrajectory(const Eigen::VectorXd &x, bool skip_update=false)
Computes the cost of the trajectory.
Eigen::MatrixXd R_old
Task message covariance (last most optimal value)
void InitMessages()
Initializes message data.
Eigen::VectorXd v_old
Backward message mean (last most optimal value)
void GetTaskCosts()
Updates the task cost terms . UnconstrainedEndPoseProblem::Update() has to be called before calling t...
Eigen::MatrixXd Winv
Configuration space weight matrix inverse.
Eigen::VectorXd damping_reference_
Damping reference point.
Eigen::MatrixXd Sinv_old
Forward message covariance inverse (last most optimal value)
Eigen::MatrixXd Binv_old
Belief covariance inverse (last most optimal value)
UnconstrainedEndPoseProblemPtr prob_
Shared pointer to the planning problem.
std::shared_ptr< exotica::UnconstrainedEndPoseProblem > UnconstrainedEndPoseProblemPtr
Eigen::VectorXd qhat_old
Point of linearisation (last most optimal value)
Eigen::VectorXd q
Configuration space trajectory.
Eigen::MatrixXd W
Configuration space weight matrix inverse.
void Solve(Eigen::MatrixXd &solution) override
Solves the problem.
Eigen::MatrixXd Vinv
Backward message covariance inverse.
int max_backtrack_iterations_
Max. number of sweeps without improvement before terminating (= line-search)
Eigen::VectorXd v
Backward message mean.
Eigen::VectorXd r_old
Task message mean (last most optimal value)
void SpecifyProblem(PlanningProblemPtr pointer) override
Binds the solver to a specific problem which must be pre-initalised.
Eigen::MatrixXd Binv
Belief covariance inverse.
Eigen::VectorXd b
Belief mean.
void Instantiate(const BayesianIKSolverInitializer &init) override
std::shared_ptr< PlanningProblem > PlanningProblemPtr
double function_tolerance_
Relative function tolerance/first-order optimality criterion.
void UpdateTaskMessage(const Eigen::Ref< const Eigen::VectorXd > &qhat_t, double tolerance, double max_step_size=-1.)
Updates the task message.
int iteration_count_
Iteration counter.
void RememberOldState()
Stores the previous state.
double rhat_old
Task message point of linearisation (last most optimal value)
void UpdateBwdMessage()
Updates the backward message Updates the mean and covariance of the backward message using: ...
Eigen::MatrixXd Sinv
Forward message covariance inverse.
double step_tolerance_
Relative step tolerance (termination criterion)
Eigen::VectorXd r
Task message mean.


exotica_aico_solver
Author(s):
autogenerated on Sat Apr 10 2021 02:35:19