00001 #include "informed_object_search/ObjectOnSurfaceModel.h" 00002 #include <ros/time.h> 00003 00004 using namespace std; 00005 using namespace rail::interactive_world; 00006 00007 ObjectOnSurfaceModel::ObjectOnSurfaceModel(const string &object, const string &surface) 00008 : object_(object), surface_(surface) 00009 { 00010 dirty_ = false; 00011 last_seen_ = 0; 00012 mu_ = 0; 00013 } 00014 00015 const string &ObjectOnSurfaceModel::getObject() const 00016 { 00017 return object_; 00018 } 00019 00020 void ObjectOnSurfaceModel::setObject(const std::string &object) 00021 { 00022 object_ = object; 00023 } 00024 00025 const string &ObjectOnSurfaceModel::getSurface() const 00026 { 00027 return surface_; 00028 } 00029 00030 void ObjectOnSurfaceModel::setSurface(const std::string &surface) 00031 { 00032 surface_ = surface; 00033 } 00034 00035 time_t ObjectOnSurfaceModel::getLastSeen() const 00036 { 00037 return last_seen_; 00038 } 00039 00040 void ObjectOnSurfaceModel::addObservation(const time_t seen, const time_t removed) 00041 { 00042 if (seen > last_seen_) 00043 { 00044 last_seen_ = seen; 00045 } 00046 struct observation cur; 00047 cur.seen = seen; 00048 cur.removed = removed; 00049 observations_.push_back(cur); 00050 dirty_ = true; 00051 } 00052 00053 double ObjectOnSurfaceModel::getMu() 00054 { 00055 if (dirty_) 00056 { 00057 // average 00058 mu_ = 0; 00059 ros::Time now = ros::Time::now(); 00060 for (size_t i = 0; i < observations_.size(); i++) 00061 { 00062 // check if the observation is still current 00063 double duration; 00064 if (observations_[i].removed == 0) 00065 { 00066 duration = now.toSec() - observations_[i].seen; 00067 } else 00068 { 00069 duration = observations_[i].removed - observations_[i].seen; 00070 } 00071 // put into minutes 00072 duration /= 60.0; 00073 mu_ += duration; 00074 } 00075 mu_ /= (double) observations_.size(); 00076 dirty_ = false; 00077 } 00078 00079 return mu_; 00080 } 00081 00082 double ObjectOnSurfaceModel::getLambda() 00083 { 00084 return 1.0 / this->getMu(); 00085 } 00086 00087 double ObjectOnSurfaceModel::getCurrentProbability() 00088 { 00089 ros::Time now = ros::Time::now(); 00090 // x in minutes 00091 double x = (now.toSec() - this->getLastSeen()) / 60.0; 00092 double lambda = this->getLambda(); 00093 return exp(-lambda * x); 00094 }