TVM  0.9.4
FeedForward.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017-2020 CNRS-AIST JRL and CNRS-UM LIRMM
3  */
4 
5 #pragma once
6 
9 
10 namespace tvm
11 {
12 
13 namespace task_dynamics
14 {
15 
20 template<class TD, class TDImpl = typename TD::Impl>
21 class FeedForward : public TD
22 {
23 public:
24  class Impl;
25 
26  using getFeedForwardT = std::function<const Eigen::VectorXd &()>;
27  using addProviderDependencyT = std::function<void(Impl &)>;
28 
29  template<class FFProvider, class FFSignal, typename... Args>
30  FeedForward(std::shared_ptr<FFProvider> provider,
31  const Eigen::VectorXd & (FFProvider::*method)() const,
32  FFSignal signal,
33  Args &&... args)
34  : TD(std::forward<Args>(args)...)
35  {
36  feedForward_ = [provider, method]() -> const Eigen::VectorXd & { return ((provider.get())->*method)(); };
37  addProviderDependency_ = [provider, signal](Impl & impl) {
38  impl.addInputDependency(TDImpl::Update::UpdateValue, provider, signal);
39  };
40  }
41 
42  ~FeedForward() override = default;
43 
44  class Impl : public TDImpl
45  {
46  public:
47  friend class FeedForward;
48 
49  template<typename... Args>
52  const Eigen::VectorXd & rhs,
53  const getFeedForwardT & ff,
54  const addProviderDependencyT & addPD,
55  Args &&... args)
56  : TDImpl(f, t, rhs, std::forward<Args>(args)...), feedForward_(ff)
57  {
58  if(feedForward_().size() != this->function().size())
59  {
60  throw std::runtime_error(
61  "[task_dynamics::FeedForward] Feed forward term does not have the same size as the provided function");
62  }
63  addPD(*this);
64  }
65 
66  ~Impl() override = default;
67 
68  void updateValue() override
69  {
70  TDImpl::updateValue();
71  this->value_ += feedForward_();
72  }
73 
74  private:
75  getFeedForwardT feedForward_;
76  };
77 
78 protected:
81  std::unique_ptr<abstract::TaskDynamicsImpl> impl_(FunctionPtr f,
83  const Eigen::VectorXd & rhs) const override
84  { return TD::template impl_<Impl>(f, t, rhs, feedForward_, addProviderDependency_); }
85 
87 };
88 
91 
92 } // namespace task_dynamics
93 
94 } // namespace tvm
#define COMPOSABLE_TASK_DYNAMICS_DERIVED_FACTORY(T,...)
Definition: TaskDynamics.h:82
Definition: FeedForward.h:45
Impl(FunctionPtr f, constraint::Type t, const Eigen::VectorXd &rhs, const getFeedForwardT &ff, const addProviderDependencyT &addPD, Args &&... args)
Definition: FeedForward.h:50
void updateValue() override
Definition: FeedForward.h:68
Definition: FeedForward.h:22
~FeedForward() override=default
addProviderDependencyT addProviderDependency_
Definition: FeedForward.h:80
std::function< void(Impl &)> addProviderDependencyT
Definition: FeedForward.h:27
getFeedForwardT feedForward_
Definition: FeedForward.h:79
std::function< const Eigen::VectorXd &()> getFeedForwardT
Definition: FeedForward.h:26
std::unique_ptr< abstract::TaskDynamicsImpl > impl_(FunctionPtr f, constraint::Type t, const Eigen::VectorXd &rhs) const override
Definition: FeedForward.h:81
FeedForward(std::shared_ptr< FFProvider > provider, const Eigen::VectorXd &(FFProvider::*method)() const, FFSignal signal, Args &&... args)
Definition: FeedForward.h:30
Definition: probe.h:44
Type
Definition: enums.h:15
Definition: Clock.h:12
std::shared_ptr< function::abstract::Function > FunctionPtr
Definition: defs.h:57