Roomba.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 
00019 bool leftBumper, rightBumper, wallSensor;
00020 FSM(Roomba)
00021 {
00022         enum STATES
00023         {
00024                 findWall,
00025                 turnSx,
00026                 correctSx,
00027                 correctDx
00028         }
00029         FSM_START(findWall);
00030         FSM_BGN
00031         {
00032                 FSM_STATE(findWall)
00033                 {
00034                         FSM_TRANSITIONS
00035                         {
00036                                 FSM_ON_CONDITION( leftBumper==1||rightBumper==1 , FSM_NEXT(turnSx));
00037                         }
00038                 }
00039                 FSM_STATE(turnSx)
00040                 {
00041 
00042                         FSM_TRANSITIONS
00043                         {
00044                                 FSM_ON_CONDITION( leftBumper==0&&rightBumper==0 , FSM_NEXT(correctDx));
00045                         }
00046                 }
00047                 FSM_STATE(correctSx)
00048                 {
00049 
00050                         FSM_TRANSITIONS
00051                         {
00052                                 FSM_ON_CONDITION( leftBumper==1||rightBumper==1 , FSM_NEXT(turnSx));
00053                                 FSM_ON_CONDITION( wallSensor==0 , FSM_NEXT(correctDx));
00054                         }
00055                 }
00056                 FSM_STATE(correctDx)
00057                 {
00058 
00059                         FSM_TRANSITIONS
00060                         {
00061                                 FSM_ON_CONDITION( leftBumper==1||rightBumper==1 , FSM_NEXT(turnSx));
00062                                 FSM_ON_CONDITION( wallSensor==1 , FSM_NEXT(correctSx));
00063                         }
00064                 }
00065         }
00066         FSM_END
00067 }
00068 
00069 void run_fsm(){
00070         FsmRoomba(NULL, mainEventQueue);
00071 }
00072 
00073 
00074 void EVENTS_GENERATOR(){
00075         Event spec[]={"---","REPEAT"};
00076         int i=0;
00077         boost::this_thread::sleep(boost::posix_time::seconds(1));
00078         while(true and ros::ok()){
00079                 Event t = spec[i];
00080                 if(t == "REPEAT"){ i=1; t=spec[0]; }else i++;
00081                 cout << endl << t<<" -> ";
00082                 mainEventQueue->riseEvent(t);
00083                 boost::this_thread::sleep(boost::posix_time::seconds(1));
00084         }
00085         mainEventQueue->close();
00086 }
00087 
00088 int main(int argc, char** argv){
00089 
00090         ros::init(argc, argv, "Roomba");
00091         MainEventQueue meq;
00092         ros_decision_making_init(argc, argv);
00093 
00094         boost::thread_group threads;
00095         threads.add_thread(new boost::thread(boost::bind(&run_fsm)));
00096         threads.add_thread(new boost::thread(boost::bind(&EVENTS_GENERATOR)));
00097 
00098         ros::spin();
00099         threads.join_all();
00100 
00101         return 0;
00102 }
00103 
00104 


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