User Tools

Site Tools


getting_started:tutorials:firstproject

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
getting_started:tutorials:firstproject [2015/08/06 13:02] visentingetting_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 [[..:install_and_setup_development_environment|Install and Setup Development Environment]]. The following example shows a typical EEROS application.  + 
 +  - First of all, make sure that you have set up your environment as described in [[..:install_and_setup_development_environment|Install and Setup Development Environment]].  
 +  - Then create a new project following the steps under "preparation" on [[getting_started:tutorials:helloworld|Getting Started]]. 
 +  - 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:tutorials:helloworld|Getting Started]], "Say Hello World with EEROS", point 2 and 3.  
 <code c> <code c>
 +#include <iostream>
 +#include <unistd.h>
 +
 +#include <eeros/logger/Logger.hpp>
 +#include <eeros/logger/StreamLogWriter.hpp>
 +
 +#include "MySequencer.hpp"
 +#include "MySafetyProperties.hpp"
 +#include "MyControlSystem.hpp"
 +
 +
 +using namespace eeros;
 +using namespace eeros::hal;
 +using namespace eeros::control;
 +using namespace eeros::safety;
 +using namespace eeros::logger;
 +using namespace eeros::sequencer;
 +using namespace testproject;
 +
 +
 int main() { int main() {
   std::cout << "SCARA Robot Control started" << std::endl;   std::cout << "SCARA Robot Control started" << std::endl;
Line 26: Line 51:
   sequencer.start(&mainSequence);   sequencer.start(&mainSequence);
      
-  while(sequencer.getState() != state::terminated) { +//  while(sequencer.getState() != state::terminated) { 
-      usleep(10000); +//      usleep(10000); 
-  }+//  } 
 +   
 +  sequencer.join();
      
-  controlSystem.stop(); +//  controlSystem.stop(); 
-  safetySystem.shutdown(); +//  safetySystem.shutdown(); 
-  sequencer.shutdown();+//  sequencer.shutdown();
      
   std::cout << "SCARA Robot Control stopped" << std::endl;   std::cout << "SCARA Robot Control stopped" << std::endl;
Line 99: Line 126:
     // Run Blocks     // Run Blocks
     // e.g. timedomain.addBlock(&constant);     // e.g. timedomain.addBlock(&constant);
-} 
- 
-void MyControlSystem::start() { 
-    timedomain.start(); 
-} 
- 
-void MyControlSystem::stop() { 
-    timedomain.stop(); 
-    timedomain.join();   
 } }
 </code> </code>
Line 225: Line 243:
  
 <code c> <code c>
 +#ifndef CH_NTB_TEST_MYSEQUENCER_HPP_
 +#define CH_NTB_TEST_MYSEQUENCER_HPP_
 +
 +#include <eeros/sequencer/Sequence.hpp>
 +#include <eeros/safety/SafetySystem.hpp>
 +#include "MyControlSystem.hpp"
 +
 +
 +namespace testproject {
 +    
 +    class MySequencer : public eeros::sequencer::Sequence<void> {
 +    
 +    public:
 + MySequencer(eeros::sequencer::Sequencer* sequencer, testproject::MyControlSystem* controlSys, eeros::safety::SafetySystem* safetySys);
 +
 + virtual bool checkPreCondition();
 + virtual void run();
 + virtual void exit();
 +
 +    private: 
 + // Define subsequences here
 + // Example: Homing homingSequence; 
 +
 + bool isTerminating();
 +
 + testproject::MyControlSystem* controlSys;
 + eeros::safety::SafetySystem* safetySys;
 +
 +    }; // end class
 +};     // end namespace
 +
 +#endif // CH_NTB_TEST_MYSEQUENCER_HPP_
 </code> </code>
  
Line 230: Line 280:
  
 <code c> <code c>
 +#include "MySequencer.hpp"
 +#include "MySafetyProperties.hpp"
 +#include <unistd.h>
 +
 +using namespace testproject;
 +using namespace eeros::sequencer;
 +using namespace eeros::safety;
 +
 +MySequencer::MySequencer(Sequencer* sequencer, MyControlSystem* controlSys, SafetySystem* safetySys) : 
 + Sequence< void >("main", sequencer), controlSys(controlSys), safetySys(safetySys) {
 +    // nothing to do 
 +}
 +
 +bool MySequencer::checkPreCondition() {
 +    return safetySys->getCurrentLevel().getId() >= off;   
 +}
 +
 +void MySequencer::run() {
 +    log.info() << "Start sequence";
 +    sleep(1);   
 +}
 +
 +void MySequencer::exit() {
 +    log.info() << "Exit sequence";
 +}
 +
 +inline bool MySequencer::isTerminating() {
 +    return sequencer->getState() == state::terminating;
 +}
 </code> </code>
  
 +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 "${CMAKE_CXX_FLAGS} -std=c++11")
 +
 +add_executable(test-project 
 +       main.cpp
 +       MyControlSystem.cpp
 +       MySafetyProperties.cpp
 +       MySequencer.cpp)
 +
 +target_link_libraries(test-project eeros)
 +</code>