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

ArBumpers.cpp

00001 /*
00002 ActivMedia Robotics Interface for Applications (ARIA)
00003 Copyright (C) 2004,2005 ActivMedia Robotics, LLC
00004 
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 ActivMedia Robotics for information about a commercial version of ARIA at 
00022 robots@activmedia.com or 
00023 ActivMedia Robotics, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481
00024 
00025 */
00026 
00027 #include "ArExport.h"
00028 #include "ariaOSDef.h"
00029 #include "ArRobot.h"
00030 #include "ArBumpers.h"
00031 
00040 ArBumpers::ArBumpers(size_t currentBufferSize, size_t cumulativeBufferSize, 
00041                      const char *name, int maxSecondsToKeepCurrent, double angleRange) :
00042   ArRangeDevice(currentBufferSize, cumulativeBufferSize, name, 5000, maxSecondsToKeepCurrent), 
00043   myProcessCB(this, &ArBumpers::processReadings)
00044 {
00045   myBumpMask = (ArUtil::BIT1 | ArUtil::BIT2 | ArUtil::BIT3 | ArUtil::BIT4 | 
00046                 ArUtil::BIT5 | ArUtil::BIT6 | ArUtil::BIT7 | ArUtil::BIT8); 
00047 
00048   myAngleRange = angleRange;
00049 
00050   setCurrentDrawingData(new ArDrawingData("polyDots", ArColor(0, 0, 0),
00051                                           120, // mm diameter of dots
00052                                           83), // layer above most everything else
00053                         true);
00054 }
00055 
00056 ArBumpers::~ArBumpers()
00057 {
00058   if (myRobot != NULL)
00059     {
00060       myRobot->remSensorInterpTask(&myProcessCB);
00061       myRobot->remRangeDevice(this);
00062     }
00063 }
00064 
00065 void ArBumpers::setRobot(ArRobot *robot)
00066 {
00067   myRobot = robot;
00068   if (myRobot != NULL)
00069     myRobot->addSensorInterpTask(myName.c_str(), 10, &myProcessCB);
00070   ArRangeDevice::setRobot(robot);
00071 }
00072 
00076 void ArBumpers::processReadings(void)
00077 {
00078   int frontBump;
00079   int rearBump;
00080   int whichBumper;
00081 
00082   if (myRobot->hasFrontBumpers())
00083     frontBump = ((myRobot->getStallValue() & 0xff00) >> 8) & myBumpMask;
00084   else
00085     {
00086       frontBump = 0;
00087     }
00088   if (myRobot->hasRearBumpers())
00089     rearBump = (myRobot->getStallValue() & 0xff) & myBumpMask;
00090   else
00091     {
00092       rearBump = 0;
00093     }
00094 
00095   if(frontBump!= 0)
00096     {
00097       whichBumper = 1;
00098       addBumpToBuffer(frontBump, whichBumper);
00099     }
00100 
00101   if(rearBump != 0)
00102     {
00103       whichBumper = 2;
00104       addBumpToBuffer(rearBump, whichBumper);
00105     }
00106 
00107 }
00108 
00113 void ArBumpers::addBumpToBuffer(int bumpValue, int whichBumper)
00114 {
00115   int numBumpers;
00116   double x;
00117   double y;
00118   double degree;
00119   double radius;
00120 
00121   const ArRobotParams *params;
00122   params = myRobot->getRobotParams();
00123 
00124   radius = params->getRobotRadius();
00125 
00126   if(whichBumper == 1) numBumpers = myRobot->getNumFrontBumpers();
00127   else numBumpers = myRobot->getNumRearBumpers();
00128 
00129   for (int i = 0; i < numBumpers; i++)
00130     {
00131       if((i == 0 && (bumpValue & ArUtil::BIT1)) || 
00132          (i == 1 && (bumpValue & ArUtil::BIT2)) ||
00133          (i == 2 && (bumpValue & ArUtil::BIT3)) || 
00134          (i == 3 && (bumpValue & ArUtil::BIT4)) ||
00135          (i == 4 && (bumpValue & ArUtil::BIT5)) || 
00136          (i == 5 && (bumpValue & ArUtil::BIT6)) ||
00137          (i == 6 && (bumpValue & ArUtil::BIT7)) || 
00138          (i == 7 && (bumpValue & ArUtil::BIT8)))
00139         {
00140           degree = -1 * (i * (myAngleRange / (double)numBumpers) + 
00141                     ((myAngleRange / (double)numBumpers) / 2) - (myAngleRange / 2));
00142 
00143           if(whichBumper == 2) degree = degree + 180;
00144 
00145           x = radius * ArMath::cos(degree);
00146           y = radius * ArMath::sin(degree);
00147 
00148           ArPose pose;
00149           pose.setX(x);
00150           pose.setY(y);
00151 
00152           ArTransform global = myRobot->getToGlobalTransform();
00153           pose = global.doTransform(pose);
00154 
00155           myCurrentBuffer.addReading(pose.getX(), pose.getY());
00156         }
00157     } 
00158 }

Generated on Wed Oct 19 12:56:34 2005 for Aria by  doxygen 1.4.0