mbsimcontrol 4.0.0 MBSim Control Module

signal_manipulation.h
1 /* Copyright (C) 2004-2009 MBSim Development Team
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 *
17 * Contact: markus.ms.schneider@gmail.com
18 */
19
20 #ifndef _SIGNAL_MANIPULATION_H_
21 #define _SIGNAL_MANIPULATION_H_
22
23 #include "mbsimControl/signal_.h"
24 #include <mbsim/functions/function.h>
25
26 namespace MBSim {
27 using Index = int;
28 }
29
30 namespace MBSimControl {
31
36 class Multiplexer : public Signal {
37 public:
38 Multiplexer(const std::string &name="") : Signal(name) { }
39 void initializeUsingXML(xercesc::DOMElement *element) override;
40 void init(InitStage stage, const MBSim::InitConfigSet &config) override;
41 void addInputSignal(Signal * signal_) { signal.push_back(signal_); }
42 void updateSignal() override;
43 int getSignalSize() const override;
44 private:
45 std::vector<Signal*> signal;
46 std::vector<std::string> signalString;
47 };
48
53 class Demultiplexer : public Signal {
54 public:
55 Demultiplexer(const std::string &name="") : Signal(name) { }
56 void initializeUsingXML(xercesc::DOMElement *element) override;
57 void init(InitStage stage, const MBSim::InitConfigSet &config) override;
58 void setInputSignal(Signal *signal_) { signal = signal_; }
59 void setIndices(const std::vector<MBSim::Index> &index_) { index = index_; }
60 void updateSignal() override;
61 int getSignalSize() const override { return index.size(); }
62 private:
63 Signal *signal{nullptr};
64 std::vector<MBSim::Index> index;
65 std::string signalString;
66 };
67
72 class SignalTimeDiscretization : public Signal {
73 public:
74 SignalTimeDiscretization(const std::string &name="") : Signal(name) { }
75 void initializeUsingXML(xercesc::DOMElement *element) override;
76 void init(InitStage stage, const MBSim::InitConfigSet &config) override;
77 void setInputSignal(Signal *signal_) { s=signal_; }
78 void updateSignal() override;
79 int getSignalSize() const override { return s->getSignalSize(); }
80 private:
81 Signal *s{nullptr};
82 double tOld{-99e99};
83 std::string signalString;
84 };
85
90 class SignalOperation : public Signal {
91 public:
92 SignalOperation(const std::string &name="") : Signal(name) { }
93 ~SignalOperation() override { delete f1; delete f2; }
94 void initializeUsingXML(xercesc::DOMElement *element) override;
95 void init(InitStage stage, const MBSim::InitConfigSet &config) override;
96 void setInputSignal(Signal *signal_) { signal.resize(1,signal_); }
97 void addInputSignal(Signal *signal_) { signal.push_back(signal_); }
98 void setFunction(MBSim::Function<fmatvec::VecV(fmatvec::VecV)> *f) {
99 f1=f;
100 f1->setParent(this);
101 f1->setName("Function");
102 };
103 void setFunction(MBSim::Function<fmatvec::VecV(fmatvec::VecV,fmatvec::VecV)> *f) {
104 f2=f;
105 f2->setParent(this);
106 f2->setName("Function");
107 };
108 void setMultiplexInputSignals(bool multiplex_) { multiplex = multiplex_; }
109 void updateSignal() override { (this->*updateSignal_)(); }
110 void updateSignal1();
111 void updateSignal2();
112 int getSignalSize() const override { return f1?f1->getRetSize().first:f2->getRetSize().first; }
113 private:
114 std::vector<Signal*> signal;
115 std::vector<std::string> signalString;
116 MBSim::Function<fmatvec::VecV(fmatvec::VecV)> *f1{nullptr};
117 MBSim::Function<fmatvec::VecV(fmatvec::VecV,fmatvec::VecV)> *f2{nullptr};
118 bool multiplex{false};
119 void (SignalOperation::*updateSignal_)();
120 };
121
122 }
123
124 #endif /* _SIGNAL_MANIPULATION_H_ */
MBSimControl::SignalTimeDiscretization
SignalTimeDiscretization.
Definition: signal_manipulation.h:72
MBSimControl::SignalOperation
SignalOperation.
Definition: signal_manipulation.h:90
MBSimControl::Signal
Signal.
Definition: signal_.h:38
MBSimControl::Multiplexer
Multiplexer.
Definition: signal_manipulation.h:36
MBSim::Element::InitStage
InitStage
MBSim::Function
MBSim::Element::name
std::string name
MBSimControl::Demultiplexer
Demultiplexer.
Definition: signal_manipulation.h:53
MBSim::Element::setName
void setName(const std::string &str)