Jafar
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
trackersimu.hpp
00001 
00002 #ifndef DDF_TRACKERSIMU_HPP
00003 #define DDF_TRACKERSIMU_HPP
00004 
00005 #include "sensorsimu.hpp"
00006 #include "ddf/tools.hpp"
00007 
00008 namespace jafar
00009 {
00010   namespace ddfsimu
00011   {
00012 
00016     template<typename T_OBS>
00017     class TrackerSimu : public SensorSimu<T_OBS>
00018     {
00019       // Perceive will use the true current state proc_state (containing the position of the robot)
00020       // and the list of observable targets to produce a measurement DX, DY DZ with noise
00021       typedef std::vector<VEC>         TargetsArray;
00022       typedef std::vector<RobotSimu *> TargetsRobotsArray;
00023 
00024       TargetsArray         m_targets;
00025       TargetsRobotsArray   m_tracked_robots;
00026       unsigned short       m_num_targets;
00027       unsigned short       m_rob_id;
00028       bool                 m_use_only_vel;
00029       unsigned short       m_num_rob_to_track;
00030 
00031     protected:
00032       using T_OBS::Hx;
00033       using SensorSimu<T_OBS>::GetProcTime;
00034       using SensorSimu<T_OBS>::GetMeasureSize;
00035       using SensorSimu<T_OBS>::GetID;
00036       using SensorSimu<T_OBS>::GetName;
00037    
00038     public:
00039       TrackerSimu(unsigned short x_size, unsigned short rob_id, unsigned short num_targets, bool use_only_vel, unsigned short num_rob_to_track):
00040         SensorSimu<T_OBS>(x_size,
00041                           (num_targets+num_rob_to_track) * 3),
00042                           m_num_targets(num_targets),
00043                           m_rob_id(rob_id),
00044                           m_use_only_vel(use_only_vel),
00045                           m_num_rob_to_track(num_rob_to_track)
00046       {
00047         unsigned short num_robots = (x_size - num_targets * 3)/6;
00048         int i,j;
00049         this->m_type_name = SENSOR_TRACK;
00050   
00051         Hx.clear();
00052   
00053         for(i = 0; i < num_targets; i++) {
00054           for(j = 0; j < 3; j++) {
00055             Hx(3*i+j,6*m_rob_id+2*j)     = -1.;
00056             Hx(3*i+j,6*num_robots+3*i+j) = 1.;
00057           }
00058         }
00059       }
00060 
00061       void AddTarget(VEC const& target) { JFR_PRECOND(m_targets.size() < m_num_targets, "too many targets"); m_targets.push_back(target); }
00062       unsigned short GetNumTargets() { return m_num_targets; }
00063 
00064       void AddRobotToTracker(RobotSimu *other_robot) {
00065         int i,j;
00066   
00067         JFR_PRECOND(other_robot->GetRobID() != m_rob_id, "wrong robot");
00068         std::cout << m_num_rob_to_track << " " << m_tracked_robots.size();
00069           
00070         m_tracked_robots.push_back(other_robot);
00071 
00072         JFR_PRECOND(m_num_rob_to_track <= m_tracked_robots.size(), "bad sizes");
00073           
00074         for(i = 0,j = 3*m_num_targets; i < 6; i = i+2,j++) {
00075           Hx(j,6*m_rob_id+i) = -1.0;
00076           Hx(j,6*other_robot->GetRobID()+i) = 1.0;
00077         }
00078       }
00079 
00080       // proc_state is the true state [x vx ax y vy ay z vz az]
00081       void Perceive(VEC const& proc_state, time t)
00082       {
00083         int  i,j,k=0;
00084         VEC  true_pos(3),other_rob_pos(3);
00085         VEC  measured_pos(GetMeasureSize());
00086         if(m_use_only_vel){
00087           for(i = 0, j = 0; i < 3; i++, j = j+2) true_pos[i] = proc_state[j];
00088         }
00089         else {
00090           true_pos[0] = proc_state[AccelMotion::SV_X];
00091           true_pos[1] = proc_state[AccelMotion::SV_Y];
00092           true_pos[2] = proc_state[AccelMotion::SV_Z];
00093         }
00094          
00095         for(i = 0; i < m_num_targets; i++)
00096           {
00097             for(j = 0; j < 3; j++) measured_pos[k++] = m_targets[i][j] - true_pos[j];
00098           }
00099 
00100         if (!m_tracked_robots.empty())
00101           {
00102             for(i = 0; i < m_num_rob_to_track; i++)
00103             {
00104               other_rob_pos = m_tracked_robots[i]->ComputePositionAtTimeT(t.to_double());
00105               for(j = 0; j < 3; j++) measured_pos[k++] = other_rob_pos[j] - true_pos[j];
00106              }
00107 
00108           }
00109         // Add a noise wich is proportional to the dist^2 !
00110         AddMeasurementWithNoise(t, t+GetProcTime(), measured_pos);
00111       }
00112       void PerceiveRet(VEC const& proc_state, VEC & result) const {   }
00113       void PrintObservationModel(){
00114         JFR_DEBUG("Observation model of sensor " << GetID() << " (" << GetName() << ")\n");
00115         PrettyPrintMatrix(Hx, "Hx");
00116       }
00117       void PrintTargets()
00118       {
00119         std::ostringstream stream;
00120         
00121         stream << "\nNum targets: " << GetNumTargets() << "\n";
00122         
00123         for(int i = 0; i < m_num_targets; i++)
00124           stream << "Target " << i << " " << m_targets[i] << "\n";
00125         
00126         JFR_DEBUG(stream.str());
00127       }
00128     };
00129 
00130     class TrackerSimuUncorr : public TrackerSimu<Bayesian_filter::Linear_uncorrelated_observe_model>
00131     {
00132     public:
00133       TrackerSimuUncorr(unsigned short x_size, unsigned short rob_id, unsigned short num_targets, \
00134                         bool use_only_vel, unsigned short num_rob_to_track) :
00135         TrackerSimu<Bayesian_filter::Linear_uncorrelated_observe_model>(x_size, rob_id, num_targets, use_only_vel, num_rob_to_track){}
00136    
00137       virtual ~TrackerSimuUncorr() {}
00138 
00139       void ComputeInformation(VEC const& z, VEC &i, MSYM &I) { compute_information_uncorr(*this, z, i, I); }
00140       void SetSensorModelVar(VEC const& var) { Zv = var; }
00141       void PrintObservationModel()
00142       {
00143         TrackerSimu<Bayesian_filter::Linear_uncorrelated_observe_model>::PrintObservationModel();
00144         PrettyPrintVector(Zv, "Zv");
00145       }
00146     };
00147 
00148   } // namespace ddfsimu
00149 } // namespace jafar
00150 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Wed Oct 15 2014 00:37:18 for Jafar by doxygen 1.7.6.1
LAAS-CNRS