AGX Dynamics  2.37.2.0
RigidBodyAttributeAccessors.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGXFMI2_RIGIDBODYATTRIBUTEACCESSORS_H
18 #define AGXFMI2_RIGIDBODYATTRIBUTEACCESSORS_H
19 
22 #include <agx/Solver.h>
23 #include <agxData/Attribute.h>
24 
25 extern "C"
26 {
27  #include <FMI2/fmi2Functions.h>
28 }
29 
30 namespace agx {
31  class RigidBody;
32 }
33 
34 namespace agxFMI2
35 {
36  namespace Export
37  {
39  // INPUT VARIABLES
42 
43  class AGXFMI_EXPORT RigidBodyAttributeInputVariableReal : public InputVariable_Real
44  {
45  public:
47 
49  void setBody(agx::Physics::RigidBodyRef body);
50  protected:
52 
53  protected:
55  };
56 
58 
59  // Generic agx::Vec3 attribute
61  {
62  public:
64 
65  public:
66  RigidBodyVec3AttributeInputVariable(agx::RigidBody *body, AttributeT *attribute, agx::UInt component, bool causalityName = false);
67  RigidBodyVec3AttributeInputVariable(agx::RigidBody *body, AttributeT *attribute, agx::UInt component, const agx::String& name);
68  virtual fmi2Status set(agx::Real value) override;
69  virtual fmi2Status get(agx::Real& value) override;
70 
71  void setDirectionalDerivativeInput(agx::MobilitySolver *solver, agx::Real value);
72 
73  protected:
75 
76  private:
77  using InputVariable_Real::get;
78  agx::Real get();
79 
80  protected:
83 
84  };
85 
86 #define RB_VEC3_INPUT_VARIABLE(NAME, ATTRIBUTE_NAME) \
87  class AGXFMI_EXPORT RigidBody ## NAME ## InputVariable : public RigidBodyVec3AttributeInputVariable \
88  { \
89  public: \
90  RigidBody ## NAME ## InputVariable(agx::RigidBody *body, agx::UInt component, bool causalityName = false) : RigidBodyVec3AttributeInputVariable(body, agx::Physics::RigidBodyModel::ATTRIBUTE_NAME ## Attribute, component, causalityName) {} \
91  \
92  protected: \
93  virtual ~RigidBody ## NAME ## InputVariable() {} \
94  }
95 
96  RB_VEC3_INPUT_VARIABLE(Force, force);
97  RB_VEC3_INPUT_VARIABLE(Torque, torque);
98  RB_VEC3_INPUT_VARIABLE(Velocity, velocity);
99  RB_VEC3_INPUT_VARIABLE(AngularVelocity, angularVelocity);
100 
102 
104  {
105  public:
106  RigidBodyForceAccumulatorInputVariable(agx::RigidBody *body, agx::UInt component, bool causalityName = false);
107  virtual fmi2Status set(agx::Real value) override;
108  void apply();
109 
110  protected:
112 
113  private:
114  agx::Real m_storedValue;
115  };
116 
118 
120  {
121  public:
122  RigidBodyTorqueAccumulatorInputVariable(agx::RigidBody *body, agx::UInt component, bool causalityName = false);
123  virtual fmi2Status set(agx::Real value) override;
124  void apply();
125 
126  protected:
128 
129  private:
130  agx::Real m_storedValue;
131  };
132 
133 
135  {
136  public:
137  RigidBodyPositionInputVariable(agx::RigidBody *body, agx::UInt component, bool causalityName = false);
138  virtual fmi2Status set(agx::Real value) override;
139  virtual fmi2Status get(agx::Real& value) override;
140 
141  protected:
143 
144  private:
145  agx::UInt m_component;
146  };
147 
149  {
150  public:
151  RigidBodyRotationQuatInputVariable(agx::RigidBody *body, agx::UInt component, bool causalityName = false);
152  virtual fmi2Status set(agx::Real value) override;
153  virtual fmi2Status get(agx::Real& value) override;
154 
155  protected:
157 
158  private:
159  agx::UInt m_component;
160  };
161 
163  {
164  public:
165  RigidBodyRotationEulerInputVariable(agx::RigidBody *body, agx::UInt component, bool causalityName = false);
166  virtual fmi2Status set(agx::Real value) override;
167  virtual fmi2Status get(agx::Real& value) override;
168 
169  protected:
171 
172  private:
173  agx::UInt m_component;
174  };
175 
176 
178  // OUTPUT VARIABLES
180 
181  // Generic agx::Vec3 attribute
182 
183  class AGXFMI_EXPORT RigidBodyVec3AttributeOutputVariable : public OutputVariable_Real
184  {
185  public:
187 
188  public:
189  RigidBodyVec3AttributeOutputVariable(agx::RigidBody *body, AttributeT *attribute, agx::UInt component, bool causalityName = false);
190  virtual fmi2Status get(agx::Real& value) override;
191  agx::Real getDirectionalDerivativeOutput(agx::MobilitySolver *solver, agx::MobilitySolver *referenceSolver);
192  agx::Real get(agx::MobilitySolver *solver);
193 
194  protected:
196 
197  private:
199  agx::ref_ptr<AttributeT> m_attribute;
200  agx::UInt m_component;
201  };
202 
203 #define RB_VEC3_OUTPUT_VARIABLE(NAME, ATTRIBUTE_NAME) \
204  class AGXFMI_EXPORT RigidBody ## NAME ## OutputVariable : public RigidBodyVec3AttributeOutputVariable \
205  { \
206  public: \
207  RigidBody ## NAME ## OutputVariable(agx::RigidBody *body, agx::UInt component, bool causalityName = false) : RigidBodyVec3AttributeOutputVariable(body, agx::Physics::RigidBodyModel::ATTRIBUTE_NAME ## Attribute, component, causalityName) {} \
208  \
209  protected: \
210  virtual ~RigidBody ## NAME ## OutputVariable() {} \
211  }
212 
213  RB_VEC3_OUTPUT_VARIABLE(Force, force);
214  RB_VEC3_OUTPUT_VARIABLE(Torque, torque);
215  RB_VEC3_OUTPUT_VARIABLE(AppliedForce, lastForce);
216  RB_VEC3_OUTPUT_VARIABLE(AppliedTorque, lastTorque);
217  RB_VEC3_OUTPUT_VARIABLE(Acceleration, linearAcceleration);
218  RB_VEC3_OUTPUT_VARIABLE(AngularAcceleration, angularAcceleration);
219  RB_VEC3_OUTPUT_VARIABLE(Velocity, velocity);
220  RB_VEC3_OUTPUT_VARIABLE(AngularVelocity, angularVelocity);
221 
222 
223  class AGXFMI_EXPORT RigidBodyPositionOutputVariable : public OutputVariable_Real
224  {
225  public:
226  RigidBodyPositionOutputVariable(agx::RigidBody *body, agx::UInt component, bool causalityName = false);
227  virtual fmi2Status get(agx::Real& value) override;
228 
229  protected:
231 
232  private:
234  agx::UInt m_component;
235  };
236 
237  class AGXFMI_EXPORT RigidBodyRotationQuatOutputVariable : public OutputVariable_Real
238  {
239  public:
240  RigidBodyRotationQuatOutputVariable(agx::RigidBody *body, agx::UInt component, bool causalityName = false);
241  virtual fmi2Status get(agx::Real& value) override;
242 
243  protected:
245 
246  private:
248  agx::UInt m_component;
249  };
250 
251  class AGXFMI_EXPORT RigidBodyRotationEulerOutputVariable : public OutputVariable_Real
252  {
253  public:
254  RigidBodyRotationEulerOutputVariable(agx::RigidBody *body, agx::UInt component, bool causalityName = false);
255  virtual fmi2Status get(agx::Real& value) override;
256 
257  protected:
259 
260  private:
262  agx::UInt m_component;
263  };
264  }
265 }
266 
267 #endif /* AGXFMI2_RIGIDBODYATTRIBUTEACCESSORS_H */
#define AGXFMI_EXPORT
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define RB_VEC3_INPUT_VARIABLE(NAME, ATTRIBUTE_NAME)
uint32_t UInt
Definition: Integer.h:34
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
#define RB_VEC3_OUTPUT_VARIABLE(NAME, ATTRIBUTE_NAME)
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
This namespace contains functionality for using AGX together with version 2 of the Functional Mockup ...
double Real
Definition: Real.h:42