ScxmlHierarchyExample.cpp
Go to the documentation of this file.
00001 
00002 #include <ros/ros.h>
00003 #include <decision_making/SynchCout.h>
00004 #include <decision_making/BT.h>
00005 #include <decision_making/FSM.h>
00006 #include <decision_making/ROSTask.h>
00007 #include <decision_making/DecisionMaking.h>
00008 
00009 using namespace std;
00010 using namespace decision_making;
00011 
00012 EventQueue* mainEventQueue;
00013 struct MainEventQueue{
00014         MainEventQueue(){ mainEventQueue = new RosEventQueue(); }
00015         ~MainEventQueue(){ delete mainEventQueue; }
00016 };
00017 
00018 FSM(Superstate)
00019 {
00020         FSM_STATES
00021         {
00022                 Start, Process
00023         }
00024         FSM_START(Start);
00025         FSM_BGN
00026         {
00027                 FSM_STATE(Start)
00028                 {
00029                         FSM_TRANSITIONS
00030                         {
00031                                 FSM_ON_EVENT(/begin, FSM_NEXT(Process));
00032                                 FSM_ON_EVENT(/end, FSM_RISE(Start/end));
00033                                 FSM_ON_EVENT(/data, FSM_RISE(Start/data));
00034                         }
00035                 }
00036                 FSM_STATE(Process)
00037                 {
00038                         FSM_TRANSITIONS
00039                         {
00040                                 FSM_ON_EVENT(/data, FSM_NEXT(Process));
00041                                 FSM_ON_EVENT(/end, FSM_RISE(Process/end));
00042                                 FSM_ON_EVENT(/data, FSM_RISE(Process/data));
00043                         }
00044                 }
00045         }
00046         FSM_END
00047 }
00048 
00049 FSM(ScxmlHierarchyExample)
00050 {
00051         FSM_STATES
00052         {
00053                 Success, Error, Superstate
00054         }
00055         FSM_START(Superstate);
00056         FSM_BGN
00057         {
00058                 FSM_STATE(Success)
00059                 {
00060                         FSM_TRANSITIONS
00061                 }
00062                 FSM_STATE(Error)
00063                 {
00064                         FSM_TRANSITIONS
00065                 }
00066                 FSM_STATE(Superstate)
00067                 {
00068                         FSM_CALL_FSM(Superstate);
00069                         FSM_TRANSITIONS
00070                         {
00071                                 FSM_ON_EVENT(/error, FSM_NEXT(Error));
00072                                 FSM_ON_EVENT(Superstate/error, FSM_NEXT(Error));
00073                                 FSM_ON_EVENT(Superstate/Start/end, FSM_NEXT(Error));
00074                                 FSM_ON_EVENT(Superstate/Start/data, FSM_NEXT(Error));
00075                                 FSM_ON_EVENT(Superstate/Process/begin, FSM_NEXT(Error));
00076                                 FSM_ON_EVENT(Superstate/Process/end, FSM_NEXT(Success));
00077                         }
00078                 }
00079 
00080         }
00081         FSM_END
00082 }
00083 
00084 void run_fsm(){
00085         FsmScxmlHierarchyExample(NULL, mainEventQueue);
00086 }
00087 
00088 
00089 void EVENTS_GENERATOR(){
00090         Event spec[]={"---","REPEAT"};
00091         int i=0;
00092         boost::this_thread::sleep(boost::posix_time::seconds(1));
00093         while(true and ros::ok()){
00094                 Event t = spec[i];
00095                 if(t == "REPEAT"){ i=1; t=spec[0]; }else i++;
00096                 cout << endl << t<<" -> ";
00097                 mainEventQueue->riseEvent(t);
00098                 boost::this_thread::sleep(boost::posix_time::seconds(1));
00099         }
00100         mainEventQueue->close();
00101 }
00102 
00103 int main(int argc, char** argv){
00104 
00105         ros::init(argc, argv, "ScxmlHierarchyExample");
00106         MainEventQueue meq;
00107         ros_decision_making_init(argc, argv);
00108 
00109         boost::thread_group threads;
00110         threads.add_thread(new boost::thread(boost::bind(&run_fsm)));
00111         threads.add_thread(new boost::thread(boost::bind(&EVENTS_GENERATOR)));
00112 
00113         ros::spin();
00114         threads.join_all();
00115 
00116         return 0;
00117 }
00118 
00119 


decision_making_examples
Author(s):
autogenerated on Wed Aug 26 2015 11:17:01