Controller.h
Go to the documentation of this file.
00001 /* -*- mode: C++ -*-
00002  *
00003  *  Base class for finite state machine states
00004  *
00005  *  Copyright (C) 2007, 2010, Austin Robot Technology
00006  *
00007  *  License: Modified BSD Software License Agreement
00008  *
00009  *  $Id: Controller.h 873 2010-11-28 13:57:03Z jack.oquin $
00010  */
00011 
00012 #ifndef __CONTROLLER_HH__
00013 #define __CONTROLLER_HH__
00014 
00015 #include "navigator_internal.h"
00016 
00017 class Controller
00018 {
00019 public:
00020 
00021   typedef enum
00022     {
00023       // safety results come first, their order is significant
00024       OK,
00025       Caution,
00026       Beware,
00027       Unsafe,
00028       Blocked,
00029       // other results follow safety
00030       Collision,
00031       Finished,
00032       NotApplicable,
00033       NotImplemented,
00034       N_results
00035     } result_t;
00036 
00037   // return result name as a C string
00038   const char *result_name(result_t result)
00039   {
00040     static const char *rname[N_results] =
00041       {
00042         "OK",
00043         "Caution",
00044         "Beware",
00045         "Unsafe",
00046         "Blocked",
00047         "Collision",
00048         "Finished",
00049         "NotApplicable",
00050         "NotImplemented",
00051       };
00052     return rname[result];
00053   }
00054 
00055   Controller(Navigator *navptr, int _verbose)
00056   {
00057     verbose = _verbose;
00058     nav = navptr;
00059 
00060     // save pointers to frequently-used Navigator data
00061     course = nav->course;
00062     estimate = &nav->estimate;
00063     navdata = &nav->navdata;
00064     obstacle = nav->obstacle;
00065     odom = nav->odometry;
00066     order = &nav->order;
00067     pops = nav->pops;
00068     config_ = &nav->config_;
00069 
00070     // start the controller from its reset state
00071     // (any subordinate controller constructors will reset themselves)
00072     reset_me();
00073   };
00074 
00075   virtual ~Controller() {};
00076 
00077   // generic controller method
00078   virtual result_t control(pilot_command_t &pcmd)
00079   {
00080     return OK;
00081   };
00082 
00083   // reset the controller and all its subordinates to a known state
00084   virtual void reset(void) {};
00085 
00086   // trace controller state
00087   virtual void trace(const char *name, const pilot_command_t &pcmd)
00088   {
00089     ROS_DEBUG_NAMED("trace", "%s: pcmd = (%.3f, %.3f) ",
00090                     name, pcmd.velocity, pcmd.yawRate);
00091   }
00092 
00093   // trace controller state and result
00094   virtual void trace(const char *name, const pilot_command_t &pcmd,
00095                      result_t res)
00096   {
00097     ROS_DEBUG_NAMED("trace", "%s: pcmd = (%.3f, %.3f), result = %s",
00098                     name, pcmd.velocity, pcmd.yawRate,
00099                     result_name(res));
00100   }
00101 
00102   // trace controller resets
00103   virtual void trace_reset(const char *name)
00104   {
00105     if (verbose >= 2)
00106       ART_MSG(5, "%s::reset()", name);
00107   }
00108 
00109 protected:
00110   Navigator *nav;
00111   int verbose;
00112 
00113   // convenience pointers to public Navigator control data
00114   Course *course;
00115   Obstacle *obstacle;
00116   nav_msgs::Odometry *estimate;
00117   art_msgs::NavigatorState *navdata;
00118   nav_msgs::Odometry *odom;
00119   art_msgs::Order *order;
00120   PolyOps *pops;
00121   const Config *config_;
00122 
00123   // reset this controller only
00124   virtual void reset_me(void) {};
00125 };
00126 
00127 #endif // __CONTROLLER_HH__


art_nav
Author(s): Austin Robot Technology, Jack O'Quin
autogenerated on Fri Jan 3 2014 11:08:43