Jafar
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
sensorAbstract.hpp
Go to the documentation of this file.
00001 
00012 #ifndef SENSORABSTRACT_H_
00013 #define SENSORABSTRACT_H_
00014 
00015 /* --------------------------------------------------------------------- */
00016 /* --- INCLUDE --------------------------------------------------------- */
00017 /* --------------------------------------------------------------------- */
00018 
00019 #include <boost/assign.hpp>
00020 #include <boost/smart_ptr.hpp>
00021 
00022 #include "kernel/IdFactory.hpp"
00023 #include "jmath/jblas.hpp"
00024 #include "rtslam/rtSlam.hpp"
00025 //include parents
00026 #include "rtslam/parents.hpp"
00027 #include "rtslam/mapAbstract.hpp"
00028 #include "rtslam/mapObject.hpp"
00029 #include "rtslam/robotAbstract.hpp"
00030 #include "rtslam/hardwareSensorAbstract.hpp"
00031 
00032 namespace jafar {
00033   namespace rtslam {
00034 
00035     // Forward declarations of children
00036     class ObservationAbstract;
00037     class DataManagerAbstract;
00038 
00043     class SensorAbstract: public MapObject,
00044                           public ChildOf<RobotAbstract>,
00045                           public boost::enable_shared_from_this<SensorAbstract>,
00046                           public kernel::DataLoggable
00047     {
00048       private:
00049         // define the function linkToParentRobot().
00050         ENABLE_LINK_TO_PARENT(RobotAbstract,Robot,SensorAbstract);
00051         // define the functions robotPtr() and robot().
00052         ENABLE_ACCESS_TO_PARENT(RobotAbstract,robot);
00053     
00054       protected:
00055         bool integrate_all;
00056         bool use_for_init; 
00057         bool need_init; 
00058         bool enabled; 
00059         
00060         RobotQuantity quantsJacob; 
00061         RobotQuantity quantsState; 
00062 
00063         static IdFactory sensorIds;
00064 
00065       public:
00066         
00073         SensorAbstract(const robot_ptr_t & _robPtr, const filtered_obj_t poseInFilter = UNFILTERED, int extraStateFilterSize = 0,
00074           std::vector<RobotAbstract::Quantity> robQuant = createQuantPosOriQuat());
00075 
00079         virtual ~SensorAbstract() {
00080         }
00081 
00082         void setIntegrationPolicy(bool integrate_all) { this->integrate_all = integrate_all; }
00083         bool getIntegrationPolicy() { return integrate_all; }
00084         void setUseForInit(bool use_for_init) { this->use_for_init = use_for_init; }
00085         bool getUseForInit() { return use_for_init; }
00086         void setNeedInit(bool need_init) { this->need_init = need_init; }
00087         bool getNeedInit() { return need_init; }
00088 
00094         virtual void move()
00095         {
00096           if (poseInFilter)
00097           {
00098             jblas::mat QN_q(4,4), XNEW_x(7,7); XNEW_x.clear();
00099             jblas::sym_mat Q(7,7); Q.clear();
00100 
00101             jblas::vec q = ublas::subrange(pose.x(), 3,7);
00102             ublasExtra::normalizeJac(q, QN_q);
00103             ublasExtra::normalize(q);
00104             ublas::subrange(pose.x(), 3,7) = q;
00105 
00106             ublas::subrange(XNEW_x, 0,3, 0,3) = jblas::identity_mat(3);
00107             ublas::subrange(XNEW_x, 3,7, 3,7) = QN_q;
00108             robotPtr()->mapPtr()->filterPtr->predict(robotPtr()->mapPtr()->ia_used_states(), XNEW_x, pose.ia(), Q); // P = F*P*F' + Q
00109           }
00110         }
00111 
00112         virtual int queryAvailableRaws(RawInfos &infos) = 0; 
00113         virtual int queryNextAvailableRaw(RawInfo &info) = 0; 
00114         virtual double getRawTimestamp(unsigned id) = 0;
00115         virtual void process(unsigned id, double date_limit = -1.) = 0; 
00116         virtual void process_fake(unsigned id, bool move) = 0; 
00117         virtual void discard(unsigned id) = 0; 
00118         virtual void init(double date) { use_for_init = false; } 
00119         virtual void start() = 0;
00120         virtual void stop() = 0;
00121         virtual bool join(int timed_ms = -1) = 0;
00122         void enable(bool enabled = true) { this->enabled = enabled; if (!enabled) enableHard(false); }
00123         bool isEnabled() { return enabled; }
00124         virtual void enableHard(bool enabled = true) = 0;
00125         virtual void stopDumping() = 0;
00126         virtual void showInfos() = 0;
00127 
00128         // to replace (because does not work with gcc 4.4) boost::assign::list_of(RobotAbstract::qPos)(RobotAbstract::qOriQuat)
00129         static std::vector<RobotAbstract::Quantity> createQuantPosOriQuat()
00130         {
00131           std::vector<RobotAbstract::Quantity> quant;
00132           quant.push_back(RobotAbstract::qPos);
00133           quant.push_back(RobotAbstract::qOriQuat);
00134           return quant;
00135         }
00136 
00137         enum type_enum {
00138           PINHOLE, PINHOLESTEREO, BARRETO
00139         } type;
00140         enum kind_enum {
00141           PROPRIOCEPTIVE, EXTEROCEPTIVE
00142         } kind;
00143         virtual std::string categoryName() const {
00144           return "SENSOR";
00145         }
00146 
00147         inline void setId() { id(sensorIds.getId()); }
00148         
00149         void setPose(double x, double y, double z, double rollDeg,
00150             double pitchDeg, double yawDeg);
00151         void setPoseStd(double x, double y, double z, double rollDeg,
00152             double pitchDeg, double yawDeg, double xStd, double yStd,
00153             double zStd, double rollDegStd, double pitchDegStd,
00154             double yawDegStd);
00155         void setPoseStd(double x, double y, double z, double rollDeg,
00156             double pitchDeg, double yawDeg, double posStd, double oriDegStd) {
00157           setPoseStd(x, y, z, rollDeg, pitchDeg, yawDeg, posStd, posStd,
00158                      posStd, oriDegStd, oriDegStd, oriDegStd);
00159         }
00160 
00161 
00163         Gaussian pose;
00164 
00166         ind_array ia_globalPose;
00168         bool poseInFilter;
00169 
00170         size_t missed_data; 
00171 
00178         vec7 globalPose(bool normalize = false);
00179 
00191         void globalPose(jblas::vec7 & senGlobalPose, jblas::mat & SG_rs);
00192 
00193         virtual void writeLogHeader(kernel::DataLogger& log) const;
00194         virtual void writeLogData(kernel::DataLogger& log) const;
00195     };
00196     
00197     
00203     class SensorProprioAbstract: public SensorAbstract
00204     {
00205       protected:
00206         RawVec reading;
00207       public:
00208         hardware::hardware_sensorprop_ptr_t hardwareSensorPtr;
00209       public:
00210         SensorProprioAbstract(const robot_ptr_t & robPtr, const filtered_obj_t poseInFilter = UNFILTERED, int extraStateFilterSize = 0,
00211           std::vector<RobotAbstract::Quantity> robQuant = createQuantPosOriQuat()):
00212           SensorAbstract(robPtr, poseInFilter, extraStateFilterSize, robQuant) { kind = PROPRIOCEPTIVE; }
00213 
00214         void setHardwareSensor(hardware::hardware_sensorprop_ptr_t hardwareSensorPtr_)
00215           { hardwareSensorPtr = hardwareSensorPtr_; }
00216         virtual void start() { hardwareSensorPtr->start(); }
00217         virtual void stop() { hardwareSensorPtr->stop(); }
00218         virtual bool join(int timed_ms = -1) { return hardwareSensorPtr->join(timed_ms); }
00219         virtual void enableHard(bool enabled = true) { hardwareSensorPtr->enable(enabled); if (enabled) enable(true); }
00220         virtual void stopDumping() { hardwareSensorPtr->stopDumping(); }
00221         virtual void showInfos() { hardwareSensorPtr->showInfos(); }
00222 
00223 
00224         virtual int queryAvailableRaws(RawInfos &infos)
00225           { int res = hardwareSensorPtr->getUnreadRawInfos(infos); infos.integrate_all = integrate_all; return res; }
00226         virtual int queryNextAvailableRaw(RawInfo &info)
00227           { return hardwareSensorPtr->getNextRawInfo(info); }
00228         virtual double getRawTimestamp(unsigned id) { return hardwareSensorPtr->getRawTimestamp(id); } 
00229         //process(id) will do the filtering, so it is specific to each hardware
00230         void process_fake(unsigned id, bool move) { hardwareSensorPtr->getRaw(id, reading); if (move) robotPtr()->move_fake(reading.data(0)); use_for_init = false; }
00231         void discard(unsigned id) { hardwareSensorPtr->getRaw(id, reading); }
00232     };
00233     
00241     class SensorProprioPredictorAbstract: public SensorProprioAbstract
00242     {
00243       public:
00244         SensorProprioPredictorAbstract(const robot_ptr_t & robPtr, const filtered_obj_t poseInFilter = UNFILTERED, int extraStateFilterSize = 0):
00245           SensorProprioAbstract(robPtr, poseInFilter, extraStateFilterSize) {}
00246         virtual void predict(double t) = 0;
00247     
00248     };
00249     
00255     class SensorExteroAbstract: public SensorAbstract,
00256                                 public ParentOf<DataManagerAbstract>
00257     {
00258       protected:
00259         // define the type DataManagerList, and the function dataManagerList().
00260         ENABLE_ACCESS_TO_CHILDREN(DataManagerAbstract,DataManager,dataManager);
00261       
00262         raw_ptr_t rawPtr;
00263       public:
00264         hardware::hardware_sensorext_ptr_t hardwareSensorPtr;
00265       
00266       public:
00267         
00268         SensorExteroAbstract(const robot_ptr_t & robPtr, const filtered_obj_t poseInFilter = UNFILTERED, int extraStateFilterSize = 0):
00269           SensorAbstract(robPtr, poseInFilter, extraStateFilterSize)
00270         {
00271           kind = EXTEROCEPTIVE; 
00272           rawCounter = 0;
00273         }
00274 
00275         unsigned rawCounter;
00276 
00277         void setHardwareSensor(hardware::hardware_sensorext_ptr_t hardwareSensorPtr_)
00278           { hardwareSensorPtr = hardwareSensorPtr_; }
00279         virtual void start() { hardwareSensorPtr->start(); }
00280         virtual void stop() { hardwareSensorPtr->stop(); }
00281         virtual bool join(int timed_ms = -1) { return hardwareSensorPtr->join(timed_ms); }
00282         virtual void enableHard(bool enabled = true) { hardwareSensorPtr->enable(enabled); if (enabled) enable(true); }
00283         virtual void stopDumping() { hardwareSensorPtr->stopDumping(); }
00284         virtual void showInfos() { hardwareSensorPtr->showInfos(); }
00285 
00286 //        virtual int acquireRaw() = 0;
00287 //        virtual raw_ptr_t getRaw() = 0;
00288 
00289         virtual raw_ptr_t getLastProcessedRaw() { raw_ptr_t raw; hardwareSensorPtr->getLastProcessedRaw(raw); return raw; }
00290         virtual int queryAvailableRaws(RawInfos &infos)
00291           { int res = hardwareSensorPtr->getUnreadRawInfos(infos); infos.integrate_all = integrate_all; return res; }
00292         virtual int queryNextAvailableRaw(RawInfo &info)
00293           { return hardwareSensorPtr->getNextRawInfo(info); }
00294         virtual double getRawTimestamp(unsigned id) { return hardwareSensorPtr->getRawTimestamp(id); } 
00295         void process(unsigned id, double date_limit = -1.);
00296         void process_fake(unsigned id, bool move) { hardwareSensorPtr->getRaw(id, rawPtr); if (move) robotPtr()->move_fake(rawPtr->timestamp); rawCounter++; }
00297         void discard(unsigned id) { hardwareSensorPtr->getRaw(id, rawPtr); }
00298     };
00299 
00300   }
00301 }
00302 
00303 #endif /* SENSORABSTRACT_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

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