constraint_app
/home/jbrooksh/drc/software/perception/constraint_app/src/matlab_mex/ConstraintApp.h
Go to the documentation of this file.
00001 #ifndef CONSTRAINTAPP_H
00002 #define CONSTRAINTAPP_H
00003 
00004 #include <boost/thread.hpp>
00005 #include <boost/thread/condition_variable.hpp>
00006 #include <iostream>
00007 #include <fstream>
00008 //#include <lcmtypes/drc_lcmtypes.h>
00009 #include <lcm/lcm-cpp.hpp>
00010 #include <lcmtypes/drc_lcmtypes.hpp>
00011 #include <kdl/tree.hpp>
00012 #include <kdl/frames.hpp>
00013 #include <kdl_parser/kdl_parser.hpp>
00014 #include <forward_kinematics/treefksolverposfull_recursive.hpp>
00015 #include <map>
00016 #include <vector>
00017 #include <string>
00018 #include <kdl/frames.hpp>
00019 #include <kdl/frames_io.hpp>
00020 #include <boost/thread/thread_time.hpp>
00021 #include <boost/optional.hpp>
00022 #include "Affordance.h"
00023 
00024 class ConstraintApp
00025 {
00026  public :
00027 
00028   ConstraintApp();
00029   virtual ~ConstraintApp();
00030 
00031   virtual bool WaitForObservations(unsigned int timeout_ms) = 0;
00032   virtual bool GetObservations(std::vector<double>& actualObservations,
00033                                std::vector<std::string>& observationIds) = 0;
00034   virtual bool GetExpectedObservations(const std::vector<double>& state,
00035                                        const std::vector<std::string>& observationIds,
00036                                        std::vector<double>& observations) = 0;
00037   virtual bool GetResetAndClear() = 0;
00038   virtual void GetCurrentStateEstimate(std::vector<double>& state) = 0;
00039   virtual void SetCurrentStateEstimate(const std::vector<double>& state) = 0;
00040 
00041   virtual void AffordanceTrackCollectionHandlerAux(const lcm::ReceiveBuffer* rbuf, const std::string& channel,
00042                                                    const drc::affordance_track_collection_t *tracks) {
00043     AffordanceTrackCollectionHandler(tracks);
00044   }
00045   virtual void AffordanceTrackCollectionHandler(const drc::affordance_track_collection_t *affordance) = 0;
00046 
00047   virtual void AffordanceFitHandlerAux(const lcm::ReceiveBuffer* rbuf, const std::string& channel,
00048                                        const drc::affordance_plus_t *affordance) {
00049     AffordanceFitHandler(affordance);
00050   }
00051   virtual void AffordanceFitHandler(const drc::affordance_plus_t *affordance) = 0;
00052 
00053   virtual int GetStateSize() = 0;
00054 
00055   typedef boost::optional<KDL::Frame> OptionalKDLFrame;
00056   static OptionalKDLFrame GetFrameFromParams(const drc::affordance_t *msg);
00057   static std::vector<double> FrameToVector(const KDL::Frame& frame);
00058   static KDL::Frame VectorToFrame(const std::vector<double>& state);  
00059 
00060  protected :
00061   bool shouldStop();
00062   void stopThreads();
00063   void main();
00064   int lcm_handle_timeout(lcm_t* lcm, int ms);
00065 
00066  protected :
00067   boost::thread* m_mainThread;
00068   volatile bool m_stopThreads;
00069   boost::mutex m_stopThreadsMutex;
00070 
00071   boost::mutex m_lcmMutex;
00072   lcm::LCM* m_lcm;
00073 
00074   std::ofstream m_log;
00075 };
00076 
00077 #endif
 All Classes Files Functions Variables Typedefs