EEROS  1.0.0.0
API for the EEROS Real-Time Robotics Framework
PeripheralOutput.hpp
Go to the documentation of this file.
1 #ifndef ORG_EEROS_CONTROL_PERIPHERALOUTPUT_HPP
2 #define ORG_EEROS_CONTROL_PERIPHERALOUTPUT_HPP
3 
4 #include <cmath>
6 #include <eeros/hal/HAL.hpp>
7 #include <eeros/core/Fault.hpp>
9 
10 namespace eeros {
11  namespace control {
12 
13  template < typename T = double >
14  class PeripheralOutput : public Block1i<T> {
15 
16  public:
17  PeripheralOutput(std::string id, bool exclusive = true) : hal(hal::HAL::instance()) {
18  systemOutput = dynamic_cast<hal::Output<T>*>(hal.getOutput(id, exclusive));
19  if(systemOutput == nullptr) throw Fault("Peripheral output '" + id + "' not found!");
20  }
21 
22  virtual void run() {
23  T val = this->in.getSignal().getValue();
24  if(std::isnan(val)) throw NaNOutputFault("NaN written to output");
25  systemOutput->set(val);
26  systemOutput->setTimestampSignalIn(this->in.getSignal().getTimestamp());
27  }
28 
29  template<typename ... ArgTypesOut>
30  void callOutputFeature(std::string featureName, ArgTypesOut... args){
31  hal.callOutputFeature(systemOutput, featureName, args...);
32  }
33 
34  private:
35  hal::HAL& hal;
36  hal::Output<T>* systemOutput;
37  };
38 
39  };
40 };
41 
42 #endif // ORG_EEROS_CONTROL_PERIPHERALOUTPUT_HPP
OutputInterface * getOutput(std::string name, bool exclusive=true)
Definition: HAL.cpp:143
Definition: HAL.hpp:18
Definition: Block1i.hpp:12
Definition: Config.hpp:14
virtual void run()
Definition: PeripheralOutput.hpp:22
PeripheralOutput(std::string id, bool exclusive=true)
Definition: PeripheralOutput.hpp:17
Definition: Fault.hpp:9
Definition: Output.hpp:18
void callOutputFeature(OutputInterface *obj, std::string featureName, ArgTypesOut...args)
Definition: HAL.hpp:38
Definition: NaNOutputFault.hpp:8
void callOutputFeature(std::string featureName, ArgTypesOut...args)
Definition: PeripheralOutput.hpp:30
Input< T > in
Definition: Block1i.hpp:21
Definition: PeripheralOutput.hpp:14