Example1.cpp
Go to the documentation of this file.
00001 /*
00002  * Filename: Example1.cpp
00003  *   Author: Igor Makhtes
00004  *     Date: Jan 8, 2014
00005  *
00006  * The MIT License (MIT)
00007  *
00008  * Copyright (c) 2014 Cogniteam Ltd.
00009  *
00010  * Permission is hereby granted, free of charge, to any person obtaining a copy
00011  * of this software and associated documentation files (the "Software"), to deal
00012  * in the Software without restriction, including without limitation the rights
00013  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00014  * copies of the Software, and to permit persons to whom the Software is
00015  * furnished to do so, subject to the following conditions:
00016  *
00017  * The above copyright notice and this permission notice shall be included in
00018  * all copies or substantial portions of the Software.
00019  *
00020  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00021  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00022  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00023  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00024  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00025  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00026  * THE SOFTWARE.
00027  */
00028 
00029 #include <iostream>
00030 #include <boost/bind.hpp>
00031 #include <boost/thread.hpp>
00032 #include <boost/foreach.hpp>
00033 #include <ros/ros.h>
00034 
00035 #include <decision_making/FSM.h>
00036 #include <decision_making/BT.h>
00037 #include <decision_making/ROSTask.h>
00038 #include <decision_making/DecisionMaking.h>
00039 
00040 using namespace std;
00041 using namespace decision_making;
00042 
00043 #define foreach BOOST_FOREACH
00044 
00045 const int TR_REPEAT_TASK = 10;
00046 
00047 //BT_BGN(D11)
00048 //{
00049 //    BT_CALL_TASK(CreateLocalGoal);
00050 //    BT_CALL_TASK(GoToLandmark);
00051 //
00052 //    BT_SEL_BGN(E1)
00053 //    {
00054 //        BT_SEQ_BGN(F1)
00055 //        {
00056 //            BT_CALL_TASK(IsGoal);
00057 //            BT_CALL_TASK(ReachedGoal);
00058 //        }
00059 //        BT_SEQ_END(F1);
00060 //
00061 //        // Reference to D1
00062 //
00063 //        //BT_CALL_BT(D1);
00064 //
00065 //        BT_TASK_BGN(RETURN_REPEAT)
00066 //        {
00067 //            BT_TASK_RESULT(TaskResult::FAIL(TR_REPEAT_TASK, "REPEAT D1"));
00068 //        }
00069 //        BT_TASK_END(RETURN_REPEAT);
00070 //    }
00071 //    BT_SEL_END(E1);
00072 //}
00073 //BT_END(D11);
00074 //
00075 //
00076 //BT_BGN(D1)
00077 //{
00078 //    BT_TASK_BGN(WHILE_RETURN_REPEAT)
00079 //    {
00080 //        TaskResult res;
00081 //        do{
00082 //            BT_CALL_BT(D11);
00083 //            res = BT_LAST_NODE->run();
00084 //        }while(res.error() == TR_REPEAT_TASK);
00085 //    }
00086 //    BT_TASK_END(WHILE_RETURN_REPEAT);
00087 //}
00088 //BT_END(D1);
00089 //
00090 //
00091 //
00092 //BT_BGN(C1)
00093 //{
00094 //    BT_CALL_TASK(MakeGlobalPath);
00095 //    BT_CALL_BT(D1);
00096 //}
00097 //BT_END(C1);
00098 //
00099 //
00100 //
00101 //BT_BGN(SemanticNavigation)
00102 //{
00103 //    BT_SEQ_BGN(SemanticNavigationRoot)
00104 //    {
00105 //        BT_CALL_TASK(WaitingForMainGoal);
00106 //        BT_SEL_BGN(A1)
00107 //        {
00108 //            BT_SEQ_BGN(B1)
00109 //            {
00110 //                BT_CALL_TASK(IsLocalized);
00111 //                BT_CALL_BT(C1);
00112 //            }
00113 //            BT_SEQ_END(B1);
00114 //
00115 //            BT_SEQ_BGN(B2)
00116 //            {
00117 //                BT_CALL_TASK(LookForLandmark);
00118 //
00119 //                BT_CALL_BT(D1);
00120 //            }
00121 //            BT_SEQ_END(B2);
00122 //
00123 //            BT_CALL_BT(C1);
00124 //        }
00125 //        BT_SEL_END(A1);
00126 //    }
00127 //    BT_SEQ_END(SemanticNavigationRoot);
00128 //}
00129 //BT_END(SemanticNavigation);
00130 
00131 
00132 
00133 BT_BGN(Decorators)
00134 {
00135     BT_SEQ_BGN(RootElement)
00136     {
00137         BT_DEC_SUCCESS_BGN
00138         {
00139             BT_CALL_TASK(Task11);
00140             BT_CALL_TASK(Task12);
00141             BT_CALL_TASK(Task13);
00142 //            BT_SET_TASK_RESULT(1);
00143         }
00144         BT_DEC_SUCCESS_END
00145 
00146         BT_DEC_NOT_BGN
00147         {
00148             BT_CALL_TASK(Task21);
00149             BT_CALL_TASK(Task22);
00150             BT_CALL_TASK(Task23);
00151 //            BT_SET_TASK_RESULT_AFTER(TaskResult::SUCCESS, 1);
00152         }
00153         BT_DEC_NOT_END
00154 
00155         BT_DEC_FAIL_BGN(100)
00156         {
00157             BT_CALL_TASK(Task31);
00158             BT_CALL_TASK(Task32);
00159             BT_CALL_TASK(Task33);
00160 //            BT_SET_TASK_RESULT(TaskResult::SUCCESS);
00161         }
00162         BT_DEC_FAIL_END
00163     }
00164     BT_SEQ_END(RootElement);
00165 }
00166 BT_END(Decorators);
00167 
00168 
00169 
00170 
00171 
00172 //
00173 //BT_BGN(SemanticNavigation)
00174 //{
00175 //    BT_SEQ_BGN(SemanticNavigationRoot)
00176 //    {
00177 //        BT_CALL_TASK(WaitingForMainGoal);
00178 //        BT_SEL_BGN(A1)
00179 //        {
00180 //            BT_SEQ_BGN(B1)
00181 //            {
00182 //                BT_CALL_TASK(IsLocalized);
00183 //                BT_SEQ_BGN(C1)
00184 //                {
00185 //                    BT_CALL_TASK(MakeGlobalPath);
00186 //                    BT_SEQ_BGN(D1)
00187 //                    {
00188 //                        BT_CALL_TASK(CreateLocalGoal);
00189 //                        BT_CALL_TASK(GoToLandmark);
00190 //
00191 //                        BT_SEL_BGN(E1)
00192 //                        {
00193 //                            BT_SEQ_BGN(F1)
00194 //                            {
00195 //                                BT_CALL_TASK(IsGoal);
00196 //                                BT_CALL_TASK(ReachedGoal);
00197 //                            }
00198 //                            BT_SEQ_END(F1);
00199 //
00200 //                            // Reference to D1
00201 //                        }
00202 //                        BT_SEL_END(E1);
00203 //                    }
00204 //                    BT_SEQ_END(D1);
00205 //                }
00206 //                BT_SEQ_END(C1);
00207 //            }
00208 //            BT_SEQ_END(B1);
00209 //
00210 //            BT_SEQ_BGN(B2)
00211 //            {
00212 //                BT_CALL_TASK(LookForLandmark);
00213 //
00214 //                // Reference to D1
00215 //            }
00216 //            BT_SEQ_END(B2);
00217 //
00218 //            // Reference to C1
00219 //        }
00220 //        BT_SEL_END(A1);
00221 //    }
00222 //    BT_SEQ_END(SemanticNavigationRoot);
00223 //}
00224 //BT_END(SemanticNavigation);
00225 
00226 
00227 
00228 
00229 
00230 
00231 
00232 
00233 
00234 
00235 FSM(SemanticNavigationFSM)
00236 {
00237     FSM_STATES
00238     {
00239         WaitingForMainGoal,
00240         IsLocalized,
00241         MakeGlobalPath,
00242         CreateLocalGoal,
00243         GoToLandmark,
00244         IsGoal,
00245         LookForLandmark,
00246         ReachedGoal
00247     }
00248     FSM_START(WaitingForMainGoal)
00249     FSM_BGN
00250     {
00252         FSM_STATE(WaitingForMainGoal)
00253         {
00254             FSM_CALL_TASK(WaitingForMainGoal)
00255 
00256             FSM_TRANSITIONS
00257             {
00258                 FSM_ON_EVENT(/RECEIVED_GOAL, FSM_NEXT(IsLocalized))
00259             }
00260         }
00262         FSM_STATE(IsLocalized)
00263         {
00264             FSM_CALL_TASK(IsLocalized)
00265 
00266             FSM_TRANSITIONS
00267             {
00268                 FSM_ON_EVENT(/KNOWN_LOC, FSM_NEXT(MakeGlobalPath))
00269         FSM_ON_EVENT(/NOT_KNOWN_LOC, FSM_NEXT(LookForLandmark))
00270             }
00271         }
00273         FSM_STATE(MakeGlobalPath)
00274         {
00275             FSM_CALL_TASK(MakeGlobalPath)
00276 
00277             FSM_TRANSITIONS
00278             {
00279                 FSM_ON_EVENT(/PATH_IS_RDY, FSM_NEXT(CreateLocalGoal))
00280             }
00281         }
00283         FSM_STATE(CreateLocalGoal)
00284         {
00285             FSM_CALL_TASK(CreateLocalGoal)
00286 
00287             FSM_TRANSITIONS
00288             {
00289                 FSM_ON_EVENT(/LOCAL_GOAL_UPDATED, FSM_NEXT(GoToLandmark))
00290             }
00291         }
00293         FSM_STATE(GoToLandmark)
00294         {
00295             FSM_CALL_TASK(GoToLandmark)
00296 
00297             FSM_TRANSITIONS
00298             {
00299                 FSM_ON_EVENT(/REACHED_LANDMARK, FSM_NEXT(IsGoal))
00300         FSM_ON_EVENT(/LOST, FSM_NEXT(LookForLandmark))
00301             }
00302         }
00304         FSM_STATE(IsGoal)
00305         {
00306             FSM_CALL_TASK(IsGoal)
00307 
00308             FSM_TRANSITIONS
00309             {
00310                 FSM_ON_EVENT(/IS_GOAL, FSM_NEXT(ReachedGoal))
00311         FSM_ON_EVENT(/NOT_GOAL, FSM_NEXT(CreateLocalGoal))
00312             }
00313         }
00315         FSM_STATE(LookForLandmark)
00316         {
00317             FSM_CALL_TASK(LookForLandmark)
00318 
00319             FSM_TRANSITIONS
00320             {
00321                 FSM_ON_EVENT(/FOUND_UNEXPECTED_LANDMARK, FSM_NEXT(MakeGlobalPath))
00322         FSM_ON_EVENT(/FOUND_EXPECTED_LANDMARK, FSM_NEXT(CreateLocalGoal))
00323             }
00324         }
00326         FSM_STATE(ReachedGoal)
00327         {
00328             FSM_CALL_TASK(ReachedGoal)
00329 
00330             FSM_TRANSITIONS
00331             {
00332                 FSM_ON_EVENT(/FINISHED, FSM_NEXT(WaitingForMainGoal))
00333             }
00334         }
00335     }
00336     FSM_END
00337 }
00338 
00339 
00340 int main(int argc, char **argv) {
00341     ros::init(argc, argv, "bt_example1");
00342     ros_decision_making_init(argc, argv);
00343 
00344     ros::AsyncSpinner spinner(2);
00345     spinner.start();
00346 
00347         return 0;
00348 }


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