All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
joint_constraint.h
1 /* Copyright (C) 2004-2009 MBSim Development Team
2  * This library is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU Lesser General Public
4  * License as published by the Free Software Foundation; either
5  * version 2.1 of the License, or (at your option) any later version.
6  *
7  * This library is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10  * Lesser General Public License for more details.
11  *
12  * You should have received a copy of the GNU Lesser General Public
13  * License along with this library; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15  *
16  * Contact: martin.o.foerg@googlemail.com
17  */
18 
19 #ifndef _JOINT_CONSTRAINT_H
20 #define _JOINT_CONSTRAINT_H
21 
22 #include "mechanical_constraint.h"
23 #include "mbsim/functions/function.h"
24 #include "mbsim/frames/floating_relative_frame.h"
25 
26 namespace MBSim {
27 
28  class RigidBody;
29  class Frame;
30 
37  public:
38  enum FrameOfReference {
39  firstFrame=0,
40  secondFrame,
41  unknown
42  };
43 
44  JointConstraint(const std::string &name="");
45 
46  void init(InitStage stage, const InitConfigSet &config) override;
47 
48  void resetUpToDate() override;
49 
50  void connect(Frame* frame0, Frame* frame1) { frame[0] = frame0; frame[1] = frame1; }
51  void addDependentRigidBodyOnFirstSide(RigidBody* bd) { bd1.push_back(bd); }
52  void addDependentRigidBodyOnSecondSide(RigidBody* bd) { bd2.push_back(bd); }
53  void setIndependentRigidBody(RigidBody* bi_) { bi.resize(1); bi[0] = bi_; }
54  void addIndependentRigidBody(RigidBody* bi_) { bi.push_back(bi_); }
55 
56  void setUpInverseKinetics() override;
57  void setForceDirection(const fmatvec::Mat3xV& fd);
58  void setMomentDirection(const fmatvec::Mat3xV& md);
59 
63  void setFrameOfReference(FrameOfReference refFrame_) { refFrame = refFrame_; }
64 
65  void updatePositions(Frame *frame) override;
66  void updateGeneralizedCoordinates() override;
67  void updateGeneralizedJacobians(int jj=0) override;
68  void updateForceDirections();
69  void updateA();
70 
71  const fmatvec::Mat3xV& evalGlobalForceDirection() { if(updDF) updateForceDirections(); return DF; }
72  const fmatvec::Mat3xV& evalGlobalMomentDirection() { if(updDF) updateForceDirections(); return DM; }
73  const fmatvec::SqrMat& evalA() { if(updA) updateA(); return A; }
74 
75  fmatvec::Mat3xV& getGlobalForceDirection(bool check=true) { assert((not check) or (not updDF)); return DF; }
76  fmatvec::Mat3xV& getGlobalMomentDirection(bool check=true) { assert((not check) or (not updDF)); return DM; }
77  fmatvec::SqrMat& getA(bool check=true) { assert((not check) or (not updA)); return A; }
78 
79  void setInitialGuess(const fmatvec::VecV &q0_) { q0 = q0_; }
80 
81  void initializeUsingXML(xercesc::DOMElement *element) override;
82 
83  private:
84  class Residuum : public Function<fmatvec::Vec(fmatvec::Vec)> {
85  private:
86  std::vector<RigidBody*> body1, body2;
87  fmatvec::Mat3xV forceDir, momentDir;
88  std::vector<Frame*> frame;
89  FrameOfReference refFrame;
90  public:
91  Residuum(std::vector<RigidBody*> body1_, std::vector<RigidBody*> body2_, const fmatvec::Mat3xV &forceDir_, const fmatvec::Mat3xV &momentDir_, const std::vector<Frame*> frame_, FrameOfReference refFrame_);
92 
93  fmatvec::Vec operator()(const fmatvec::Vec &x) override;
94  };
95  std::vector<RigidBody*> bd1, bd2, bi;
96 
97  std::vector<Frame*> frame;
98 
102  FrameOfReference refFrame{firstFrame};
103 
105 
106  fmatvec::Mat3xV DF, DM, forceDir, momentDir;
107 
108  fmatvec::RangeV iF, iM;
109  std::vector<fmatvec::RangeV> Iq1, Iq2, Iu1, Iu2, Ih1, Ih2;
110  int nq{0};
111  int nu{0};
112  int nh{0};
113  fmatvec::Vec q, q0;
114  fmatvec::Mat JT, JR;
115  fmatvec::SqrMat A;
116 
117  bool updDF{true};
118  bool updA{true};
119 
120  std::string saved_ref1, saved_ref2;
121  std::vector<std::string> saved_RigidBodyFirstSide, saved_RigidBodySecondSide, saved_IndependentBody;
122  };
123 
124 }
125 
126 #endif
Class for mechanical constraints.
Definition: mechanical_constraint.h:32
cartesian frame on rigid bodies
Definition: floating_relative_frame.h:31
FrameOfReference refFrame
frame of reference the force is defined in
Definition: joint_constraint.h:102
void setFrameOfReference(FrameOfReference refFrame_)
The frame of reference for the force/moment direction vectors. If firstFrame (default) the first fram...
Definition: joint_constraint.h:63
Definition: joint_constraint.h:84
fmatvec::Vec x
order one parameters
Definition: constraint.h:60
Joint contraint.
Definition: joint_constraint.h:36
InitStage
The stages of the initialization.
Definition: element.h:62
Definition: planar_contour.h:30
std::string name
name of element
Definition: element.h:235
cartesian frame on bodies used for application of e.g. links and loads
Definition: frame.h:39
void init(InitStage stage, const InitConfigSet &config) override
plots time series header
Definition: joint_constraint.cc:73
rigid bodies with arbitrary kinematics
Definition: rigid_body.h:50

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Home