mission_exec.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002  * mission_exec.cpp
00003  *
00004  *  Created on: Mar 24, 2014
00005  *      Author: Filip Mandic
00006  *
00007  ********************************************************************/
00008 
00009 /*********************************************************************
00010 * Software License Agreement (BSD License)
00011 *
00012 *  Copyright (c) 2014, LABUST, UNIZG-FER
00013 *  All rights reserved.
00014 *
00015 *  Redistribution and use in source and binary forms, with or without
00016 *  modification, are permitted provided that the following conditions
00017 *  are met:
00018 *
00019 *   * Redistributions of source code must retain the above copyright
00020 *     notice, this list of conditions and the following disclaimer.
00021 *   * Redistributions in binary form must reproduce the above
00022 *     copyright notice, this list of conditions and the following
00023 *     disclaimer in the documentation and/or other materials provided
00024 *     with the distribution.
00025 *   * Neither the name of the LABUST nor the names of its
00026 *     contributors may be used to endorse or promote products derived
00027 *     from this software without specific prior written permission.
00028 *
00029 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00030 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00031 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00032 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00033 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00034 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00035 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00036 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00037 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00038 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00039 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00040 *  POSSIBILITY OF SUCH DAMAGE.
00041 *********************************************************************/
00042 
00043 #include <labust_mission/labustMission.hpp>
00044 #include <labust_mission/primitiveManager.hpp>
00045 #include <labust_mission/missionExecution.hpp>
00046 
00047 #include <tinyxml2.h>
00048 
00049 #include <decision_making/SynchCout.h>
00050 #include <decision_making/BT.h>
00051 #include <decision_making/FSM.h>
00052 #include <decision_making/ROSTask.h>
00053 #include <decision_making/DecisionMaking.h>
00054 
00055 using namespace decision_making;
00056 using namespace tinyxml2;
00057 
00058 /*********************************************************************
00059 *** Global variables
00060 *********************************************************************/
00061 
00062 EventQueue* mainEventQueue;
00063 labust::mission::MissionExecution* ME = NULL;
00064 
00065 struct MainEventQueue{
00066 MainEventQueue(){ mainEventQueue = new RosEventQueue(); }
00067 ~MainEventQueue(){ delete mainEventQueue; }
00068 };
00069 
00070 /*********************************************************************
00071  *** Finite State Machine
00072  *********************************************************************/
00073 
00074         /* Mission selection  */
00075         FSM(MissionSelect)
00076         {
00077                 FSM_STATES
00078                 {
00079                         /*** Execution states */
00080                         Wait_state,
00081                         Dispatcher_state,
00082                         placeholder_state,
00083                         /*** Primitive states */
00084                         go2point_FA_state,
00085                         dynamic_positioning_state,
00086                         course_keeping_state,
00087                         //iso_state,
00088                         //path_following_state,
00089                         //pointer_state
00090                 }
00091                 FSM_START(Wait_state);
00092                 FSM_BGN
00093                 {
00094                         FSM_STATE(Wait_state)
00095                         {
00096                                 ROS_ERROR("Mission waiting...");
00097 
00098                                 FSM_ON_STATE_EXIT_BGN{
00099 
00100                                         ROS_ERROR("Starting mission...");
00102                                         //ros::Rate(ros::Duration(1.0)).sleep(); Vidjeti je li potrebno
00103 
00105                                         ME->oldPosition.north = ME->state.position.north;
00106                                         ME->oldPosition.east = ME->state.position.east;
00107                                         ME->oldPosition.depth = ME->state.position.depth;
00108 
00109                                 }FSM_ON_STATE_EXIT_END
00110 
00111                                 FSM_TRANSITIONS
00112                                 {
00113                                         FSM_ON_EVENT("/START_DISPATCHER", FSM_NEXT(Dispatcher_state));
00114                                 }
00115                         }
00116                         FSM_STATE(Dispatcher_state)
00117                         {
00118                                 ROS_ERROR("Dispatcher active");
00119                                 ME->missionActive = true;
00120                                 ME->requestPrimitive();
00121 
00122                                 FSM_TRANSITIONS
00123                                 {
00124                                         FSM_ON_EVENT("/STOP", FSM_NEXT(Wait_state));
00125                                         FSM_ON_EVENT("/PLACEHOLDER", FSM_NEXT(placeholder_state));
00126                                         FSM_ON_EVENT("/GO2POINT_FA", FSM_NEXT(go2point_FA_state));
00127                                         FSM_ON_EVENT("/DYNAMIC_POSITIONING", FSM_NEXT(dynamic_positioning_state));
00128                                         //FSM_ON_EVENT("/COURSE_KEEPING", FSM_NEXT(course_keeping_state));
00129                                         //FSM_ON_EVENT("/ISO", FSM_NEXT(iso_state));
00130                                         //FSM_ON_EVENT("/PATH_FOLLOWING", FSM_NEXT(path_following_state));
00131                                         //FSM_ON_EVENT("/POINTER", FSM_NEXT(pointer_state));
00132                                 }
00133                         }
00134                         FSM_STATE(placeholder_state)
00135                         {
00136                                 ROS_ERROR("Placeholder active");
00137 
00138                                 FSM_TRANSITIONS
00139                                 {
00140                                         FSM_ON_EVENT("/STOP", FSM_NEXT(Wait_state));
00141                                         FSM_ON_EVENT("/PRIMITIVE_FINISHED", FSM_NEXT(Dispatcher_state));
00142                                         FSM_ON_EVENT("/TIMEOUT", FSM_NEXT(Dispatcher_state));
00143                                 }
00144                         }
00145                         FSM_STATE(go2point_FA_state)
00146                         {
00147                                 ROS_ERROR("go2point_FA primitive active");
00148 
00149                                 ME->go2point_FA_state();
00150 
00151                                 FSM_ON_STATE_EXIT_BGN{
00152 
00153                                         ME->CM.go2point_FA(false,0,0,0,0,0,0);
00154 
00155                                 }FSM_ON_STATE_EXIT_END
00156 
00157                                 FSM_TRANSITIONS
00158                                 {
00159                                         FSM_ON_EVENT("/STOP", FSM_NEXT(Wait_state));
00160                                         FSM_ON_EVENT("/PRIMITIVE_FINISHED", FSM_NEXT(Dispatcher_state));
00161                                         FSM_ON_EVENT("/TIMEOUT", FSM_NEXT(Dispatcher_state));
00162 
00163                                 }
00164                         }
00165                         FSM_STATE(dynamic_positioning_state)
00166                         {
00167                                 ROS_ERROR("dynamic_positioning primitive active");
00168 
00169                                 ME->dynamic_postitioning_state();
00170 
00171                                 FSM_ON_STATE_EXIT_BGN{
00172 
00173                                         ME->CM.dynamic_positioning(false,0,0,0);
00174 
00175                                 }FSM_ON_STATE_EXIT_END
00176 
00177                                 FSM_TRANSITIONS
00178                                 {
00179                                         FSM_ON_EVENT("/STOP", FSM_NEXT(Wait_state));
00180                                         FSM_ON_EVENT("/PRIMITIVE_FINISHED", FSM_NEXT(Dispatcher_state));
00181                                         FSM_ON_EVENT("/TIMEOUT", FSM_NEXT(Dispatcher_state));
00182                                 }
00183                         }
00184 /*                      FSM_STATE(course_keeping_state)
00185                         {
00186                                 ROS_ERROR("course_keeping_FA primitive active");
00187 
00188                                 ME->course_keeping_FA_state();
00189 
00190                                 FSM_ON_STATE_EXIT_BGN{
00191 
00192                                         ME->CM.course_keeping_FA(false,0,0,0);
00193 
00194                                         ME->oldPosition.north = ME->state.position.north;
00195                                         ME->oldPosition.east = ME->state.position.east;
00196                                         ME->oldPosition.depth = ME->state.position.depth;
00197 
00198                                 }FSM_ON_STATE_EXIT_END
00199 
00200                                 FSM_TRANSITIONS
00201                                 {
00202                                         FSM_ON_EVENT("/STOP", FSM_NEXT(Wait_state));
00203                                         FSM_ON_EVENT("/PRIMITIVE_FINISHED", FSM_NEXT(Dispatcher_state));
00204                                         FSM_ON_EVENT("/TIMEOUT", FSM_NEXT(Dispatcher_state));
00205                                 }
00206                         }*/
00207 /*                      FSM_STATE(iso_state)
00208                         {
00209                                 ROS_ERROR("iso primitive active");
00210 
00211                                 ME->iso_state();
00212 
00213 
00214                                 FSM_ON_STATE_EXIT_BGN{
00215 
00216                                         ME->CM.ISOprimitive(false,0,0,0,0,0);
00217 
00218                                         ME->oldPosition.north = ME->state.position.north;
00219                                         ME->oldPosition.east = ME->state.position.east;
00220                                         ME->oldPosition.depth = ME->state.position.depth;
00221 
00222                                 }FSM_ON_STATE_EXIT_END
00223 
00224                                 FSM_TRANSITIONS
00225                                 {
00226                                         FSM_ON_EVENT("/STOP", FSM_NEXT(Wait_state));
00227                                         FSM_ON_EVENT("/PRIMITIVE_FINISHED", FSM_NEXT(Dispatcher_state));
00228                                         FSM_ON_EVENT("/TIMEOUT", FSM_NEXT(Dispatcher_state));
00229                                 }
00230                         }
00231                         FSM_STATE(path_following_state)
00232                         {
00233                                 ROS_ERROR("path_following primitive active");
00234 
00235                                 ME->path_following_state();
00236 
00237 
00238                                 FSM_ON_STATE_EXIT_BGN{
00239 
00240                                 }FSM_ON_STATE_EXIT_END
00241 
00242                                 FSM_TRANSITIONS
00243                                 {
00244                                         FSM_ON_EVENT("/STOP", FSM_NEXT(Wait_state));
00245                                         FSM_ON_EVENT("/PRIMITIVE_FINISHED", FSM_NEXT(Dispatcher_state));
00246                                         FSM_ON_EVENT("/TIMEOUT", FSM_NEXT(Dispatcher_state));
00247                                 }
00248                         }
00249                         FSM_STATE(pointer_state)
00250                         {
00251                                 ROS_ERROR("pointer primitive active");
00252 
00253                                 ME->pointer_state();
00254 
00255 
00256                                 FSM_ON_STATE_EXIT_BGN{
00257 
00258                                 }FSM_ON_STATE_EXIT_END
00259 
00260                                 FSM_TRANSITIONS
00261                                 {
00262                                         FSM_ON_EVENT("/STOP", FSM_NEXT(Wait_state));
00263                                         FSM_ON_EVENT("/PRIMITIVE_FINISHED", FSM_NEXT(Dispatcher_state));
00264                                         FSM_ON_EVENT("/TIMEOUT", FSM_NEXT(Dispatcher_state));
00265                                 }
00266                         }*/
00267                 }
00268                 FSM_END
00269         }
00270 
00271 
00272 /*********************************************************************
00273  ***  Main function
00274  ********************************************************************/
00275 
00276 int main(int argc, char** argv){
00277 
00278         ros::init(argc, argv, "ControllerFSM");
00279         ros_decision_making_init(argc, argv);
00280         ros::NodeHandle nh;
00281 
00282         /* Start Mission Execution */
00283         labust::mission::MissionExecution MissExec(nh);
00284         ME = &MissExec;
00285 
00286         /* Global event queue */
00287         MainEventQueue meq;
00288 
00289         /* Start state machine */
00290         ros::AsyncSpinner spinner(2);
00291         spinner.start();
00292         FsmMissionSelect(NULL, mainEventQueue);
00293         spinner.stop();
00294 
00295         return 0;
00296 }
00297 
00298 
00299 


labust_mission
Author(s): Filip Mandic
autogenerated on Fri Aug 28 2015 11:23:04