SCL  1.0
Standard Control Library : Control, dynamics, physics, and simulation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Groups Pages
Model.hpp
Go to the documentation of this file.
1 /*
2  * Stanford Whole-Body Control Framework http://stanford-scl.sourceforge.net/
3  *
4  * Copyright (c) 2010 Stanford University. All rights reserved.
5  *
6  * This program is free software: you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation, either version 3 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this program. If not, see
18  * <http://www.gnu.org/licenses/>
19  */
20 
26 #ifndef JSPACE_MODEL_HPP
27 #define JSPACE_MODEL_HPP
28 
29 #include <jspace/State.hpp>
30 #include <jspace/wrap_eigen.hpp>
31 #include <string>
32 #include <vector>
33 #include <list>
34 #include <map>
35 #include <set>
36 
37 // Clients of Model never really need to worry about what exactly lies
38 // behind TAO, they can treat this as an opaque pointer type.
39 class taoDNode;
40 class taoJoint;
41 class deVector3;
42 
43 namespace jspace {
44 
45 
46  // declared in <jspace/tao_util.hpp>
47  struct STaoTreeInfo;
48 
49  class Model
50  {
51  public:
56  Model();
57 
58  ~Model();
59 
78  int init(
82  STaoTreeInfo * kgm_tree,
88  STaoTreeInfo * cc_tree,
90  double grav_x_,
92  double grav_y_,
94  double grav_z_,
97  std::ostream * msg);
98 
100  // fire-and-forget facet
101 
113  void update(State const & state);
114 
127  void setState(State const & state);
128 
131  inline State const & getState() const { return state_; }
132 
134  // Bare tree accessors.
135 
144  size_t getNNodes() const;
145 
149  size_t getNJoints() const;
150 
155  size_t getNDOF() const;
156 
160  std::string getNodeName(size_t id) const;
161 
169  std::string getJointName(size_t id) const;
170 
172  taoDNode * getNode(size_t id) const;
173 
180  taoDNode * getNodeByName(std::string const & name) const;
181 
195  taoDNode * getNodeByJointName(std::string const & name) const;
196 
202  void getJointLimits(Eigen::VectorXd & joint_limits_lower,
203  Eigen::VectorXd & joint_limits_upper) const;
204 
206  // kinematic facet
207 
209  void updateKinematics();
210 
217  bool getGlobalFrame(taoDNode const * node,
218  Eigen::Affine3d & global_transform) const;
219 
227  bool computeGlobalFrame(taoDNode const * node,
228  Eigen::Affine3d const & local_transform,
229  Eigen::Affine3d & global_transform) const;
230 
239  bool computeGlobalFrame(taoDNode const * node,
240  double local_x, double local_y, double local_z,
241  Eigen::Affine3d & global_transform) const;
242 
251  bool computeGlobalFrame(taoDNode const * node,
252  Eigen::VectorXd const & local_translation,
253  Eigen::Affine3d & global_transform) const;
254 
255  bool computeGlobalCOMFrame(taoDNode const * node,
256  Eigen::Affine3d & global_com_transform) const;
257 
269  bool computeJacobian(taoDNode const * node,
270  Eigen::MatrixXd & jacobian) const;
271 
282  bool computeJacobian(taoDNode const * node,
283  double gx, double gy, double gz,
284  Eigen::MatrixXd & jacobian) const;
285 
288  inline bool computeJacobian(taoDNode const * node,
289  Eigen::VectorXd const & global_point,
290  Eigen::MatrixXd & jacobian) const
291  { return computeJacobian(node, global_point[0], global_point[1], global_point[2], jacobian); }
292 
294  // dynamics facet
295 
298  void updateDynamics();
299 
305  bool computeCOM(Eigen::VectorXd & com, Eigen::MatrixXd * opt_jcom) const;
306 
308  void computeGravity();
309 
319  bool disableGravityCompensation(size_t index, bool disable);
320 
326  bool getGravity(Eigen::VectorXd & gravity) const;
327 
332 
340  bool getCoriolisCentrifugal(Eigen::VectorXd & coriolis_centrifugal) const;
341 
344  void computeMassInertia();
345 
352  bool getMassInertia(Eigen::MatrixXd & mass_inertia) const;
353 
356 
362  bool getInverseMassInertia(Eigen::MatrixXd & inverse_mass_inertia) const;
363 
364 
367  STaoTreeInfo * _getKGMTree() { return kgm_tree_; }
368 
372  STaoTreeInfo * _getCCTree() { return cc_tree_; }
373 
374 
375  private:
376  typedef std::set<size_t> dof_set_t;
377 
378  std::size_t ndof_;
379  STaoTreeInfo * kgm_tree_;
380  STaoTreeInfo * cc_tree_;
381 
382  dof_set_t gravity_disabled_;
383  deVector3* gravity_;
384 
385  State state_;
386  Eigen::VectorXd g_torque_;
387  Eigen::VectorXd cc_torque_;
388  std::vector<double> a_upper_triangular_;
389  std::vector<double> ainv_upper_triangular_;
390 
391  struct SAncestryEntry {
392  int id;
393  taoJoint * joint;
394  };
395 
396  std::map<taoDNode *, std::list<SAncestryEntry> > ancestry_table_;
397  };
398 
399 }
400 
401 #endif // JSPACE_MODEL_HPP
STaoTreeInfo * _getKGMTree()
Definition: Model.hpp:367
void setState(State const &state)
Definition: Model.cpp:158
void computeGravity()
Definition: Model.cpp:469
3x1 vector classThis is a C++ wrapper class of deVector3f.
Definition: TaoDeVector3.h:32
bool computeGlobalFrame(taoDNode const *node, Eigen::Affine3d const &local_transform, Eigen::Affine3d &global_transform) const
Definition: Model.cpp:300
void updateKinematics()
Definition: Model.cpp:263
bool disableGravityCompensation(size_t index, bool disable)
Definition: Model.cpp:478
STaoTreeInfo * _getCCTree()
Definition: Model.hpp:372
taoDNode * getNodeByName(std::string const &name) const
Definition: Model.cpp:229
void updateDynamics()
Definition: Model.cpp:427
Definition: Model.hpp:49
bool computeJacobian(taoDNode const *node, Eigen::MatrixXd &jacobian) const
Definition: Model.cpp:355
Definition: tao_util.hpp:68
bool getGlobalFrame(taoDNode const *node, Eigen::Affine3d &global_transform) const
Definition: Model.cpp:274
std::string getJointName(size_t id) const
Definition: Model.cpp:210
abstract node class for articulated bodyA dynamics node = {Articulated Body Link + Set of associated ...
Definition: taoDNode.h:46
bool computeJacobian(taoDNode const *node, Eigen::VectorXd const &global_point, Eigen::MatrixXd &jacobian) const
Definition: Model.hpp:288
void update(State const &state)
Definition: Model.cpp:150
size_t getNJoints() const
Definition: Model.cpp:186
void computeInverseMassInertia()
Definition: Model.cpp:603
bool computeCOM(Eigen::VectorXd &com, Eigen::MatrixXd *opt_jcom) const
Definition: Model.cpp:436
Definition: State.hpp:33
std::string getNodeName(size_t id) const
Definition: Model.cpp:200
bool getGravity(Eigen::VectorXd &gravity) const
Definition: Model.cpp:507
void computeMassInertia()
Definition: Model.cpp:547
Definition: Model.hpp:391
size_t getNDOF() const
Definition: Model.cpp:193
Base joint class for articulated bodyThis provides a joint for articulated body dynamics.
Definition: taoJoint.h:45
State const & getState() const
Definition: Model.hpp:131
bool getMassInertia(Eigen::MatrixXd &mass_inertia) const
Definition: Model.cpp:583
bool getInverseMassInertia(Eigen::MatrixXd &inverse_mass_inertia) const
Definition: Model.cpp:638
size_t getNNodes() const
Definition: Model.cpp:180
int init(STaoTreeInfo *kgm_tree, STaoTreeInfo *cc_tree, double grav_x_, double grav_y_, double grav_z_, std::ostream *msg)
Definition: Model.cpp:65
taoDNode * getNode(size_t id) const
Definition: Model.cpp:220
Model()
Definition: Model.cpp:56
void getJointLimits(Eigen::VectorXd &joint_limits_lower, Eigen::VectorXd &joint_limits_upper) const
Definition: Model.cpp:251
void computeCoriolisCentrifugal()
Definition: Model.cpp:522
taoDNode * getNodeByJointName(std::string const &name) const
Definition: Model.cpp:240
bool getCoriolisCentrifugal(Eigen::VectorXd &coriolis_centrifugal) const
Definition: Model.cpp:534