$search
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 mask = 0; 00017 } 00018 00019 ModelEntry::ModelEntry(const TomGine::tgModel& m) 00020 : model(m), m_lpf_a(0.7f), m_lpf_t(0.7f), m_lpf_cs(0.2f), m_lpf_cl(0.99f) 00021 { 00022 del_predictor = predictor = new Predictor(); 00023 bfc = false; 00024 lock = false; 00025 mask_geometry_edges = false; 00026 num_convergence = 0; 00027 mask = 0; 00028 } 00029 00030 ModelEntry::~ModelEntry() 00031 { 00032 delete(del_predictor); 00033 } 00034 00035 void ModelEntry::poseDiff(float &t, float &a) 00036 { 00037 vec3 axis0, axis1; 00038 float angle0, angle1; 00039 00040 pose.q.getAxisAngle(axis0, angle0); 00041 pose_prev.q.getAxisAngle(axis1, angle1); 00042 00043 vec3 axis01 = axis0 - axis1; 00044 vec3 t01 = pose.t - pose_prev.t; 00045 00046 a = (angle0-angle1); 00047 t = t01.length(); 00048 } 00049 00050 void ModelEntry::speed() 00051 { 00052 static Timer s_timer; 00053 float dt = (float)s_timer.Update(); 00054 00055 float t,a; 00056 poseDiff(t,a); 00057 00058 speed_angular = a/dt; 00059 speed_translational = t/dt; 00060 } 00061 00062 void ModelEntry::filter_pose() 00063 { 00064 lpf_pose.t.x = m_lpf_pose_tx.Process(pose.t.x); 00065 lpf_pose.t.y = m_lpf_pose_ty.Process(pose.t.y); 00066 lpf_pose.t.z = m_lpf_pose_tz.Process(pose.t.z); 00067 lpf_pose.q.x = m_lpf_pose_qx.Process(pose.q.x); 00068 lpf_pose.q.y = m_lpf_pose_qy.Process(pose.q.y); 00069 lpf_pose.q.z = m_lpf_pose_qz.Process(pose.q.z); 00070 lpf_pose.q.w = m_lpf_pose_qw.Process(pose.q.w); 00071 } 00072 00073 void ModelEntry::setInitialPose(const TomGine::tgPose &p, float lpf_delay, float lpf_delay_z) 00074 { 00075 initial_pose = p; 00076 initial_pose.c = pose.c; 00077 initial_pose.w = pose.w; 00078 m_lpf_pose_tx.Set(p.t.x, lpf_delay); 00079 m_lpf_pose_ty.Set(p.t.y, lpf_delay); 00080 m_lpf_pose_tz.Set(p.t.z, lpf_delay_z); 00081 m_lpf_pose_qx.Set(p.q.x, lpf_delay); 00082 m_lpf_pose_qy.Set(p.q.y, lpf_delay); 00083 m_lpf_pose_qz.Set(p.q.z, lpf_delay); 00084 m_lpf_pose_qw.Set(p.q.w, lpf_delay); 00085 } 00086 00087 void ModelEntry::evaluate_states(const Particle &variation, unsigned rec, 00088 float c_th_base, float c_th_min, float c_th_fair, 00089 float c_mv_not, float c_mv_slow, float c_th_lost) 00090 { 00091 00092 if(lock){ 00093 st_quality = ST_LOCKED; 00094 return; 00095 } 00096 00097 speed(); 00098 00099 poseDiff(t,a); 00100 00101 t_max = max(variation.t.x, max(variation.t.y, variation.t.z)); 00102 a_max = max(variation.r.x, max(variation.r.y, variation.r.z)); 00103 00104 t = t/(t_max * rec); 00105 a = a/(a_max * rec); 00106 00107 t = m_lpf_t.Process(t); 00108 a = m_lpf_a.Process(a); 00109 00110 c_edge = m_lpf_cs.Process(this->confidence_edge); 00111 //ROS_INFO("c_edge: %f, this->confidence_edge: %f", c_edge, this->confidence_edge); 00112 00113 abs_a = abs(a); 00114 abs_t = abs(t); 00115 00116 c_th = c_th_base - max(abs_a, abs_t); 00117 if(c_th < c_th_min) c_th = c_th_min; 00118 00119 if(c_edge < c_th) 00120 c_lost = m_lpf_cl.Process(c_th - c_edge); 00121 else 00122 c_lost = m_lpf_cl.Process(0.0f); 00123 00124 // Movement detection 00125 if( abs_a<c_mv_not && abs_t < c_mv_not ) 00126 st_movement = ST_STILL; 00127 else if( abs_a<c_mv_slow && abs_t < c_mv_slow ) 00128 st_movement = ST_SLOW; 00129 else 00130 st_movement = ST_FAST; 00131 00133 if( c_lost > c_th_lost ){ 00134 if( st_movement != ST_STILL && st_quality != ST_OCCLUDED) 00135 st_quality = ST_LOST; 00136 else if( st_quality != ST_LOST) 00137 st_quality = ST_OCCLUDED; 00138 }else if( st_quality != ST_LOST && st_quality != ST_OCCLUDED ){ 00139 st_quality = ST_OK; 00140 } 00141 if( st_quality == ST_OCCLUDED && st_movement == ST_FAST ) 00142 st_quality = ST_LOST; 00143 00144 // Quality detection 00145 if( c_edge > c_th_base ) 00146 st_confidence = ST_GOOD; 00147 else if( c_edge > c_th_fair ) 00148 st_confidence = ST_FAIR; 00149 else 00150 st_confidence = ST_BAD; 00151 00152 if( st_movement == ST_STILL && c_edge >= c_th_base ){ 00153 st_quality = ST_OK; 00154 } 00155 00156 }