VR-Engage  2.2
Loading...
Searching...
No Matches
vortexPart.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2024 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file vortexPart.h
7//! \brief Classes for representing parts in the Vortex physics simulation
8//! \ingroup vreVrfVortex
9
10#pragma once
11
12#include <vreVrfVortex/export.h>
13
14#include <matrix/vlVector.h>
15#include <matrix/vlTaitBryan.h>
16
17#include <Vx/VxTransform.h>
18#include <Vx/VxSmartPtr.h>
19
20#include <VxSim/VxSmartInterface.h>
21
22namespace makVre
23{
25}
26
27class DtArticulatedPart;
28class DtUpdateRepositoryOutputPortGroup;
29
30//! \brief Wheel articulated part IDs used in the system
31//! \details
32//! 7840 Wheel 1 left front
33//! 7872 Wheel 2 right front
34//! 7904 Wheel 3 left etc...
35//! 7936 Wheel 4 right etc...
36//! 7968 Wheel 5
37//! 8000 Wheel 6
38//! 8032 Wheel 7
39//! 8064 Wheel 8
40//! 8096 Wheel 9
41//! 8128 Wheel 10
42//! 8160 Wheel 11
43//! 8192 Wheel 12
44//! 8224 Wheel 13
45//! 8256 Wheel 14
46//! 8288 Wheel 15
47//! 8320 Wheel 16
48//! 8352 Wheel 17
49//! 8384 Wheel 18
50//! 8416 Wheel 19
51//! 8448 Wheel 20
52
53namespace Vx
54{
55class VxPart;
56}
57
58namespace VxData
59{
60class FieldBase;
61}
62
63namespace VxSim
64{
65class VxExtension;
66class VxPluginExtension;
67class VxVHLInterface;
68class VxSimulationState;
69} // namespace VxSim
70
71namespace VxDynamics
72{
73class Part;
74}
75
76//! \brief Base class for Vortex parts in the physics simulation
77//!
78//! Provides common functionality for different types of parts including position,
79//! orientation, and motion tracking. Derived classes implement specific behaviors
80//! for different part types such as wheels and turrets.
82{
83public:
84 //! \brief Enumeration defining possible part motion types
85 //!
86 //! These flags can be combined to define which degrees of freedom
87 //! a part supports.
89 {
90 X = 0x01, //!< Motion along X axis
91 Y = 0x02, //!< Motion along Y axis
92 Z = 0x04, //!< Motion along Z axis
93 TRANSLATION = X | Y | Z, //!< All translational motion
94 AZIMUTH = 0x10, //!< Rotation around Z axis
95 ELEVATION = 0x20, //!< Rotation around Y axis
96 ROTATION = 0x40, //!< Rotation around X axis
97 ORIENTATION = AZIMUTH | ELEVATION | ROTATION //!< All rotational motion
98 };
99
100public:
101 //! \brief Constructor
102 //!
103 //! Creates a part with the specified descriptor and parent.
104 //!
105 //! \param desc The part descriptor containing configuration
106 //! \param parent The parent part, or nullptr for root parts
108
109 //! \brief Virtual destructor
111
112 //! \brief Gets the parameter IDs associated with this part
113 //!
114 //! \return Vector of parameter IDs
115 virtual const std::vector<int>& paramIds() const { return myParamterIds; }
116
117 //! \brief Initializes the part
118 //!
119 //! Sets up the part and its connections to the physics engine.
120 //!
121 //! \return True if initialization succeeded, false otherwise
122 virtual bool init() = 0;
123
124 //! \brief Updates the part state
125 //!
126 //! Called every frame by the movement actuator. Takes data from Vortex
127 //! and produces values translated for publishing.
128 virtual void update() = 0;
129
130 //! \brief Gets the local transform in Vortex coordinates
131 //!
132 //! \return Local transform in NWU coordinates
133 virtual Vx::VxTransform transform() const = 0;
134
135 //! \brief Gets the world transform in Vortex coordinates
136 //!
137 //! \return World transform in NWU coordinates
138 virtual Vx::VxTransform worldTransform() const = 0;
139
140 //! \brief Resets the initial part positions
141 //!
142 //! Derived classes may implement this to reset specific part positions.
144
145 //! \brief Resets the part to its initial state in Vortex
146 virtual void reset();
147
148 //! \brief Gets the parent part
149 //!
150 //! \return Reference to the parent part
151 virtual DtVortexBasePart& parent() const;
152
153 //! \brief Checks if this part has the specified motion capability
154 //!
155 //! \param motion The motion type to check (from DtPartMotion enum)
156 //! \return True if this part is configured with the specified motion
157 virtual bool hasMotion(DtPartMotion motion) const;
158
159 //! \brief Gets the part ID
160 //!
161 //! Gets this part's articulated part ID (see disEnums.h).
162 //!
163 //! \return The part ID
164 virtual inline int partId() const { return myPartId; }
165
166 //! \brief Gets the parent part ID
167 //!
168 //! \return The parent part ID
169 virtual inline int parentId() const { return myParentId; }
170
171 //! \brief Gets the position in NED coordinate system
172 //!
173 //! Returns the position in the articulated part standard coordinate system.
174 //!
175 //! \return Current part position
176 virtual inline DtVector position() const { return myPosition; }
177
178 //! \brief Gets the current velocity
179 //!
180 //! \return Current velocity vector
181 virtual inline DtVector velocity() const { return myVelocity; }
182
183 //! \brief Gets the current acceleration
184 //!
185 //! \return Current acceleration vector
186 virtual inline DtVector acceleration() const { return myAcceleration; }
187
188 //! \brief Gets the current orientation
189 //!
190 //! \return Current orientation as Tait-Bryan angles
191 virtual inline DtTaitBryan orientation() const { return myOrientation; }
192
193 //! \brief Gets the current angular velocity
194 //!
195 //! \return Current angular velocity vector
196 virtual inline DtVector angularVelocity() const { return myAngularVelocity; }
197
198 //! \brief Gets the part name
199 //!
200 //! Returns the name of this part as defined in the descriptor.
201 //!
202 //! \return Part name
203 virtual inline const std::string& name() const { return myName; }
204
205protected:
206 std::string myName; //!< Part name
207 DtVortexBasePart* myParent; //!< Parent part
209
210 int myParentId; //!< Parent part ID
211 int myPartId; //!< This part's ID
212
213 int myMotion; //!< Supported motion types (bitmask)
214
215 std::vector<int> myParamterIds; //!< Parameter IDs for this part
216
217 DtVector myPosition; //!< Current position
218 DtVector myVelocity; //!< Current velocity
219 DtVector myAcceleration; //!< Current acceleration
220
221 DtTaitBryan myOrientation; //!< Current orientation
222 DtVector myAngularVelocity; //!< Current angular velocity
223};
224
225//---------------------------------------------------------------------------------------------------------------------
226
227//! \brief Standard Vortex part implementation
228//!
229//! Used primarily for the chassis, turret, and main gun parts.
230//! Wraps a Vortex physics part and provides access to its properties.
232{
233public:
234 //! \brief Constructor
235 //!
236 //! \param part Pointer to the Vortex part
237 //! \param desc Part descriptor
238 //! \param parent Pointer to the parent part
240
241 //! \brief Destructor
242 virtual ~DtVortexPart() override;
243
244 //! \brief Initializes the part
245 //!
246 //! \return True if initialization succeeded, false otherwise
247 virtual bool init() override;
248
249 //! \brief Updates the part state from Vortex
250 virtual void update() override;
251
252 //! \brief Gets the local transform
253 //!
254 //! \return Local transform in Vortex coordinates
255 virtual Vx::VxTransform transform() const override;
256
257 //! \brief Gets the world transform
258 //!
259 //! \return World transform in Vortex coordinates
260 virtual Vx::VxTransform worldTransform() const override;
261
262 //! \brief Resets the initial part positions
263 virtual void resetInitialPartPositions() override;
264
265 //! \brief Resets the part to its initial state
266 virtual void reset() override;
267
268 //! \brief Gets the underlying Vortex part
269 //!
270 //! \return Pointer to the Vortex part
271 virtual Vx::VxPart* getPart();
272
273protected:
274 //! \brief Calculates the current position
275 //!
276 //! \return Current position vector
278
279 //! \brief Calculates the current orientation
280 //!
281 //! \return Current orientation as Tait-Bryan angles
282 DtTaitBryan calculateOrientation();
283
284 //! \brief Calculates the current linear velocity
285 //!
286 //! \return Current velocity vector
288
289 //! \brief Calculates the current angular velocity
290 //!
291 //! \return Current angular velocity vector
293
294 //! \brief Calculates the current acceleration
295 //!
296 //! \return Current acceleration vector
298
299 Vx::VxPart* myPart; //!< The Vortex physics part
300};
301
302//---------------------------------------------------------------------------------------------------------------------
303
304//! \brief Dynamics-based Vortex part implementation
305//!
306//! Used for parts that rely on the Vortex dynamics extension,
307//! such as wheels and tracks.
309{
310public:
311 //! \brief Constructor
312 //!
313 //! \param dynamicsExt The Vortex dynamics extension
314 //! \param desc Part descriptor
315 //! \param parent Pointer to the parent part
316 DtVortexDynamicsPart(Vx::VxWeakPtr<VxSim::VxExtension> dynamicsExt, makVre::DtVortexSimArtPartDescriptor* desc,
318
319 //! \brief Destructor
320 virtual ~DtVortexDynamicsPart() override;
321
322 //! \brief Initializes the part
323 //!
324 //! \return True if initialization succeeded, false otherwise
325 virtual bool init() override;
326
327 //! \brief Updates the part state from Vortex
328 virtual void update() override;
329
330 //! \brief Gets the local transform
331 //!
332 //! \return Local transform in Vortex coordinates
333 virtual Vx::VxTransform transform() const override;
334
335 //! \brief Gets the world transform
336 //!
337 //! \return World transform in Vortex coordinates
338 virtual Vx::VxTransform worldTransform() const override;
339
340 //! \brief Gets the wheel radius
341 //!
342 //! \return Wheel radius in meters
343 double wheelRadius();
344
345 //! \brief Resets the initial part positions
346 virtual void resetInitialPartPositions() override;
347
348 //! \brief Resets the part to its initial state
349 //!
350 //! See DtVortexBasePart::reset()
351 virtual void reset() override;
352
353protected:
354 //! \brief Initializes a car wheel
355 //!
356 //! \return True if initialization succeeded, false otherwise
357 virtual bool initializeCarWheel();
358
359 //! \brief Initializes a track sprocket
360 //!
361 //! \return True if initialization succeeded, false otherwise
363
364 //! \brief Initializes a track idler
365 //!
366 //! \return True if initialization succeeded, false otherwise
367 virtual bool initializeTrackIdler();
368
369 //! \brief Initializes a track wheel
370 //!
371 //! \return True if initialization succeeded, false otherwise
372 virtual bool initializeTrackWheel();
373
374 double myDynamicWheelRadius; //!< Wheel radius for dynamics calculations
375 Vx::VxTransform myDOFTransform; //!< Degree of freedom transform
376 Vx::VxWeakPtr<VxSim::VxExtension> myDynamicsExt; //!< The dynamics extension
377 VxData::FieldBase* myDynamicsTransform; //!< The dynamics transform field
378 VxData::FieldBase* myDynamicsContactMaterial; //!< The dynamics contact material field
379};
380
381//---------------------------------------------------------------------------------------------------------------------
382
383//! \brief Modular vehicle part implementation
384//!
385//! Used for parts in modular vehicles where parts connect to a base chassis.
387{
388public:
389 //! \brief Constructor
390 //!
391 //! \param part The Vortex dynamics part interface
392 //! \param desc Part descriptor
393 //! \param parent Pointer to the parent part
394 DtVortexModularPart(VxSim::VxWeakInterface<VxDynamics::Part> part, makVre::DtVortexSimArtPartDescriptor* desc,
396
397 //! \brief Destructor
398 virtual ~DtVortexModularPart() override;
399
400 //! \brief Initializes the part
401 //!
402 //! \return True if initialization succeeded, false otherwise
403 virtual bool init() override;
404
405 //! \brief Updates the part state from Vortex
406 virtual void update() override;
407
408 //! \brief Resets the part to its initial state
409 virtual void reset() override;
410
411 //! \brief Checks if the parent transform is valid
412 //!
413 //! Needed because modular vehicles do not update their parts until the simulation starts.
414 //!
415 //! \return True if the parent transform is valid, false otherwise
417
418 //! \brief Updates the parent transform
419 virtual void updateParentTransform();
420
421 //! \brief Gets the local transform
422 //!
423 //! \return Local transform in Vortex coordinates
424 virtual Vx::VxTransform transform() const override;
425
426 //! \brief Gets the world transform
427 //!
428 //! \return World transform in Vortex coordinates
429 virtual Vx::VxTransform worldTransform() const override;
430
431protected:
432 VxSim::VxWeakInterface<VxDynamics::Part> myPart; //!< The Vortex dynamics part
433 Vx::VxTransform myTransformToChassis; //!< Transform from part to chassis
434};
int myMotion
Supported motion types (bitmask)
Definition vortexPart.h:213
std::string myName
Part name.
Definition vortexPart.h:206
DtTaitBryan myOrientation
Current orientation.
Definition vortexPart.h:221
DtVector myPosition
Current position.
Definition vortexPart.h:217
DtVector myAngularVelocity
Current angular velocity.
Definition vortexPart.h:222
virtual void update()=0
Updates the part state.
virtual DtVector velocity() const
Gets the current velocity.
Definition vortexPart.h:181
virtual DtTaitBryan orientation() const
Gets the current orientation.
Definition vortexPart.h:191
virtual const std::string & name() const
Gets the part name.
Definition vortexPart.h:203
int myPartId
This part's ID.
Definition vortexPart.h:211
DtVortexBasePart * myParent
Parent part.
Definition vortexPart.h:207
std::vector< int > myParamterIds
Parameter IDs for this part.
Definition vortexPart.h:215
virtual int parentId() const
Gets the parent part ID.
Definition vortexPart.h:169
virtual DtVector position() const
Gets the position in NED coordinate system.
Definition vortexPart.h:176
makVre::DtVortexSimArtPartDescriptor * myDescriptor
Part descriptor.
Definition vortexPart.h:208
virtual ~DtVortexBasePart()
Virtual destructor.
virtual const std::vector< int > & paramIds() const
Gets the parameter IDs associated with this part.
Definition vortexPart.h:115
virtual bool hasMotion(DtPartMotion motion) const
Checks if this part has the specified motion capability.
virtual void resetInitialPartPositions()
Resets the initial part positions.
Definition vortexPart.h:143
virtual void reset()
Resets the part to its initial state in Vortex.
virtual DtVector angularVelocity() const
Gets the current angular velocity.
Definition vortexPart.h:196
virtual int partId() const
Gets the part ID.
Definition vortexPart.h:164
DtPartMotion
Enumeration defining possible part motion types.
Definition vortexPart.h:89
@ X
Motion along X axis.
Definition vortexPart.h:90
@ Y
Motion along Y axis.
Definition vortexPart.h:91
@ Z
Motion along Z axis.
Definition vortexPart.h:92
@ ORIENTATION
All rotational motion.
Definition vortexPart.h:97
@ ELEVATION
Rotation around Y axis.
Definition vortexPart.h:95
@ TRANSLATION
All translational motion.
Definition vortexPart.h:93
@ AZIMUTH
Rotation around Z axis.
Definition vortexPart.h:94
@ ROTATION
Rotation around X axis.
Definition vortexPart.h:96
virtual DtVector acceleration() const
Gets the current acceleration.
Definition vortexPart.h:186
DtVortexBasePart(makVre::DtVortexSimArtPartDescriptor *desc, DtVortexBasePart *parent)
Constructor.
DtVector myVelocity
Current velocity.
Definition vortexPart.h:218
virtual Vx::VxTransform transform() const =0
Gets the local transform in Vortex coordinates.
virtual DtVortexBasePart & parent() const
Gets the parent part.
int myParentId
Parent part ID.
Definition vortexPart.h:210
virtual bool init()=0
Initializes the part.
virtual Vx::VxTransform worldTransform() const =0
Gets the world transform in Vortex coordinates.
DtVector myAcceleration
Current acceleration.
Definition vortexPart.h:219
virtual bool init() override
Initializes the part.
VxData::FieldBase * myDynamicsTransform
The dynamics transform field.
Definition vortexPart.h:377
virtual bool initializeCarWheel()
Initializes a car wheel.
virtual bool initializeTrackSprocket()
Initializes a track sprocket.
double myDynamicWheelRadius
Wheel radius for dynamics calculations.
Definition vortexPart.h:374
virtual Vx::VxTransform transform() const override
Gets the local transform.
double wheelRadius()
Gets the wheel radius.
virtual void reset() override
Resets the part to its initial state.
virtual Vx::VxTransform worldTransform() const override
Gets the world transform.
VxData::FieldBase * myDynamicsContactMaterial
The dynamics contact material field.
Definition vortexPart.h:378
virtual bool initializeTrackIdler()
Initializes a track idler.
virtual void resetInitialPartPositions() override
Resets the initial part positions.
virtual ~DtVortexDynamicsPart() override
Destructor.
Vx::VxTransform myDOFTransform
Degree of freedom transform.
Definition vortexPart.h:375
virtual void update() override
Updates the part state from Vortex.
DtVortexDynamicsPart(Vx::VxWeakPtr< VxSim::VxExtension > dynamicsExt, makVre::DtVortexSimArtPartDescriptor *desc, DtVortexBasePart *parent)
Constructor.
virtual bool initializeTrackWheel()
Initializes a track wheel.
Vx::VxWeakPtr< VxSim::VxExtension > myDynamicsExt
The dynamics extension.
Definition vortexPart.h:376
virtual void reset() override
Resets the part to its initial state.
DtVortexModularPart(VxSim::VxWeakInterface< VxDynamics::Part > part, makVre::DtVortexSimArtPartDescriptor *desc, DtVortexBasePart *parent)
Constructor.
Vx::VxTransform myTransformToChassis
Transform from part to chassis.
Definition vortexPart.h:433
VxSim::VxWeakInterface< VxDynamics::Part > myPart
The Vortex dynamics part.
Definition vortexPart.h:432
virtual void updateParentTransform()
Updates the parent transform.
virtual bool init() override
Initializes the part.
virtual void update() override
Updates the part state from Vortex.
virtual ~DtVortexModularPart() override
Destructor.
virtual Vx::VxTransform transform() const override
Gets the local transform.
virtual bool isParentTransformValid()
Checks if the parent transform is valid.
virtual Vx::VxTransform worldTransform() const override
Gets the world transform.
DtVector calculateLinearVelocity()
Calculates the current linear velocity.
DtVector calculateAngularVelocity()
Calculates the current angular velocity.
virtual ~DtVortexPart() override
Destructor.
Vx::VxPart * myPart
The Vortex physics part.
Definition vortexPart.h:299
virtual Vx::VxTransform worldTransform() const override
Gets the world transform.
virtual Vx::VxTransform transform() const override
Gets the local transform.
DtVector calculateAccleration()
Calculates the current acceleration.
virtual Vx::VxPart * getPart()
Gets the underlying Vortex part.
DtVector calculatePosition()
Calculates the current position.
virtual void reset() override
Resets the part to its initial state.
DtTaitBryan calculateOrientation()
Calculates the current orientation.
virtual bool init() override
Initializes the part.
virtual void resetInitialPartPositions() override
Resets the initial part positions.
DtVortexPart(Vx::VxPart *part, makVre::DtVortexSimArtPartDescriptor *desc, DtVortexBasePart *parent)
Constructor.
virtual void update() override
Updates the part state from Vortex.
Articulated part descriptor for Vortex physics simulation.
Definition vortexArtPartDescriptor.h:27
Export macros for the VR-Forces Vortex extension library.
#define VREVRFVORTEX_DLL
Export macro for non-Windows platforms.
Definition export.h:30
Definition vortexConfiguration.h:24
Definition vortexIntegrationModule.h:28
Wheel articulated part IDs used in the system.
Definition surfaceToVxMaterialMapper.h:17
Definition vortexConfiguration.h:29
Include export definitions for this library.
Definition glsVreMessageUtil.h:49