Turnstile.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(Turnstile)
00019 {
00020         FSM_STATES
00021         {
00022                 Locked,
00023                 Unlocked
00024         }
00025         FSM_START(Locked);
00026         FSM_BGN
00027         {
00028                 FSM_STATE(Locked)
00029                 {
00030                         FSM_TRANSITIONS
00031                         {
00032                                 FSM_ON_EVENT(/COIN, FSM_NEXT(Unlocked));
00033                                 FSM_ON_EVENT(/PUSH, FSM_NEXT(Locked));
00034                         }
00035                 }
00036                 FSM_STATE(Unlocked)
00037                 {
00038                         FSM_TRANSITIONS
00039                         {
00040                                 FSM_ON_EVENT(/COIN, FSM_NEXT(Unlocked));
00041                                 FSM_ON_EVENT(/PUSH, FSM_NEXT(Locked));
00042                         }
00043                 }
00044         }
00045         FSM_END
00046 }
00047 
00048 void run_fsm(){
00049         FsmTurnstile(NULL, mainEventQueue);
00050 }
00051 
00052 
00053 void EVENTS_GENERATOR(){
00054         Event spec[]={"COIN","COIN","PUSH","PUSH", "REPEAT"};
00055         int i=0;
00056         boost::this_thread::sleep(boost::posix_time::seconds(1));
00057         while(true and ros::ok()){
00058                 Event t = spec[i];
00059                 if(t == "REPEAT"){ i=1; t=spec[0]; }else i++;
00060                 cout << endl << t<<" -> ";
00061                 mainEventQueue->riseEvent(t);
00062                 boost::this_thread::sleep(boost::posix_time::seconds(1));
00063         }
00064         mainEventQueue->close();
00065 }
00066 
00067 #include <boost/filesystem.hpp>
00068 
00069 int main(int argc, char** argv){
00070 
00071         ros::init(argc, argv, "Turnstile");
00072         MainEventQueue meq;
00073         ros_decision_making_init(argc, argv);
00074 
00075         boost::thread_group threads;
00076         threads.add_thread(new boost::thread(boost::bind(&run_fsm)));
00077         threads.add_thread(new boost::thread(boost::bind(&EVENTS_GENERATOR)));
00078 
00079         ros::spin();
00080         threads.join_all();
00081 
00082         return 0;
00083 }
00084 
00085 


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