1 // =============================================================================
2 // PROJECT CHRONO - http://projectchrono.org
3 //
4 // Copyright (c) 2014 projectchrono.org
5 // All rights reserved.
6 //
7 // Use of this source code is governed by a BSD-style license that can be found
8 // in the LICENSE file at the top level of the distribution and at
9 // http://projectchrono.org/license-chrono.txt.
10 //
11 // =============================================================================
12 // Authors: Alessandro Tasora, Radu Serban
13 // =============================================================================
14 
15 #ifndef CHLINK_H
16 #define CHLINK_H
17 
18 #include "chrono/physics/ChBodyFrame.h"
19 #include "chrono/physics/ChLinkBase.h"
20 
21 namespace chrono {
22 
23 // Forward references
24 class ChSystem;
25 
26 /// Base class for joints between two ChBodyFrame objects.
27 ///
28 /// Links (joints) are objects which can be created to constrain two rigid bodies
29 /// (i.e. objects from the ChBody class) in 3D space.
30 ///
31 /// Note that there are many specializations of this base class. In fact, this base
32 /// ChLink class does basically nothing, unless it is specialized by some child class.
33 class ChApi ChLink : public ChLinkBase {
34 
35   protected:
36     ChBodyFrame* Body1;       ///< first connected body
37     ChBodyFrame* Body2;       ///< second connected body
38     ChVector<> react_force;   ///< store the xyz reactions, expressed in local coordinate system of link;
39     ChVector<> react_torque;  ///< store the torque reactions, expressed in local coordinate system of link;
40 
41   public:
ChLink()42     ChLink() : Body1(NULL), Body2(NULL), react_force(VNULL), react_torque(VNULL) {}
43     ChLink(const ChLink& other);
~ChLink()44     virtual ~ChLink() {}
45 
46     /// "Virtual" copy constructor (covariant return type).
Clone()47     virtual ChLink* Clone() const override { return new ChLink(*this); }
48 
49     /// Get the number of free degrees of freedom left by this link, between two bodies.
GetLeftDOF()50     int GetLeftDOF() { return 6 - GetDOC(); }
51 
52     /// Get the number of scalar variables affected by constraints in this link
GetNumCoords()53     virtual int GetNumCoords() override { return 12; }
54 
55     /// Get the constrained body '1', the 'slave' body.
GetBody1()56     ChBodyFrame* GetBody1() { return Body1; }
57     /// Get the constrained body '2', the 'master' body.
GetBody2()58     ChBodyFrame* GetBody2() { return Body2; }
59 
60     /// Get the link coordinate system, expressed relative to Body2 (the 'master' body). This represents the 'main'
61     /// reference of the link: reaction forces and reaction torques are expressed in this coordinate system. By default
62     /// this is in the origin of Body2.
GetLinkRelativeCoords()63     virtual ChCoordsys<> GetLinkRelativeCoords() { return CSYSNORM; }
64 
65     /// Get the link coordinate system in absolute reference. This represents the 'main' reference of the link: reaction
66     /// forces and reaction torques are expressed in this coordinate system.
GetLinkAbsoluteCoords()67     virtual ChCoordsys<> GetLinkAbsoluteCoords() override { return GetLinkRelativeCoords() >> Body2->GetCoord(); }
68 
69     /// Get reaction force, expressed in link coordinate system.
Get_react_force()70     virtual ChVector<> Get_react_force() override { return react_force; }
71     /// Get reaction torque,  expressed in link coordinate system.
Get_react_torque()72     virtual ChVector<> Get_react_torque() override { return react_torque; }
73 
74     /// If some constraint is redundant, return to normal state  //***OBSOLETE***
RestoreRedundant()75     virtual int RestoreRedundant() { return 0; }
76 
77     //
78     // UPDATING FUNCTIONS
79     //
80 
81     /// Given new time, current body state, update time-dependent quantities in link state,
82     /// for example motion laws, moving markers, etc.
83     /// Default: do nothing except setting new time.
84     virtual void UpdateTime(double mytime);
85 
86     /// This function, called by the owner ChSystem at least once per integration step,
87     /// updates any auxiliary data of the link (e.g. internal states, forces, Jacobian matrices).
88     /// This base version, by default, simply updates the time.
89     virtual void Update(double mytime, bool update_assets = true) override;
90 
91     /// As above, but with current time
92     virtual void Update(bool update_assets = true) override;
93 
94     /// Called from a external package (i.e. a plugin, a CAD app.) to report that time has changed.
UpdatedExternalTime(double prevtime,double time)95     virtual void UpdatedExternalTime(double prevtime, double time) {}
96 
97     //
98     // SERIALIZATION
99     //
100 
101     /// Method to allow serialization of transient data to archives.
102     virtual void ArchiveOUT(ChArchiveOut& marchive) override;
103 
104     /// Method to allow deserialization of transient data from archives.
105     virtual void ArchiveIN(ChArchiveIn& marchive) override;
106 };
107 
108 CH_CLASS_VERSION(ChLink,0)
109 
110 }  // end namespace chrono
111 
112 #endif
113