getting_started:tutorials:firstproject
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
getting_started:tutorials:firstproject [2015/08/06 12:59] – visentin | getting_started:tutorials:firstproject [2016/10/07 14:02] – gehrig | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Your First EEROS Project ====== | ====== Your First EEROS Project ====== | ||
- | First of all, make sure that you have set up your environment as described in [[..: | + | |
+ | - First of all, make sure that you have set up your environment as described in [[..: | ||
+ | - Then create a new project following the steps under " | ||
+ | - The following example shows a typical EEROS application. | ||
+ | - After creating all those files, modify the CMakeLists.txt and CMAkeCache.txt files accoring to [[getting_started: | ||
<code c> | <code c> | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | #include " | ||
+ | #include " | ||
+ | #include " | ||
+ | |||
+ | |||
+ | using namespace eeros; | ||
+ | using namespace eeros::hal; | ||
+ | using namespace eeros:: | ||
+ | using namespace eeros:: | ||
+ | using namespace eeros:: | ||
+ | using namespace eeros:: | ||
+ | using namespace testproject; | ||
+ | |||
+ | |||
int main() { | int main() { | ||
std::cout << "SCARA Robot Control started" | std::cout << "SCARA Robot Control started" | ||
Line 26: | Line 51: | ||
sequencer.start(& | sequencer.start(& | ||
| | ||
- | | + | // |
- | usleep(10000); | + | // |
- | } | + | // } |
| | ||
- | controlSystem.stop(); | + | |
- | safetySystem.shutdown(); | + | |
- | sequencer.shutdown(); | + | // |
+ | // | ||
+ | // | ||
| | ||
std::cout << "SCARA Robot Control stopped" | std::cout << "SCARA Robot Control stopped" | ||
Line 99: | Line 126: | ||
// Run Blocks | // Run Blocks | ||
// e.g. timedomain.addBlock(& | // e.g. timedomain.addBlock(& | ||
- | } | ||
- | |||
- | void MyControlSystem:: | ||
- | timedomain.start(); | ||
- | } | ||
- | |||
- | void MyControlSystem:: | ||
- | timedomain.stop(); | ||
- | timedomain.join(); | ||
} | } | ||
</ | </ | ||
Line 116: | Line 134: | ||
<code c> | <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 // | ||
</ | </ | ||
Line 121: | Line 181: | ||
<code c> | <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 | ||
+ | } | ||
+ | |||
</ | </ | ||
Line 128: | Line 243: | ||
<code c> | <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_ | ||
</ | </ | ||
Line 133: | Line 280: | ||
<code c> | <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-> | ||
+ | } | ||
</ | </ | ||
+ | The related CMake File is: | ||
+ | |||
+ | <code c> | ||
+ | cmake_minimum_required(VERSION 2.8) | ||
+ | |||
+ | project(test-project) | ||
+ | |||
+ | include_directories(${ADDITIONAL_INCLUDE_DIRS}) | ||
+ | link_directories(${ADDITIONAL_LINK_DIRS}) | ||
+ | |||
+ | set(CMAKE_CXX_FLAGS " | ||
+ | |||
+ | add_executable(test-project | ||
+ | main.cpp | ||
+ | MyControlSystem.cpp | ||
+ | MySafetyProperties.cpp | ||
+ | MySequencer.cpp) | ||
+ | |||
+ | target_link_libraries(test-project eeros) | ||
+ | </ |