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

ArSensorReading.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 "ArSensorReading.h"
00029 #include "ariaUtil.h"
00030 
00036 ArSensorReading::ArSensorReading(double xPos, double yPos, double thPos)
00037 {
00038   myRange = 5000;
00039   myCounterTaken = 0;
00040   myReading.setPose(-1, -1);
00041   myReadingTaken.setPose(-1, -1, -1);
00042   resetSensorPosition(xPos, yPos, thPos, true);
00043   myExtraInt = 0;
00044   myAdjusted = false;
00045 }
00046 
00047 AREXPORT ArSensorReading::ArSensorReading(const ArSensorReading & reading)
00048 {
00049   myCounterTaken = reading.myCounterTaken;
00050   myReading = reading.myReading;
00051   myLocalReading = reading.myLocalReading;  
00052   myReadingTaken = reading.myReadingTaken;
00053   myEncoderPoseTaken = reading.myEncoderPoseTaken;
00054   mySensorPos = reading.mySensorPos;
00055   mySensorCos = reading.mySensorCos;
00056   mySensorSin = reading.mySensorSin;
00057   myDistToCenter = reading.myDistToCenter;
00058   myAngleToCenter = reading.myAngleToCenter;
00059   myRange = reading.myRange;
00060   myTimeTaken = reading.myTimeTaken;
00061   myIgnoreThisReading = reading.myIgnoreThisReading;
00062   myExtraInt = reading.myExtraInt;  
00063   myAdjusted = reading.myAdjusted;
00064 }
00065 
00066 AREXPORT ArSensorReading &ArSensorReading::operator=(
00067         const ArSensorReading &reading)
00068 {
00069   if (this != &reading)
00070   {
00071     myCounterTaken = reading.myCounterTaken;
00072     myReading = reading.myReading;
00073     myLocalReading = reading.myLocalReading;  
00074     myReadingTaken = reading.myReadingTaken;
00075     myEncoderPoseTaken = reading.myEncoderPoseTaken;
00076     mySensorPos = reading.mySensorPos;
00077     mySensorCos = reading.mySensorCos;
00078     mySensorSin = reading.mySensorSin;
00079     myDistToCenter = reading.myDistToCenter;
00080     myAngleToCenter = reading.myAngleToCenter;
00081     myRange = reading.myRange;
00082     myTimeTaken = reading.myTimeTaken;
00083     myIgnoreThisReading = reading.myIgnoreThisReading;
00084     myExtraInt = reading.myExtraInt;
00085     myAdjusted = reading.myAdjusted;
00086   }
00087   return *this;
00088 }
00089 
00090 
00091 
00092 ArSensorReading::~ArSensorReading()
00093 {
00094 }
00095 
00096 
00106 AREXPORT void ArSensorReading::newData(int range, ArPose robotPose,
00107                        ArPose encoderPose, ArTransform trans, 
00108                        unsigned int counter,
00109                        ArTime timeTaken,
00110                        bool ignoreThisReading, int extraInt)
00111 {
00112   // TODO calculate the x and y position of the sensor
00113   double rx, ry;
00114   myRange = range;
00115   myCounterTaken = counter;
00116   myReadingTaken = robotPose;
00117   myEncoderPoseTaken = encoderPose;
00118   rx = getSensorX() + myRange * mySensorCos;
00119   ry = getSensorY() + myRange * mySensorSin;
00120   myLocalReading.setPose(rx, ry);
00121   myReading = trans.doTransform(myLocalReading);
00122   myTimeTaken = timeTaken;
00123   myIgnoreThisReading = ignoreThisReading;
00124   myExtraInt = extraInt;
00125   myAdjusted = false;
00126 }
00127 
00138 AREXPORT void ArSensorReading::newData(int sx, int sy, ArPose robotPose,
00139                        ArPose encoderPose, ArTransform trans, 
00140                        unsigned int counter, ArTime timeTaken,
00141                        bool ignoreThisReading, int extraInt)
00142 {
00143   // TODO calculate the x and y position of the sensor
00144   double rx, ry;
00145   myRange = (int)sqrt((double)(sx*sx + sy*sy));
00146   myCounterTaken = counter;
00147   myReadingTaken = robotPose;
00148   myEncoderPoseTaken = encoderPose;
00149   rx = getSensorX() + sx;
00150   ry = getSensorY() + sy;
00151   myLocalReading.setPose(rx, ry);
00152   myReading = trans.doTransform(myLocalReading);
00153   myTimeTaken = timeTaken;
00154   myIgnoreThisReading = ignoreThisReading;
00155   myExtraInt = extraInt;
00156   myAdjusted = false;
00157 }
00158 
00159 
00165 AREXPORT void ArSensorReading::resetSensorPosition(double xPos, double yPos, 
00166                            double thPos, 
00167                            bool forceComputation)
00168 {
00169   // if its the same position and we're not forcing, just bail
00170   if (!forceComputation && fabs(thPos - mySensorPos.getTh()) < .00001 &&
00171       xPos == mySensorPos.getX() && yPos == mySensorPos.getY())
00172     return;
00173       
00174   mySensorPos.setPose(xPos, yPos, thPos);
00175   myDistToCenter = sqrt(xPos * xPos + yPos * yPos);
00176   myAngleToCenter = ArMath::atan2(yPos, xPos);
00177   mySensorCos = ArMath::cos(thPos);
00178   mySensorSin = ArMath::sin(thPos);
00179   //printf("xpose %d ypose %d thpose %d disttoC %.1f angletoC %.1f\n",
00180   //xPos, yPos, thPos, myDistToCenter, myAngleToCenter);
00181 }
00182 
00186 AREXPORT void ArSensorReading::applyTransform(ArTransform trans)
00187 {
00188   myReading = trans.doTransform(myReading);
00189   myReadingTaken = trans.doTransform(myReadingTaken);
00190 }
00191 
00195 AREXPORT void ArSensorReading::applyEncoderTransform(ArTransform trans)
00196 {
00197   myEncoderPoseTaken = trans.doTransform(myEncoderPoseTaken);
00198 }

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