EEROS  0.4.1.0
API for the EEROS Real-Time Robotics Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ZTransferFunction.hpp
Go to the documentation of this file.
1 #ifndef ORG_EEROS_CONTROL_ZTRANSFERFUNCTION_HPP_
2 #define ORG_EEROS_CONTROL_ZTRANSFERFUNCTION_HPP_
3 
4 #include <eeros/core/System.hpp>
7 #include <vector>
8 
9 namespace eeros {
10  namespace control {
11 
12  template < int ORDER >
14  static constexpr int N = (ORDER + 1);
15 
16  public:
18  fraction(copy) { }
19 
20  ZTransferFunction(const std::vector<double> a, const std::vector<double> b) :
21  fraction(b,a) { }
22 
23  static ZTransferFunction<1> PT1(double Ts, double K, double T1) {
24  return ZTransferFunction<1>( { Ts+T1, -T1 }, { K*Ts } );
25  }
26 
27  static ZTransferFunction<1> D(double Ts, double Tv) {
28  return ZTransferFunction<1>( { Ts }, { Tv, -Tv } );
29  }
30 
31  static ZTransferFunction<1> I(double Ts, double Tn) {
32  return ZTransferFunction<1>( { Tn, -Tn }, { Ts } );
33  }
34 
35  static ZTransferFunction<1> DT1(double Ts, double Tv, double T1) {
36  return ZTransferFunction<1>( { Ts+T1, -T1 }, { Tv, -Tv } );
37  }
38 
39  static ZTransferFunction<2> PID(double Ts, double Kp, double Tn, double Tv, double Tv1) {
40  return (I(Ts, Tn) + DT1(Ts, Tv, Tv1) + 1)*Kp;
41  }
42 
43  template < int RORDER >
45  return ZTransferFunction<ORDER+RORDER>(fraction * right.fraction);
46  }
47 
49  return ZTransferFunction<ORDER>(fraction * right);
50  }
51 
52  template < int RORDER >
54  return ZTransferFunction<ORDER+RORDER>(fraction + right.fraction);
55  }
56 
58  return ZTransferFunction<ORDER>(fraction + right);
59  }
60 
61  virtual void run() {
62  last_in[0] = in.getSignal().getValue();
63  last_out[0] = last_in[0] * fraction.numerator.c[0];
64  for (int i = 1; i < N; i++) {
65  last_out[0] += (last_in[i] * fraction.numerator.c[i] - last_out[i] * fraction.denominator.c[i]);
66  }
67  last_out[0] /= fraction.denominator.c[0];
68 
69  out.getSignal().setValue(last_out[0]);
71 
72  for (int i = (N - 1); i >= 0; i--) {
73  last_in[i] = last_in[i - 1];
74  last_out[i] = last_out[i - 1];
75  }
76  }
77 
78  private:
80  double last_in[N];
81  double last_out[N];
82  };
83  };
84 };
85 
86 #endif /* ORG_EEROS_CONTROL_ZTRANSFERFUNCTION_HPP_ */
virtual Signal< T > & getSignal()
Definition: Output.hpp:13
static ZTransferFunction< 1 > I(double Ts, double Tn)
Definition: ZTransferFunction.hpp:31
virtual T getValue() const
Definition: Signal.hpp:46
ZTransferFunction(const std::vector< double > a, const std::vector< double > b)
Definition: ZTransferFunction.hpp:20
ZTransferFunction< ORDER+RORDER > operator*(const ZTransferFunction< RORDER > right)
Definition: ZTransferFunction.hpp:44
static ZTransferFunction< 1 > D(double Ts, double Tv)
Definition: ZTransferFunction.hpp:27
Output< double > out
Definition: Block1i1o.hpp:26
static uint64_t getTimeNs()
Definition: System_POSIX.cpp:30
static ZTransferFunction< 2 > PID(double Ts, double Kp, double Tn, double Tv, double Tv1)
Definition: ZTransferFunction.hpp:39
virtual void setValue(T newValue)
Definition: Signal.hpp:50
ZTransferFunction(const eeros::math::Fraction< ORDER > &copy)
Definition: ZTransferFunction.hpp:17
virtual void setTimestamp(timestamp_t newTimestamp)
Definition: Signal.hpp:63
Definition: Fraction.hpp:13
Input< double > in
Definition: Block1i1o.hpp:25
virtual void run()
Definition: ZTransferFunction.hpp:61
Definition: Block1i1o.hpp:12
virtual Signal< T > & getSignal()
Definition: Input.hpp:35
static ZTransferFunction< 1 > PT1(double Ts, double K, double T1)
Definition: ZTransferFunction.hpp:23
Definition: ZTransferFunction.hpp:13
int i
Definition: RingBufferTest.cpp:12
static ZTransferFunction< 1 > DT1(double Ts, double Tv, double T1)
Definition: ZTransferFunction.hpp:35
ZTransferFunction< ORDER+RORDER > operator+(const ZTransferFunction< RORDER > right)
Definition: ZTransferFunction.hpp:53