smooth_feedback
Control and estimation on Lie groups
Loading...
Searching...
No Matches
asif.hpp
1// Copyright (C) 2022 Petter Nilsson. MIT License.
2
3#pragma once
4
5#include <cassert>
6#include <utility>
7
8#include "asif_func.hpp"
9#include "qp_solver.hpp"
10#include "time.hpp"
11
12namespace smooth::feedback {
13
17template<Manifold U>
19{
21 double T{1};
23 std::size_t nh{1};
25 Eigen::Matrix<double, Dof<U>, 1> u_weight{Eigen::Matrix<double, Dof<U>, 1>::Ones()};
32};
33
41template<LieGroup G, Manifold U, typename Dyn, diff::Type DT = diff::Type::Default>
43{
44public:
52 ASIFilter(const Dyn & f, const ASIFilterParams<U> & prm = ASIFilterParams<U>{})
53 : ASIFilter(Dyn(f), ASIFilterParams<U>(prm))
54 {}
55
59 ASIFilter(Dyn && f, ASIFilterParams<U> && prm = ASIFilterParams<U>{}) : f_(std::move(f)), prm_(std::move(prm))
60 {
61 const int nu_ineq = prm_.ulim.A.rows();
62 asif_to_qp_allocate<G, U>(qp_, prm_.asif.K, nu_ineq, prm_.nh);
63 }
64
82 std::pair<U, QPSolutionStatus> operator()(const G & g, const U & u_des, auto && h, auto && bu)
83 {
84 using std::chrono::duration, std::chrono::duration_cast, std::chrono::nanoseconds;
85
86 assert((prm_.nh == std::invoke_result_t<decltype(h), Scalar<G>, G>::RowsAtCompileTime));
87
89 .T = prm_.T,
90 .x0 = g,
91 .u_des = u_des,
92 .W_u = prm_.u_weight,
93 .ulim = prm_.ulim,
94 };
95
96 asif_to_qp_update<G, U, DT>(qp_, pbm, prm_.asif, f_, std::forward<decltype(h)>(h), std::forward<decltype(bu)>(bu));
97 auto sol = feedback::solve_qp(qp_, prm_.qp, warmstart_);
98
99 if (sol.code == QPSolutionStatus::Optimal) { warmstart_ = sol; }
100
101 return {rplus(u_des, sol.primal.template head<Dof<U>>()), sol.code};
102 }
103
104private:
105 Dyn f_;
106
107 QuadraticProgram<-1, -1, double> qp_;
109 std::optional<QPSolution<-1, -1, double>> warmstart_;
110};
111
112} // namespace smooth::feedback
Functions for active Set Invariance (ASI) filtering on Lie groups.
ASIFilter(const Dyn &f, const ASIFilterParams< U > &prm=ASIFilterParams< U >{})
Construct an ASI filter.
Definition: asif.hpp:52
ASIFilter(Dyn &&f, ASIFilterParams< U > &&prm=ASIFilterParams< U >{})
Construct an ASI filter (rvalue version).
Definition: asif.hpp:59
std::pair< U, QPSolutionStatus > operator()(const G &g, const U &u_des, auto &&h, auto &&bu)
Filter an input.
Definition: asif.hpp:82
Quadratic Program solver.
Active set invariance problem definition.
Definition: asif_func.hpp:42
double T
time horizon
Definition: asif_func.hpp:44
ASIFilter filter parameters.
Definition: asif.hpp:19
ASIFtoQPParams asif
ASIFilter algorithm parameters.
Definition: asif.hpp:29
ManifoldBounds< U > ulim
Input bounds.
Definition: asif.hpp:27
std::size_t nh
Number of barrier constraints (must agree with output dimensionality of h)
Definition: asif.hpp:23
QPSolverParams qp
solve_qp() parameters
Definition: asif.hpp:31
Eigen::Matrix< double, Dof< U >, 1 > u_weight
Weights on desired input.
Definition: asif.hpp:25
double T
Time horizon.
Definition: asif.hpp:21
Parameters for asif_to_qp.
Definition: asif_func.hpp:59
Manifold constraint set.
Definition: common.hpp:19
Solver solution.
Definition: qp.hpp:97
Options for solve_qp.
Definition: qp_solver.hpp:30
Quadratic program definition.
Definition: qp.hpp:33