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
getting_started:tutorials:firstproject [2015/08/06 13:00] visentingetting_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 [[..:install_and_setup_development_environment|Install and Setup Development Environment]]. The following example shows a typical EEROS application.   
-<code c> 
-int main() { 
-  std::cout << "SCARA Robot Control started" << std::endl; 
-   
-  // Define logger 
-  StreamLogWriter w(std::cout); 
-  w.show(); 
-  Logger<LogWriter>::setDefaultWriter(&w); 
-   
-  // Get HAL istance  
-  HAL& hal = HAL::instance(); 
-   
-  // Get Control System instance 
-  MyControlSystem controlSystem; 
-   
-  // Get Safety System instance 
-  double dt = 0.001; 
-   
-  MySafetyProperties safetyProperties(&controlSystem); 
-  SafetySystem safetySystem (safetyProperties, dt); 
- 
-  Sequencer sequencer; 
-  MySequencer  mainSequence(&sequencer, &controlSystem, &safetySystem); 
-  sequencer.start(&mainSequence); 
-   
-  while(sequencer.getState() != state::terminated) { 
-      usleep(10000); 
-  } 
-   
-  controlSystem.stop(); 
-  safetySystem.shutdown(); 
-  sequencer.shutdown(); 
-   
-  std::cout << "SCARA Robot Control stopped" << std::endl; 
-  return 0; 
-} 
-</code> 
- 
-To start, create an instance of the [[eeros_architecture:control_system:start|Control System]] and [[eeros_architecture:safety_system:start|Safety System]]. Since the safety system is closely connected to the Hardware which is accessed through the [[eeros_architecture:safety_system:hal|Hardware Abstraction Layer]] (HAL), inputs and outputs for the HAL have to be defined and assigned to the HAL. \\ 
- 
-Then you have to define the [[eeros_architecture:safety_system:properties|Safety Properties]] and start the safety system. The safety system will power-up the system and do all the necessary initialization, such as enabling actors and homing them. \\ 
- 
-Finally, a sequence has to be defined and assigned to a [[eeros_architecture:sequencer:usage|Sequencer]]. The program will run as long as the sequencer does not terminate. 
- 
-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 <eeros/control/TimeDomain.hpp> 
-#include <eeros/control/Constant.hpp> 
-#include <eeros/control/Gain.hpp> 
- 
-namespace testproject { 
-   
-  class MyControlSystem { 
-   
-  public: 
-    MyControlSystem(); 
-     
-    void start(); // starts timedomains 
-    void stop();  // stops timedomains 
-     
-    // Define blocks here 
-     
-  private: 
-    eeros::control::TimeDomain timedomain; 
-     
-  };  // end class   
-};    // end namepspace 
- 
-#endif //CH_NTB_TEST_MYCONTROLSYSTEM_HPP_ 
-</code> 
- 
-== .cpp: == 
- 
-<code c> 
-#include "MyControlSystem.hpp" 
- 
-using namespace testproject; 
- 
-MyControlSystem::MyControlSystem() : 
-  
-timedomain("Main time domain", 0.001, true) 
- 
-{ 
-    // Configure Blocks 
-     
-    // Connect Blocks 
-    // e.g. gain.getIn().connect(constant.getOut()); 
-     
-    // Run Blocks 
-    // e.g. timedomain.addBlock(&constant); 
-} 
- 
-void MyControlSystem::start() { 
-    timedomain.start(); 
-} 
- 
-void MyControlSystem::stop() { 
-    timedomain.stop(); 
-    timedomain.join();   
-} 
-</code> 
- 
-=== Safety System: ===  
- 
-== .hpp: == 
- 
-<code c> 
-#ifndef CH_NTB_TEST_MYSAFETYPROPERTIES_HPP_ 
-#define CH_NTB_TEST_MYSAFETYPROPERTIES_HPP_ 
- 
-#include <eeros/safety/SafetyProperties.hpp> 
-#include <eeros/hal/HAL.hpp> 
-#include <eeros/hal/PeripheralOutput.hpp> 
-#include <eeros/hal/PeripheralInput.hpp> 
-#include <eeros/hal/ScalablePeripheralInput.hpp> 
- 
-namespace testproject { 
-     
-    class MyControlSystem; 
-     
-    // ***** Define events ***** // 
-    enum { 
- // e.g. doPowerUp = 1, 
-    }; 
-     
-    // ***** Define levels ***** // 
-    enum { 
- // e.g. off = 1, 
-    }; 
-     
-    class MySafetyProperties : public eeros::safety::SafetyProperties { 
-  
-    public:  
- MySafetyProperties(MyControlSystem* cs); 
- virtual ~MySafetyProperties(); 
-  
- // ***** Define critical outputs ***** // 
-  // e.g. eeros::hal::PeripheralOutput<bool>* watchdog; 
-  
- // ***** Define critical inputs ***** // 
-  //e.g. eeros::hal::PeripheralInput<bool>* emergencyButton; 
-  
-    private: 
- MyControlSystem* controlSys; 
-  
-    }; // end class 
-};     // end namespace 
- 
-#endif //CH_NTB_TEST_MYSAFETYPROPERTIES_HPP_ 
-</code> 
- 
-== .cpp: == 
- 
-<code c> 
-</code> 
- 
-=== Main Sequencer: === 
- 
-== .hpp: == 
- 
-<code c> 
-</code> 
- 
-== .cpp: == 
- 
-<code c> 
-</code> 
  
getting_started/tutorials/firstproject.1438858847.txt.gz · Last modified: 2015/08/06 13:00 (external edit)