Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
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
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
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
00161 }
00162 BT_DEC_FAIL_END
00163 }
00164 BT_SEQ_END(RootElement);
00165 }
00166 BT_END(Decorators);
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
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 }