jspace/jspace/Model.hpp

Go to the documentation of this file.
00001 /*
00002  * Stanford Whole-Body Control Framework http://stanford-wbc.sourceforge.net/
00003  *
00004  * Copyright (C) 2010 The Board of Trustees of The Leland Stanford Junior University. All rights reserved.
00005  *
00006  * This program is free software: you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public License
00008  * as published by the Free Software Foundation, either version 3 of
00009  * the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful, but
00012  * WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this program.  If not, see
00018  * <http://www.gnu.org/licenses/>
00019  */
00020 
00026 #ifndef JSPACE_MODEL_HPP
00027 #define JSPACE_MODEL_HPP
00028 
00029 #include <jspace/State.hpp>
00030 #include <jspace/wrap_eigen.hpp>
00031 #include <string>
00032 #include <vector>
00033 #include <list>
00034 #include <map>
00035 #include <set>
00036 
00037 // Clients of Model never really need to worry about what exactly lies
00038 // behind TAO, they can treat this as an opaque pointer type.
00039 class taoDNode;
00040 class taoJoint;
00041 
00042 namespace jspace {
00043   
00044   
00045   // declared in <jspace/tao_util.hpp>
00046   struct tao_tree_info_s;
00047   
00048   class Model
00049   {
00050   public:
00055     Model();
00056     
00057     ~Model();
00058     
00077     int init(
00081        tao_tree_info_s * kgm_tree,
00087        tao_tree_info_s * cc_tree,
00090        std::ostream * msg);
00091     
00093     // fire-and-forget facet
00094     
00106     void update(State const & state);
00107     
00120     void setState(State const & state);
00121     
00124     inline State const & getState() const { return state_; }
00125     
00127     // Bare tree accessors.
00128     
00137     size_t getNNodes() const;
00138     
00142     size_t getNJoints() const;
00143     
00148     size_t getNDOF() const;
00149     
00153     std::string getNodeName(size_t id) const;
00154     
00162     std::string getJointName(size_t id) const;
00163     
00165     taoDNode * getNode(size_t id) const;
00166     
00173     taoDNode * getNodeByName(std::string const & name) const;
00174     
00188     taoDNode * getNodeByJointName(std::string const & name) const;
00189     
00195     void getJointLimits(Vector & joint_limits_lower,
00196       Vector & joint_limits_upper) const;
00197     
00199     // kinematic facet
00200     
00202     void updateKinematics();
00203     
00210     bool getGlobalFrame(taoDNode const * node,
00211       Transform & global_transform) const;
00212     
00220     bool computeGlobalFrame(taoDNode const * node,
00221           Transform const & local_transform,
00222           Transform & global_transform) const;
00223     
00232     bool computeGlobalFrame(taoDNode const * node,
00233           double local_x, double local_y, double local_z,
00234           Transform & global_transform) const;
00235     
00244     bool computeGlobalFrame(taoDNode const * node,
00245           Vector const & local_translation,
00246           Transform & global_transform) const;
00247     
00248     bool computeGlobalCOMFrame(taoDNode const * node,
00249              Transform & global_com_transform) const;
00250     
00262     bool computeJacobian(taoDNode const * node,
00263        Matrix & jacobian) const;
00264     
00275     bool computeJacobian(taoDNode const * node,
00276        double gx, double gy, double gz,
00277        Matrix & jacobian) const;
00278     
00281     inline bool computeJacobian(taoDNode const * node,
00282         Vector const & global_point,
00283         Matrix & jacobian) const
00284     { return computeJacobian(node, global_point[0], global_point[1], global_point[2], jacobian); }
00285     
00287     // dynamics facet
00288     
00291     void updateDynamics();
00292     
00298     bool computeCOM(Vector & com, Matrix * opt_jcom) const;
00299     
00301     void computeGravity();
00302     
00312     bool disableGravityCompensation(size_t index, bool disable);
00313     
00319     bool getGravity(Vector & gravity) const;
00320     
00324     void computeCoriolisCentrifugal();
00325     
00333     bool getCoriolisCentrifugal(Vector & coriolis_centrifugal) const;
00334     
00337     void computeMassInertia();
00338     
00345     bool getMassInertia(Matrix & mass_inertia) const;
00346     
00348     void computeInverseMassInertia();
00349     
00355     bool getInverseMassInertia(Matrix & inverse_mass_inertia) const;
00356     
00357     
00360     tao_tree_info_s * _getKGMTree() { return kgm_tree_; }
00361     
00365     tao_tree_info_s * _getCCTree() { return cc_tree_; }
00366     
00367     
00368   private:
00369     typedef std::set<size_t> dof_set_t;
00370     dof_set_t gravity_disabled_;
00371     
00372     std::size_t ndof_;
00373     tao_tree_info_s * kgm_tree_;
00374     tao_tree_info_s * cc_tree_;
00375     
00376     State state_;
00377     Vector g_torque_;
00378     Vector cc_torque_;
00379     std::vector<double> a_upper_triangular_;
00380     std::vector<double> ainv_upper_triangular_;
00381     
00382     struct ancestry_entry_s {
00383       int id;
00384       taoJoint * joint;
00385     };
00386     typedef std::list<ancestry_entry_s> ancestry_list_t;
00387     typedef std::map<taoDNode *, ancestry_list_t> ancestry_table_t;
00388     ancestry_table_t ancestry_table_;
00389   };
00390   
00391 }
00392 
00393 #endif // JSPACE_MODEL_HPP

Generated on Fri Aug 26 01:31:16 2011 for Stanford Whole-Body Control Framework by  doxygen 1.5.4