ModelEntry.cpp
Go to the documentation of this file.
00001 #include <blort/Tracker/ModelEntry.h>
00002 #include <ros/console.h>
00003 
00004 
00005 using namespace Tracking;
00006 
00008 ModelEntry::ModelEntry()
00009 : m_lpf_a(0.7f), m_lpf_t(0.7f), m_lpf_cs(0.2f), m_lpf_cl(0.99f)
00010 {  
00011         del_predictor = predictor = new Predictor();
00012         bfc = false;
00013         lock = false;
00014         mask_geometry_edges = false;
00015         num_convergence = 0;
00016   st_quality = ST_OK; //2012-11-28: added by Jordi
00017         mask = 0;
00018   ROS_WARN_STREAM("ModelEntry(): st_quality = " << st_quality );
00019 }
00020 
00021 ModelEntry::ModelEntry(const TomGine::tgModel& m)
00022 : model(m), m_lpf_a(0.7f), m_lpf_t(0.7f), m_lpf_cs(0.2f), m_lpf_cl(0.99f)
00023 {
00024         del_predictor = predictor = new Predictor();
00025         bfc = false;
00026         lock = false;
00027         mask_geometry_edges = false;
00028         num_convergence = 0;
00029         mask = 0;
00030 }
00031         
00032 ModelEntry::~ModelEntry()
00033 {
00034         delete(del_predictor);
00035 }
00036 
00037 void ModelEntry::poseDiff(float &t, float &a)
00038 {
00039         vec3 axis0, axis1;
00040         float angle0, angle1;
00041         
00042         pose.q.getAxisAngle(axis0, angle0);
00043         pose_prev.q.getAxisAngle(axis1, angle1);
00044         
00045         vec3 axis01 = axis0 - axis1;
00046         vec3 t01 = pose.t - pose_prev.t;
00047         
00048         a = (angle0-angle1);
00049         t = t01.length();
00050 }
00051 
00052 void ModelEntry::speed()
00053 {
00054         static Timer s_timer;
00055         float dt = (float)s_timer.Update();
00056         
00057         float t,a;
00058         poseDiff(t,a);
00059         
00060         speed_angular = a/dt;
00061         speed_translational = t/dt;
00062 }
00063 
00064 void ModelEntry::filter_pose()
00065 {
00066         lpf_pose.t.x = m_lpf_pose_tx.Process(pose.t.x);
00067         lpf_pose.t.y = m_lpf_pose_ty.Process(pose.t.y);
00068         lpf_pose.t.z = m_lpf_pose_tz.Process(pose.t.z);
00069         lpf_pose.q.x = m_lpf_pose_qx.Process(pose.q.x);
00070         lpf_pose.q.y = m_lpf_pose_qy.Process(pose.q.y);
00071         lpf_pose.q.z = m_lpf_pose_qz.Process(pose.q.z);
00072         lpf_pose.q.w = m_lpf_pose_qw.Process(pose.q.w);
00073 }
00074 
00075 void ModelEntry::setInitialPose(const TomGine::tgPose &p, float lpf_delay, float lpf_delay_z)
00076 {
00077         initial_pose = p;
00078         initial_pose.c = pose.c;
00079         initial_pose.w = pose.w;
00080         m_lpf_pose_tx.Set(p.t.x, lpf_delay);
00081         m_lpf_pose_ty.Set(p.t.y, lpf_delay);
00082         m_lpf_pose_tz.Set(p.t.z, lpf_delay_z);
00083         m_lpf_pose_qx.Set(p.q.x, lpf_delay);
00084         m_lpf_pose_qy.Set(p.q.y, lpf_delay);
00085         m_lpf_pose_qz.Set(p.q.z, lpf_delay);
00086         m_lpf_pose_qw.Set(p.q.w, lpf_delay);
00087 }
00088 
00089 void ModelEntry::evaluate_states(const Particle &variation, unsigned rec,
00090                                  float c_th_base, float c_th_min, float c_th_fair,
00091                                  float c_mv_not, float c_mv_slow, float c_th_lost)
00092 {
00093         
00094   if(lock)
00095   {    
00096                 st_quality = ST_LOCKED;
00097                 return;
00098         }
00099         
00100         speed();
00101         
00102         poseDiff(t,a);
00103         
00104         t_max = max(variation.t.x, max(variation.t.y, variation.t.z));
00105         a_max = max(variation.r.x, max(variation.r.y, variation.r.z));
00106         
00107         t = t/(t_max * rec);
00108         a = a/(a_max * rec);
00109 
00110         t = m_lpf_t.Process(t);
00111         a = m_lpf_a.Process(a);
00112         
00113   c_edge = m_lpf_cs.Process(this->confidence_edge);  
00114 
00115         abs_a = abs(a);
00116         abs_t = abs(t);
00117         
00118         c_th = c_th_base -  max(abs_a, abs_t);
00119         if(c_th < c_th_min) c_th = c_th_min;
00120         
00121         if(c_edge < c_th)
00122                 c_lost = m_lpf_cl.Process(c_th - c_edge);
00123         else
00124                 c_lost = m_lpf_cl.Process(0.0f);  
00125 
00126         // Movement detection
00127         if( abs_a<c_mv_not && abs_t < c_mv_not )
00128                 st_movement = ST_STILL;
00129         else if( abs_a<c_mv_slow && abs_t < c_mv_slow )
00130                 st_movement = ST_SLOW;
00131         else
00132                 st_movement = ST_FAST;
00133 
00134   ROS_INFO_STREAM("ModeEntry: evaluate_states: c_edge = " << c_edge << "  c_lost = " << c_lost << "  c_th_lost = " << c_th_lost);
00135   ROS_INFO_STREAM("                            st_movement = " << st_movement << "  st_quality = " << st_quality);
00136         
00138   if( c_lost > c_th_lost )
00139   {
00140                 if( st_movement != ST_STILL && st_quality != ST_OCCLUDED)
00141     {
00142                         st_quality = ST_LOST;
00143     }
00144     else if( st_quality != ST_LOST)
00145     {
00146       st_quality = ST_OCCLUDED;
00147     }
00148   }
00149   else if( st_quality != ST_LOST && st_quality != ST_OCCLUDED )
00150   {
00151                 st_quality = ST_OK;
00152         }
00153 
00154         if( st_quality == ST_OCCLUDED && st_movement == ST_FAST )
00155   {
00156                 st_quality = ST_LOST;
00157   }   
00158         
00159         // Quality detection
00160         if( c_edge > c_th_base )
00161                 st_confidence = ST_GOOD;
00162         else if( c_edge > c_th_fair )
00163                 st_confidence = ST_FAIR;
00164         else
00165                 st_confidence = ST_BAD;
00166                 
00167   if( st_movement == ST_STILL && c_edge >= c_th_base )
00168   {
00169                 st_quality = ST_OK;
00170         }
00171 
00172   ROS_INFO_STREAM("ModelEntry::evaluate_states has set st_confidence = " << st_confidence << "  st_quality = " << st_quality);
00173         
00174 }


blort
Author(s): Michael Zillich, Thomas Mörwald, Johann Prankl, Andreas Richtsfeld, Bence Magyar (ROS version)
autogenerated on Thu Jan 2 2014 11:38:25