getting_started:tutorials:firstproject
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| getting_started:tutorials:firstproject [2015/08/06 13:03] – visentin | getting_started:tutorials:firstproject [2016/11/29 15:36] (current) – removed graf | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Your First EEROS Project ====== | ||
| - | First of all, make sure that you have set up your environment as described in [[..: | ||
| - | <code c> | ||
| - | int main() { | ||
| - | std::cout << "SCARA Robot Control started" | ||
| - | | ||
| - | // Define logger | ||
| - | StreamLogWriter w(std:: | ||
| - | w.show(); | ||
| - | Logger< | ||
| - | | ||
| - | // Get HAL istance | ||
| - | HAL& hal = HAL:: | ||
| - | | ||
| - | // Get Control System instance | ||
| - | MyControlSystem controlSystem; | ||
| - | | ||
| - | // Get Safety System instance | ||
| - | double dt = 0.001; | ||
| - | | ||
| - | MySafetyProperties safetyProperties(& | ||
| - | SafetySystem safetySystem (safetyProperties, | ||
| - | |||
| - | Sequencer sequencer; | ||
| - | MySequencer | ||
| - | sequencer.start(& | ||
| - | | ||
| - | while(sequencer.getState() != state:: | ||
| - | usleep(10000); | ||
| - | } | ||
| - | | ||
| - | controlSystem.stop(); | ||
| - | safetySystem.shutdown(); | ||
| - | sequencer.shutdown(); | ||
| - | | ||
| - | std::cout << "SCARA Robot Control stopped" | ||
| - | return 0; | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | To start, create an instance of the [[eeros_architecture: | ||
| - | |||
| - | Then you have to define the [[eeros_architecture: | ||
| - | |||
| - | Finally, a sequence has to be defined and assigned to a [[eeros_architecture: | ||
| - | |||
| - | Here follows the basic implementation of the three subsystems of a simple EEROS application: | ||
| - | |||
| - | === Control System: === | ||
| - | |||
| - | == .hpp: == | ||
| - | |||
| - | <code c> | ||
| - | #ifndef CH_NTB_TEST_MYCONTROLSYSTEM_HPP_ | ||
| - | #define CH_NTB_TEST_MYCONTROLSYSTEM_HPP_ | ||
| - | |||
| - | #include < | ||
| - | #include < | ||
| - | #include < | ||
| - | |||
| - | namespace testproject { | ||
| - | | ||
| - | class MyControlSystem { | ||
| - | | ||
| - | public: | ||
| - | MyControlSystem(); | ||
| - | | ||
| - | void start(); // starts timedomains | ||
| - | void stop(); | ||
| - | | ||
| - | // Define blocks here | ||
| - | | ||
| - | private: | ||
| - | eeros:: | ||
| - | | ||
| - | }; // end class | ||
| - | }; // end namepspace | ||
| - | |||
| - | #endif // | ||
| - | </ | ||
| - | |||
| - | == .cpp: == | ||
| - | |||
| - | <code c> | ||
| - | #include " | ||
| - | |||
| - | using namespace testproject; | ||
| - | |||
| - | MyControlSystem:: | ||
| - | |||
| - | timedomain(" | ||
| - | |||
| - | { | ||
| - | // Configure Blocks | ||
| - | | ||
| - | // Connect Blocks | ||
| - | // e.g. gain.getIn().connect(constant.getOut()); | ||
| - | | ||
| - | // Run Blocks | ||
| - | // e.g. timedomain.addBlock(& | ||
| - | } | ||
| - | |||
| - | void MyControlSystem:: | ||
| - | timedomain.start(); | ||
| - | } | ||
| - | |||
| - | void MyControlSystem:: | ||
| - | timedomain.stop(); | ||
| - | timedomain.join(); | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | === Safety System: === | ||
| - | |||
| - | == .hpp: == | ||
| - | |||
| - | <code c> | ||
| - | #ifndef CH_NTB_TEST_MYSAFETYPROPERTIES_HPP_ | ||
| - | #define CH_NTB_TEST_MYSAFETYPROPERTIES_HPP_ | ||
| - | |||
| - | #include < | ||
| - | #include < | ||
| - | #include < | ||
| - | #include < | ||
| - | #include < | ||
| - | |||
| - | namespace testproject { | ||
| - | | ||
| - | class MyControlSystem; | ||
| - | | ||
| - | // ***** Define events ***** // | ||
| - | enum { | ||
| - | // e.g. doPowerUp = 1, | ||
| - | }; | ||
| - | | ||
| - | // ***** Define levels ***** // | ||
| - | enum { | ||
| - | // e.g. off = 1, | ||
| - | }; | ||
| - | | ||
| - | class MySafetyProperties : public eeros:: | ||
| - | |||
| - | public: | ||
| - | MySafetyProperties(MyControlSystem* cs); | ||
| - | virtual ~MySafetyProperties(); | ||
| - | |||
| - | // ***** Define critical outputs ***** // | ||
| - | // e.g. eeros:: | ||
| - | |||
| - | // ***** Define critical inputs ***** // | ||
| - | | ||
| - | |||
| - | private: | ||
| - | MyControlSystem* controlSys; | ||
| - | |||
| - | }; // end class | ||
| - | }; // end namespace | ||
| - | |||
| - | #endif // | ||
| - | </ | ||
| - | |||
| - | == .cpp: == | ||
| - | |||
| - | <code c> | ||
| - | #include " | ||
| - | #include " | ||
| - | |||
| - | #include < | ||
| - | #include < | ||
| - | #include < | ||
| - | #include < | ||
| - | |||
| - | #include < | ||
| - | |||
| - | using namespace testproject; | ||
| - | using namespace eeros::hal; | ||
| - | using namespace eeros:: | ||
| - | using namespace eeros:: | ||
| - | |||
| - | MySafetyProperties:: | ||
| - | |||
| - | // Create HAL instance | ||
| - | HAL& hal = HAL:: | ||
| - | | ||
| - | // ***** Define critical outputs ***** // | ||
| - | watchdog = hal.getLogicPeripheralOutput(" | ||
| - | criticalOutputs = {watchdog}; | ||
| - | | ||
| - | // ***** Define critical inputs ***** // | ||
| - | emergencyButton = hal.getLogicPeripheralInput(" | ||
| - | criticalInputs = {emergencyButton}; | ||
| - | | ||
| - | // ***** Define levels ***** // | ||
| - | levels = { | ||
| - | {off, | ||
| - | }; | ||
| - | | ||
| - | // ***** Add events to levels ***** // | ||
| - | level(off | ||
| - | | ||
| - | // ***** Define inputs actions ***** // | ||
| - | | ||
| - | | ||
| - | // ***** Define output actions ***** // | ||
| - | | ||
| - | | ||
| - | // ***** Define level functions ***** // | ||
| - | level(off).setLevelAction([& | ||
| - | controlSys-> | ||
| - | privateContext-> | ||
| - | }); | ||
| - | | ||
| - | entryLevel = off; | ||
| - | } | ||
| - | | ||
| - | MySafetyProperties:: | ||
| - | // nothing to do | ||
| - | } | ||
| - | |||
| - | </ | ||
| - | |||
| - | === Main Sequencer: === | ||
| - | |||
| - | == .hpp: == | ||
| - | |||
| - | <code c> | ||
| - | #ifndef CH_NTB_TEST_MYSEQUENCER_HPP_ | ||
| - | #define CH_NTB_TEST_MYSEQUENCER_HPP_ | ||
| - | |||
| - | #include < | ||
| - | #include < | ||
| - | #include " | ||
| - | |||
| - | |||
| - | namespace testproject { | ||
| - | | ||
| - | class MySequencer : public eeros:: | ||
| - | | ||
| - | public: | ||
| - | MySequencer(eeros:: | ||
| - | |||
| - | virtual bool checkPreCondition(); | ||
| - | virtual void run(); | ||
| - | virtual void exit(); | ||
| - | |||
| - | private: | ||
| - | // Define subsequences here | ||
| - | // Example: Homing homingSequence; | ||
| - | |||
| - | bool isTerminating(); | ||
| - | |||
| - | testproject:: | ||
| - | eeros:: | ||
| - | |||
| - | }; // end class | ||
| - | }; // end namespace | ||
| - | |||
| - | #endif // CH_NTB_TEST_MYSEQUENCER_HPP_ | ||
| - | </ | ||
| - | |||
| - | == .cpp: == | ||
| - | |||
| - | <code c> | ||
| - | #include " | ||
| - | #include " | ||
| - | #include < | ||
| - | |||
| - | using namespace testproject; | ||
| - | using namespace eeros:: | ||
| - | using namespace eeros:: | ||
| - | |||
| - | MySequencer:: | ||
| - | Sequence< | ||
| - | // nothing to do | ||
| - | } | ||
| - | |||
| - | bool MySequencer:: | ||
| - | return safetySys-> | ||
| - | } | ||
| - | |||
| - | void MySequencer:: | ||
| - | log.info() << "Start sequence"; | ||
| - | sleep(1); | ||
| - | } | ||
| - | |||
| - | void MySequencer:: | ||
| - | log.info() << "Exit sequence"; | ||
| - | } | ||
| - | |||
| - | inline bool MySequencer:: | ||
| - | return sequencer-> | ||
| - | } | ||
| - | </ | ||
getting_started/tutorials/firstproject.1438859000.txt.gz · Last modified: 2015/08/06 13:03 by visentin