Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages | Examples

ArPriorityResolver.cpp

00001 /*
00002 MobileRobots Advanced Robotics Interface for Applications (ARIA)
00003 Copyright (C) 2004, 2005 ActivMedia Robotics LLC
00004 Copyright (C) 2006, 2007 MobileRobots Inc.
00005 
00006      This program is free software; you can redistribute it and/or modify
00007      it under the terms of the GNU General Public License as published by
00008      the Free Software Foundation; either version 2 of the License, or
00009      (at your option) any later version.
00010 
00011      This program is distributed in the hope that it will be useful,
00012      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014      GNU General Public License for more details.
00015 
00016      You should have received a copy of the GNU General Public License
00017      along with this program; if not, write to the Free Software
00018      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 If you wish to redistribute ARIA under different terms, contact 
00021 MobileRobots for information about a commercial version of ARIA at 
00022 robots@mobilerobots.com or 
00023 MobileRobots Inc, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481
00024 */
00025 
00026 #include "ArExport.h"
00027 #include "ariaOSDef.h"
00028 #include "ArPriorityResolver.h"
00029 #include "ArAction.h"
00030 #include "ArRobot.h"
00031 
00032 AREXPORT ArPriorityResolver::ArPriorityResolver() :
00033   ArResolver("ArPriorityResolver", "Resolves strictly by using priority, the highest priority action to act is the one that gets to go.  Does no mixing of any variety.")
00034 {
00035   
00036 
00037 }
00038 
00039 
00040 AREXPORT ArPriorityResolver::~ArPriorityResolver()
00041 {
00042 }
00043 
00044 AREXPORT ArActionDesired *ArPriorityResolver::resolve(
00045     ArResolver::ActionMap *actions, ArRobot *robot, bool logActions)
00046 {
00047   ArResolver::ActionMap::reverse_iterator it;
00048   ArAction *action;
00049   ArActionDesired *act;
00050   ArActionDesired averaging;
00051   bool first = true;
00052   int lastPriority;
00053   bool printedFirst = true;
00054   int printedLast;
00055   
00056   if (actions == NULL)
00057     return NULL;
00058 
00059   myActionDesired.reset();
00060   averaging.reset();
00061   averaging.startAverage();
00062   for (it = actions->rbegin(); it != actions->rend(); ++it)
00063   {
00064     action = (*it).second;
00065     if (action != NULL && action->isActive())
00066     {
00067       act = action->fire(myActionDesired);
00068       if (robot != NULL && act != NULL)
00069     act->accountForRobotHeading(robot->getTh());
00070       if (first || (*it).first != lastPriority)
00071       {
00072     averaging.endAverage();
00073     myActionDesired.merge(&averaging);
00074     
00075     averaging.reset();
00076     averaging.startAverage();
00077     first = false;
00078     lastPriority = (*it).first;
00079       }
00080       averaging.addAverage(act);
00081       if (logActions && act != NULL && act->isAnythingDesired())
00082       {
00083     if (printedFirst || printedLast != (*it).first)
00084     {
00085       ArLog::log(ArLog::Terse, "Priority %d:", (*it).first);
00086       printedLast = (*it).first;
00087       printedFirst = false;
00088     }
00089     ArLog::log(ArLog::Terse, "Action: %s", action->getName());
00090     act->log();
00091       }
00092     
00093     
00094     }
00095   }
00096   averaging.endAverage();
00097   myActionDesired.merge(&averaging);
00098   /*
00099   printf(
00100       "desired delta %.0f strength %.3f, desired speed %.0f strength %.3f\n",
00101       myActionDesired.getDeltaHeading(), myActionDesired.getHeadingStrength(), 
00102       myActionDesired.getVel(), myActionDesired.getVelStrength());
00103   */
00104   return &myActionDesired;
00105 }
00106 
00107 

Generated on Tue Feb 20 10:51:40 2007 for Aria by  doxygen 1.4.0