00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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,
00046 80),
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