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

ArIRs.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 "ArRobot.h"
00029 #include "ariaUtil.h"
00030 #include "ArIRs.h"
00031 
00039 AREXPORT ArIRs::ArIRs(size_t currentBufferSize, size_t cumulativeBufferSize, 
00040               const char *name, int maxSecondsToKeepCurrent) :
00041   ArRangeDevice(currentBufferSize, cumulativeBufferSize, name, 5000, maxSecondsToKeepCurrent), 
00042   myProcessCB(this, &ArIRs::processReadings)
00043 {
00044   setCurrentDrawingData(new ArDrawingData("polyArrows", ArColor(255, 255, 0),
00045                       120, // mm diameter of dots
00046                       80), // layer above sick and sonar below bumpers
00047             true);
00048 }
00049 
00050 AREXPORT ArIRs::~ArIRs()
00051 {
00052   if (myRobot != NULL)
00053     {
00054       myRobot->remSensorInterpTask(&myProcessCB);
00055       myRobot->remRangeDevice(this);
00056     }
00057 }
00058 
00059 AREXPORT void ArIRs::setRobot(ArRobot *robot)
00060 {
00061   myRobot = robot;
00062   if (myRobot != NULL)
00063     myRobot->addSensorInterpTask(myName.c_str(), 10, &myProcessCB);
00064   ArRangeDevice::setRobot(robot);
00065 
00066   const ArRobotParams *params;
00067   params = myRobot->getRobotParams();
00068   myParams = *params;
00069 
00070   for(int i = 0; i < myParams.getNumIR(); i++)
00071     cycleCounters.push_back(1);
00072 }
00073 
00077 AREXPORT void ArIRs::processReadings(void)
00078 {
00079   ArUtil::BITS bit;
00080   if(myParams.haveTableSensingIR())
00081     {
00082       for (int i = 0; i < myParams.getNumIR(); ++i)
00083     {
00084       switch(i)
00085         {
00086         case 0:
00087           bit = ArUtil::BIT0;
00088           break;
00089         case 1:
00090           bit = ArUtil::BIT1;
00091           break;
00092         case 2:
00093           bit = ArUtil::BIT2;
00094           break;
00095         case 3:
00096           bit = ArUtil::BIT3;
00097           break;
00098         case 4:
00099           bit = ArUtil::BIT4;
00100           break;
00101         case 5:
00102           bit = ArUtil::BIT5;
00103           break;
00104         case 6:
00105           bit = ArUtil::BIT6;
00106           break;
00107         case 7:
00108           bit = ArUtil::BIT7;
00109           break;
00110         }
00111 
00112       if(myParams.haveNewTableSensingIR() && myRobot->getIODigInSize() > 3)
00113         {
00114           if((myParams.getIRType(i) && !(myRobot->getIODigIn(3) & bit)) ||
00115           (!myParams.getIRType(i) && (myRobot->getIODigIn(3) & bit)))
00116         {
00117           if(cycleCounters[i] < myParams.getIRCycles(i))
00118             {
00119               cycleCounters[i] = cycleCounters[i] + 1;            
00120             }
00121           else
00122             {
00123               cycleCounters[i] = 1;
00124               ArPose pose;
00125               pose.setX(myParams.getIRX(i));
00126               pose.setY(myParams.getIRY(i));
00127               
00128               ArTransform global = myRobot->getToGlobalTransform();
00129               pose = global.doTransform(pose);
00130               
00131               myCurrentBuffer.addReading(pose.getX(), pose.getY());
00132             }
00133         }
00134           else
00135         {
00136           cycleCounters[i] = 1;
00137         }
00138         }
00139       else
00140         {
00141           if(!(myRobot->getDigIn() & bit))
00142         {
00143           if(cycleCounters[i] < myParams.getIRCycles(i))
00144             {
00145               cycleCounters[i] = cycleCounters[i] + 1;            
00146             }
00147           else
00148             {
00149               cycleCounters[i] = 1;
00150               
00151               ArPose pose;
00152               pose.setX(myParams.getIRX(i));
00153               pose.setY(myParams.getIRY(i));
00154               
00155               ArTransform global = myRobot->getToGlobalTransform();
00156               pose = global.doTransform(pose);
00157               
00158               myCurrentBuffer.addReading(pose.getX(), pose.getY());
00159             }
00160         }
00161           else
00162         {
00163           cycleCounters[i] = 1;
00164         }
00165         }
00166     }
00167     }
00168 }
00169 

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