00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00038
00039 class taoDNode;
00040 class taoJoint;
00041
00042 namespace jspace {
00043
00044
00045
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
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
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
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
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