constraint_app
/home/jbrooksh/drc/software/perception/constraint_app/src/matlab_mex/Affordance.h
Go to the documentation of this file.
00001 #ifndef AFFORDANCE_H
00002 #define AFFORDANCE_H
00003 
00004 #include <boost/shared_ptr.hpp>
00005 #include <kdl/frames.hpp>
00006 #include <kdl/frames_io.hpp>
00007 #include <lcmtypes/drc_lcmtypes.h>
00008 #include <lcm/lcm.h>
00009 #include <otdf_parser/otdf_parser.h>
00010 #include <lcmtypes/bot_core.h>
00011 #include <path_util/path_util.h>
00012 #include <urdf/model.h>
00013 #include <kdl/tree.hpp>
00014 #include <kdl_parser/kdl_parser.hpp>
00015 #include <forward_kinematics/treefksolverposfull_recursive.hpp>
00016 #include <otdf_parser/otdf_parser.h>
00017 #include <otdf_parser/otdf_urdf_converter.h>
00018 #include <boost/bimap.hpp>
00019 #include <boost/multi_index_container.hpp>
00020 #include <boost/multi_index/sequenced_index.hpp>
00021 #include <boost/multi_index/ordered_index.hpp>
00022 #include <boost/multi_index/identity.hpp>
00023 
00024 using namespace boost::multi_index;
00025 
00026 class Affordance {
00027  public:
00028   class Joint {
00029   public:
00030   Joint(const std::string& _name, const int& _num) : name(_name), num(_num) {}
00031     std::string name;
00032     int num;
00033   };  
00034 
00035   typedef boost::shared_ptr<Affordance> Ptr;
00036   typedef std::vector<double> StateVector;
00037   typedef std::map<std::string, KDL::Twist> SegmentNoiseMap;
00038   
00039   Affordance(const std::string& filename, std::ostream& log = std::cout);
00040   //Affordance(std::ostream& log, const drc::affordance_t& msg);  
00041   bool GetStateFromMsg(const drc::affordance_t& msg, StateVector& state);
00042   void PrintState(const StateVector& state);
00043   KDL::Tree& GetTree() { return m_tree; }
00044   bool GetSegmentExpressedInWorld(const std::string& segmentName, const StateVector& state, 
00045                                   KDL::Frame& segment_expressedIn_world);
00046   bool GetSegmentJacobianExpressedInWorld(const std::string& segmentName, 
00047                                           const StateVector& state, 
00048                                           KDL::Jacobian& jacobian);
00049   bool GetSegmentJacobianExpressedInWorld2(const std::string& segmentName, 
00050                                            const StateVector& state, 
00051                                            KDL::Jacobian& jacobian);
00052   bool DecodeState(const StateVector& state, KDL::Frame& root_expressedIn_world, KDL::JntArray& joints);
00053   void DecodeState(const StateVector& state, KDL::JntArray& joints);
00054   void PrintKdlTree() { PrintKdlTree(m_tree, m_tree.getRootSegment()->second, 0); }
00055 
00056   bool noisyTreeCopy(const SegmentNoiseMap& noiseMap,
00057                      KDL::Tree& newTree, 
00058                      KDL::SegmentMap::const_iterator root, 
00059                      const std::string& hook_name);
00060 
00061   void GetJointNames(std::vector<std::string>& names);
00062 
00063  private:
00064   void PrintKdlTree(const KDL::Tree& tree, 
00065                     const KDL::TreeElement& segment,
00066                     unsigned int depth); 
00067   void UpdateJointNames(const KDL::TreeElement* element = NULL);
00068   void PrintJointNames();
00069 
00070  public:
00071   static KDL::Frame GetFrameFromVector(const StateVector& state);
00072 
00073  public:
00074   std::ostream& m_log;
00075   KDL::Tree m_tree;
00076   KDL::Tree m_originalTree;
00077 
00078   typedef boost::multi_index_container<
00079     Joint,
00080     indexed_by<
00081       ordered_unique<member<Joint, int, &Joint::num> >,
00082       ordered_unique<member<Joint, std::string, &Joint::name> >
00083     > 
00084     > JointMultiIndex;
00085   JointMultiIndex m_joints;    
00086 };
00087 
00088 #endif
 All Classes Files Functions Variables Typedefs