Lodestar
An integrated real-time control package in C++
IntegratorBlock.hpp
1 //
2 // Created by Hamza El-Kebir on 2/24/22.
3 //
4 
5 #ifndef LODESTAR_INTEGRATORBLOCK_HPP
6 #define LODESTAR_INTEGRATORBLOCK_HPP
7 
8 
9 #include <Lodestar/blocks/Block.hpp>
10 #include <Lodestar/aux/ArrayStack.hpp>
11 
12 namespace ls {
13  namespace blocks {
14  namespace std {
15  template<typename TInput, unsigned int NHorizon=1, typename TScalar = float>
17  : public Block<
18  ::std::tuple<TInput>,
19  ::std::tuple<TInput>,
20  ::std::tuple<TScalar>
21  > {
22  public:
23  using Base =
24  Block<
25  ::std::tuple<TInput>,
26  ::std::tuple<TInput>,
27  ::std::tuple<TScalar>
28  >;
29 
31  {
32  bindFunction();
33  }
34 
35  void clear(TInput value)
36  {
37  fifoStack_.fill(value);
38  this->template o<0>() = value;
39  }
40 
41  void clear(TInput &value)
42  {
43  fifoStack_.fill(value);
44  this->template o<0>() = value;
45  }
46 
47 
48  protected:
50 
51  void bindFunction()
52  {
53  this->equation = ::std::bind(
55  this,
56  ::std::placeholders::_1
57  );
58  }
59 
60  void triggerFunction(Base &b)
61  {
62  fifoStack_.push(b.template i<0>().object);
63  b.template o<0>() = fifoStack_.back();
64  }
65  };
66  }
67 
68  template<typename TInput, unsigned int NDelay>
70  public:
71  static constexpr const BlockType blockType = BlockType::IntegratorBlock;
72  enum {
73  directFeedthrough = (NDelay > 0)
74  };
75 
77  using Base = typename type::Base;
78 
79  enum {
80  kIns = Base::kIns,
81  kOuts = Base::kOuts,
82  kPars = Base::kPars
83  };
84 
85  static const ::std::array<::std::string, kIns> inTypes;
86  static const ::std::array<::std::string, kOuts> outTypes;
87  static const ::std::array<::std::string, kPars> parTypes;
88 
89  static const ::std::array<::std::string, 2> templateTypes;
90  };
91 
92  template<typename TInput, unsigned int NDelay>
93  const ::std::array<::std::string, BlockTraits<std::IntegratorBlock<TInput, NDelay>>::kIns> BlockTraits<std::IntegratorBlock<TInput, NDelay>>::inTypes =
94  {demangle(typeid(TInput).name())};
95 
96  template<typename TInput, unsigned int NDelay>
97  const ::std::array<::std::string, BlockTraits<std::IntegratorBlock<TInput, NDelay>>::kOuts> BlockTraits<std::IntegratorBlock<TInput, NDelay>>::outTypes =
98  {demangle(typeid(TInput).name())};
99 
100  template<typename TInput, unsigned int NDelay>
101  const ::std::array<::std::string, BlockTraits<std::IntegratorBlock<TInput, NDelay>>::kPars> BlockTraits<std::IntegratorBlock<TInput, NDelay>>::parTypes =
102  {};
103 
104  template<typename TInput, unsigned int NDelay>
105  const ::std::array<::std::string, 2> BlockTraits<std::IntegratorBlock<TInput, NDelay>>::templateTypes =
106  {demangle(typeid(TInput).name()), "unsigned int"};
107  }
108 }
109 
110 
111 #endif //LODESTAR_INTEGRATORBLOCK_HPP
ls::aux::ArrayStack::back
TType & back()
Returns a reference to the rear value in the stack.
Definition: ArrayStack.hpp:222
ls::blocks::BlockType::IntegratorBlock
@ IntegratorBlock
Integrator block.
ls::blocks::BlockTraits
A traits object that exposes information about TBlock.
Definition: BlockTraits.hpp:37
ls::blocks::BlockType
BlockType
Block type information.
Definition: BlockType.hpp:25
ls
Main Lodestar code.
Definition: BilinearTransformation.hpp:12
ls::aux::ArrayStack
A statically sized stack with full member access.
Definition: ArrayStack.hpp:21
ls::blocks::Block
Generic base template class for all tuple-based Block instances.
Definition: Block.hpp:45
ls::aux::ArrayStack::push
void push(const TType &value)
Pushes value to front of ArrayStack.
Definition: ArrayStack.hpp:144
ls::blocks::std::IntegratorBlock
Definition: IntegratorBlock.hpp:16