SensorResult.C
Go to the documentation of this file.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
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "SensorResult.H"
00038
00039
00040
00041 SensorResult::SensorResult()
00042 {
00043 sensorResultMutex = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
00044 pthread_mutex_init(sensorResultMutex,NULL);
00045
00046 itsStatus = NOT_FOUND;
00047 itsPosition = Point3D(-1,-1,-1);
00048 itsOrientation = -1.0;
00049 itsFrequency = -1.0;
00050 itsDistance = -1.0;
00051 itsMass = -1.0;
00052 itsFrameNumber = 0;
00053 itsTimer.reset(new Timer(1000000));
00054 }
00055
00056
00057 SensorResult::SensorResult(SensorResultType type)
00058 {
00059
00060 sensorResultMutex = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
00061 pthread_mutex_init(sensorResultMutex,NULL);
00062
00063 itsType = type;
00064 itsStatus = NOT_FOUND;
00065 itsPosition = Point3D(-1,-1,-1);
00066 itsOrientation = -1.0;
00067 itsFrequency = -1.0;
00068 itsDistance = -1.0;
00069 itsMass = -1.0;
00070 itsFrameNumber = 0;
00071 itsTimer.reset(new Timer(1000000));
00072 }
00073
00074
00075
00076 void SensorResult::copySensorResult(SensorResult sr)
00077 {
00078 pthread_mutex_lock(sensorResultMutex);
00079 itsPosition = sr.getPosition();
00080 itsOrientation = sr.getOrientation();
00081 itsFrequency = sr.getFrequency();
00082 itsDistance = sr.getDistance();
00083 itsMass = sr.getMass();
00084 itsType = sr.getType();
00085 itsStatus = sr.getStatus();
00086 itsTimer->reset();
00087 pthread_mutex_unlock(sensorResultMutex);
00088 }
00089
00090
00091
00092 void SensorResult::startTimer()
00093 {
00094 itsTimer.reset(new Timer(1000000));
00095 }
00096
00097
00098
00099 void SensorResult::setStatus(SensorResultStatus s)
00100 {
00101 pthread_mutex_lock(sensorResultMutex);
00102 itsStatus = s;
00103 pthread_mutex_unlock(sensorResultMutex);
00104 }
00105
00106
00107 void SensorResult::setType(SensorResultType t)
00108 {
00109 pthread_mutex_lock(sensorResultMutex);
00110 itsType = t;
00111 pthread_mutex_unlock(sensorResultMutex);
00112 }
00113
00114
00115 void SensorResult::setPosition(Point3D pos)
00116 {
00117 pthread_mutex_lock(sensorResultMutex);
00118 itsPosition = pos;
00119 itsTimer->reset();
00120 pthread_mutex_unlock(sensorResultMutex);
00121 }
00122
00123
00124 void SensorResult::setOrientation(Angle ori)
00125 {
00126 pthread_mutex_lock(sensorResultMutex);
00127 itsOrientation = ori;
00128 itsTimer->reset();
00129 pthread_mutex_unlock(sensorResultMutex);
00130 }
00131
00132
00133 void SensorResult::setFrequency(float freq)
00134 {
00135 pthread_mutex_lock(sensorResultMutex);
00136 itsFrequency = freq;
00137 itsTimer->reset();
00138 pthread_mutex_unlock(sensorResultMutex);
00139 }
00140
00141
00142 void SensorResult::setDistance(float dist)
00143 {
00144 pthread_mutex_lock(sensorResultMutex);
00145 itsDistance = dist;
00146 itsTimer->reset();
00147 pthread_mutex_unlock(sensorResultMutex);
00148 }
00149
00150
00151 void SensorResult::setMass(float mass)
00152 {
00153 pthread_mutex_lock(sensorResultMutex);
00154 itsMass = mass;
00155 itsTimer->reset();
00156 pthread_mutex_unlock(sensorResultMutex);
00157 }
00158
00159
00160 void SensorResult::setId(uint id)
00161 {
00162 pthread_mutex_lock(sensorResultMutex);
00163 itsId = id;
00164 itsTimer->reset();
00165 pthread_mutex_unlock(sensorResultMutex);
00166 }
00167
00168
00169 void SensorResult::setFrameNum(uint fnum)
00170 {
00171 pthread_mutex_lock(sensorResultMutex);
00172 itsFrameNumber = fnum;
00173 itsTimer->reset();
00174 pthread_mutex_unlock(sensorResultMutex);
00175 }
00176
00177
00178 Point3D SensorResult::getPosition()
00179 {
00180 pthread_mutex_lock(sensorResultMutex);
00181 Point3D p = itsPosition;
00182 pthread_mutex_unlock(sensorResultMutex);
00183 return p;
00184 }
00185
00186
00187 rutz::shared_ptr<Point3D> SensorResult::getPositionPtr()
00188 {
00189 pthread_mutex_lock(sensorResultMutex);
00190 rutz::shared_ptr<Point3D> p (new Point3D(itsPosition));
00191 pthread_mutex_unlock(sensorResultMutex);
00192 return p;
00193 }
00194
00195
00196 Angle SensorResult::getOrientation()
00197 {
00198 pthread_mutex_lock(sensorResultMutex);
00199 Angle o = itsOrientation;
00200 pthread_mutex_unlock(sensorResultMutex);
00201 return o;
00202 }
00203
00204
00205 rutz::shared_ptr<Angle> SensorResult::getOrientationPtr()
00206 {
00207 pthread_mutex_lock(sensorResultMutex);
00208 rutz::shared_ptr<Angle> o (new Angle(itsOrientation));
00209 pthread_mutex_unlock(sensorResultMutex);
00210 return o;
00211 }
00212
00213
00214
00215 float SensorResult::getFrequency()
00216 {
00217 pthread_mutex_lock(sensorResultMutex);
00218 float f = itsFrequency;
00219 pthread_mutex_unlock(sensorResultMutex);
00220 return f;
00221 }
00222
00223
00224 float SensorResult::getDistance()
00225 {
00226 pthread_mutex_lock(sensorResultMutex);
00227 float d = itsDistance;
00228 pthread_mutex_unlock(sensorResultMutex);
00229 return d;
00230 }
00231
00232
00233 float SensorResult::getMass()
00234 {
00235 pthread_mutex_lock(sensorResultMutex);
00236 float m = itsMass;
00237 pthread_mutex_unlock(sensorResultMutex);
00238 return m;
00239 }
00240
00241
00242 uint SensorResult::getId()
00243 {
00244 pthread_mutex_lock(sensorResultMutex);
00245 uint id = itsId;
00246 pthread_mutex_unlock(sensorResultMutex);
00247 return id;
00248 }
00249
00250
00251 uint SensorResult::getFrameNum()
00252 {
00253 pthread_mutex_lock(sensorResultMutex);
00254 uint fnum = itsFrameNumber;
00255 pthread_mutex_unlock(sensorResultMutex);
00256 return fnum;
00257 }
00258
00259
00260 SensorResult::SensorResultStatus SensorResult::getStatus()
00261 {
00262 pthread_mutex_lock(sensorResultMutex);
00263 SensorResultStatus currentStatus = itsStatus;
00264 int lastUpdate = itsTimer->get();
00265
00266 if(lastUpdate > NOT_FOUND_TIME)
00267 {
00268 if(currentStatus == SensorResult::FOUND)
00269 currentStatus = SensorResult::LOST;
00270 else
00271 currentStatus = SensorResult::NOT_FOUND;
00272 }
00273
00274 pthread_mutex_unlock(sensorResultMutex);
00275 return currentStatus;
00276 }
00277
00278
00279 SensorResult::SensorResultType SensorResult::getType()
00280 {
00281 pthread_mutex_lock(sensorResultMutex);
00282
00283
00284 SensorResultType currentType = itsType;
00285 pthread_mutex_unlock(sensorResultMutex);
00286 return currentType;
00287 }
00288
00289
00290 bool SensorResult::downwardCoordsOk()
00291 {
00292 pthread_mutex_lock(sensorResultMutex);
00293 bool isValid = (itsPosition.isValidZ() &&
00294 itsPosition.isValidX());
00295 pthread_mutex_unlock(sensorResultMutex);
00296
00297 return isValid;
00298 }
00299
00300
00301 bool SensorResult::forwardCoordsOk()
00302 {
00303 pthread_mutex_lock(sensorResultMutex);
00304 bool isValid = (itsPosition.isValidY() &&
00305 itsPosition.isValidX());
00306 pthread_mutex_unlock(sensorResultMutex);
00307
00308 return isValid;
00309 }
00310
00311
00312
00313
00314
00315
00316