VR-Engage  2.3
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
27namespace makVrf
28{
29class DtArticulatedPartStateRepository;
30}
31
32class DtArticulatedPart;
33class DtUpdateRepositoryOutputPortGroup;
34
35//! \brief Wheel articulated part IDs used in the system
36//! \details
37//! 7840 Wheel 1 left front
38//! 7872 Wheel 2 right front
39//! 7904 Wheel 3 left etc...
40//! 7936 Wheel 4 right etc...
41//! 7968 Wheel 5
42//! 8000 Wheel 6
43//! 8032 Wheel 7
44//! 8064 Wheel 8
45//! 8096 Wheel 9
46//! 8128 Wheel 10
47//! 8160 Wheel 11
48//! 8192 Wheel 12
49//! 8224 Wheel 13
50//! 8256 Wheel 14
51//! 8288 Wheel 15
52//! 8320 Wheel 16
53//! 8352 Wheel 17
54//! 8384 Wheel 18
55//! 8416 Wheel 19
56//! 8448 Wheel 20
57
58namespace Vx
59{
60class VxPart;
61}
62
63namespace VxData
64{
65class FieldBase;
66}
67
68namespace VxSim
69{
70class VxExtension;
71class VxPluginExtension;
72class VxVHLInterface;
73class VxSimulationState;
74} // namespace VxSim
75
76namespace VxDynamics
77{
78class Part;
79}
80
81//! \brief Base class for Vortex parts in the physics simulation
82//!
83//! Provides common functionality for different types of parts including position,
84//! orientation, and motion tracking. Derived classes implement specific behaviors
85//! for different part types such as wheels and turrets.
87{
88public:
89 //! \brief Enumeration defining possible part motion types
90 //!
91 //! These flags can be combined to define which degrees of freedom
92 //! a part supports.
94 {
95 X = 0x01, //!< Motion along X axis
96 Y = 0x02, //!< Motion along Y axis
97 Z = 0x04, //!< Motion along Z axis
98 TRANSLATION = X | Y | Z, //!< All translational motion
99 AZIMUTH = 0x10, //!< Rotation around Z axis
100 ELEVATION = 0x20, //!< Rotation around Y axis
101 ROTATION = 0x40, //!< Rotation around X axis
102 ORIENTATION = AZIMUTH | ELEVATION | ROTATION //!< All rotational motion
103 };
104
105public:
106 //! \brief Constructor
107 //!
108 //! Creates a part with the specified descriptor and parent.
109 //!
110 //! \param desc The part descriptor containing configuration
111 //! \param parent The parent part, or nullptr for root parts
113
114 //! \brief Virtual destructor
116
117 //! \brief Gets the parameter IDs associated with this part
118 //!
119 //! \return Vector of parameter IDs
120 virtual const std::vector<int>& paramIds() const { return myParamterIds; }
121
122 //! \brief Initializes the part
123 //!
124 //! Sets up the part and its connections to the physics engine.
125 //!
126 //! \return True if initialization succeeded, false otherwise
127 virtual bool init() = 0;
128
129 //! \brief Updates the part state
130 //!
131 //! Called every frame by the movement actuator. Takes data from Vortex
132 //! and produces values translated for publishing.
133 virtual void update() = 0;
134
135 //! \brief Gets the local transform in Vortex coordinates
136 //!
137 //! \return Local transform in NWU coordinates
138 virtual Vx::VxTransform transform() const = 0;
139
140 //! \brief Gets the world transform in Vortex coordinates
141 //!
142 //! \return World transform in NWU coordinates
143 virtual Vx::VxTransform worldTransform() const = 0;
144
145 //! \brief Resets the initial part positions
146 //!
147 //! Derived classes may implement this to reset specific part positions.
149
150 //! \brief Resets the part to its initial state in Vortex
151 virtual void reset();
152
153 //! \brief Gets the parent part
154 //!
155 //! \return Reference to the parent part
156 virtual DtVortexBasePart& parent() const;
157
158 //! \brief Checks if this part has the specified motion capability
159 //!
160 //! \param motion The motion type to check (from DtPartMotion enum)
161 //! \return True if this part is configured with the specified motion
162 virtual bool hasMotion(DtPartMotion motion) const;
163
164 //! \brief Gets the part ID
165 //!
166 //! Gets this part's articulated part ID (see disEnums.h).
167 //!
168 //! \return The part ID
169 virtual inline int partId() const { return myPartId; }
170
171 //! \brief Gets the parent part ID
172 //!
173 //! \return The parent part ID
174 virtual inline int parentId() const { return myParentId; }
175
176 //! \brief Gets the position in NED coordinate system
177 //!
178 //! Returns the position in the articulated part standard coordinate system.
179 //!
180 //! \return Current part position
181 virtual inline DtVector position() const { return myPosition; }
182
183 //! \brief Gets the current velocity
184 //!
185 //! \return Current velocity vector
186 virtual inline DtVector velocity() const { return myVelocity; }
187
188 //! \brief Gets the current acceleration
189 //!
190 //! \return Current acceleration vector
191 virtual inline DtVector acceleration() const { return myAcceleration; }
192
193 //! \brief Gets the current orientation
194 //!
195 //! \return Current orientation as Tait-Bryan angles
196 virtual inline DtTaitBryan orientation() const { return myOrientation; }
197
198 //! \brief Gets the current angular velocity
199 //!
200 //! \return Current angular velocity vector
201 virtual inline DtVector angularVelocity() const { return myAngularVelocity; }
202
203 //! \brief Gets the part name
204 //!
205 //! Returns the name of this part as defined in the descriptor.
206 //!
207 //! \return Part name
208 virtual inline const std::string& name() const { return myName; }
209
210protected:
211 std::string myName; //!< Part name
212 DtVortexBasePart* myParent; //!< Parent part
214
215 int myParentId; //!< Parent part ID
216 int myPartId; //!< This part's ID
217
218 int myMotion; //!< Supported motion types (bitmask)
219
220 std::vector<int> myParamterIds; //!< Parameter IDs for this part
221
222 DtVector myPosition; //!< Current position
223 DtVector myVelocity; //!< Current velocity
224 DtVector myAcceleration; //!< Current acceleration
225
226 DtTaitBryan myOrientation; //!< Current orientation
227 DtVector myAngularVelocity; //!< Current angular velocity
228};
229
230//---------------------------------------------------------------------------------------------------------------------
231
232//! \brief Standard Vortex part implementation
233//!
234//! Used primarily for the chassis, turret, and main gun parts.
235//! Wraps a Vortex physics part and provides access to its properties.
237{
238public:
239 //! \brief Constructor
240 //!
241 //! \param part Pointer to the Vortex part
242 //! \param desc Part descriptor
243 //! \param parent Pointer to the parent part
245
246 //! \brief Destructor
247 virtual ~DtVortexPart() override;
248
249 //! \brief Initializes the part
250 //!
251 //! \return True if initialization succeeded, false otherwise
252 virtual bool init() override;
253
254 //! \brief Updates the part state from Vortex
255 virtual void update() override;
256
257 //! \brief Gets the local transform
258 //!
259 //! \return Local transform in Vortex coordinates
260 virtual Vx::VxTransform transform() const override;
261
262 //! \brief Gets the world transform
263 //!
264 //! \return World transform in Vortex coordinates
265 virtual Vx::VxTransform worldTransform() const override;
266
267 //! \brief Resets the initial part positions
268 virtual void resetInitialPartPositions() override;
269
270 //! \brief Resets the part to its initial state
271 virtual void reset() override;
272
273 //! \brief Gets the underlying Vortex part
274 //!
275 //! \return Pointer to the Vortex part
276 virtual Vx::VxPart* getPart();
277
278protected:
279 //! \brief Calculates the current position
280 //!
281 //! \return Current position vector
283
284 //! \brief Calculates the current orientation
285 //!
286 //! \return Current orientation as Tait-Bryan angles
287 DtTaitBryan calculateOrientation();
288
289 //! \brief Calculates the current linear velocity
290 //!
291 //! \return Current velocity vector
293
294 //! \brief Calculates the current angular velocity
295 //!
296 //! \return Current angular velocity vector
298
299 //! \brief Calculates the current acceleration
300 //!
301 //! \return Current acceleration vector
303
304 Vx::VxPart* myPart; //!< The Vortex physics part
305};
306
307//---------------------------------------------------------------------------------------------------------------------
308
309//! \brief Dynamics-based Vortex part implementation
310//!
311//! Used for parts that rely on the Vortex dynamics extension,
312//! such as wheels and tracks.
314{
315public:
316 //! \brief Enumerates the type of dynamics part
317 //!
318 //! Identifies the role of a part within the vehicle dynamics system,
319 //! enabling type-specific position updates and physics calculations.
321 {
322 UNKNOWN_TYPE = -1, //!< Unknown or uninitialized part type
323 WHEEL = 0, //!< Standard car wheel
324 TRACK_WHEEL = 1, //!< Wheel on a tracked vehicle (position relative to sprocket)
325 IDLER = 2, //!< Track idler wheel at the rear of a tracked vehicle
326 SPROCKET = 3, //!< Drive sprocket at the front of a tracked vehicle
327 };
328
329 //! \brief Enumerates the side of the vehicle the part is on
330 //!
331 //! Used to determine which track system (left or right) a part belongs to
332 //! for proper position updates on tracked vehicles.
334 {
335 UNKNOWN_SIDE = -1, //!< Unknown or uninitialized side
336 LEFT = 0, //!< Part is on the left side of the vehicle
337 RIGHT = 1, //!< Part is on the right side of the vehicle
338 };
339
340public:
341 //! \brief Constructor
342 //!
343 //! \param dynamicsExt The Vortex dynamics extension
344 //! \param desc Part descriptor
345 //! \param parent Pointer to the parent part
346 DtVortexDynamicsPart(Vx::VxWeakPtr<VxSim::VxExtension> dynamicsExt,
349
350 //! \brief Destructor
351 virtual ~DtVortexDynamicsPart() override;
352
353 //! \brief Initializes the part
354 //!
355 //! \return True if initialization succeeded, false otherwise
356 virtual bool init() override;
357
358 //! \brief Updates the part state from Vortex
359 virtual void update() override;
360
361 //! \brief Gets the local transform
362 //!
363 //! \return Local transform in Vortex coordinates
364 virtual Vx::VxTransform transform() const override;
365
366 //! \brief Gets the world transform
367 //!
368 //! \return World transform in Vortex coordinates
369 virtual Vx::VxTransform worldTransform() const override;
370
371 //! \brief Gets the wheel radius
372 //!
373 //! \return Wheel radius in meters
374 double wheelRadius() const;
375
376 //! \brief Gets the wheel width
377 //!
378 //! \return Wheel width in meters
379 double wheelWidth() const;
380
381 //! \brief Gets the rest position of the part
382 //!
383 //! \return Rest position vector in Vortex coordinates
384 VxMath::Vector3 restPosition() const;
385
386 //! \brief Resets the initial part positions
387 virtual void resetInitialPartPositions() override;
388
389 //! \brief Resets the part to its initial state
390 //!
391 //! See DtVortexBasePart::reset()
392 virtual void reset() override;
393
394 //! \brief Gets the type of this dynamics part
395 //!
396 //! \return The PartType indicating whether this is a wheel, track wheel, idler, or sprocket
397 //! \see PartType
399
400 //! \brief Gets the side of the vehicle this part is on
401 //!
402 //! \return The PartSide indicating left, right, or unknown side
403 //! \see PartSide
405
406 //! \brief Gets the wheel index for track wheels
407 //!
408 //! For TRACK_WHEEL parts, returns the index of the wheel within the track system.
409 //! This index is parsed from the part name and is used to locate the correct
410 //! wheel position field in the Vortex dynamics parameters.
411 //!
412 //! \return The wheel index (0-based), or -1 if not a track wheel
413 inline int getWheelId() const { return myWheelId; }
414
415protected:
416 //! \brief Initializes a car wheel
417 //!
418 //! \return True if initialization succeeded, false otherwise
419 virtual bool initializeCarWheel();
420
421 //! \brief Initializes a track sprocket
422 //!
423 //! \return True if initialization succeeded, false otherwise
425
426 //! \brief Initializes a track idler
427 //!
428 //! \return True if initialization succeeded, false otherwise
429 virtual bool initializeTrackIdler();
430
431 //! \brief Initializes a track wheel
432 //!
433 //! \return True if initialization succeeded, false otherwise
434 virtual bool initializeTrackWheel();
435
436 double myDynamicWheelRadius; //!< Wheel radius for dynamics calculations
437 double myDynamicWheelWidth; //!< Wheel width for dynamics calculations
438 Vx::VxTransform myDOFTransform; //!< Degree of freedom transform
439 Vx::VxWeakPtr<VxSim::VxExtension> myDynamicsExt; //!< The dynamics extension
440 VxData::FieldBase* myDynamicsTransform; //!< The dynamics transform field
441 VxData::FieldBase* myDynamicsContactMaterial; //!< The dynamics contact material field
442
443 PartType myDynamicPartType; //!< The type of dynamics part (wheel, track wheel, idler, sprocket)
444 PartSide myDynamicPartSide; //!< The side of the vehicle this part is on (left, right)
445 int myWheelId; //!< The wheel index for track wheels, -1 otherwise
446};
447
448//---------------------------------------------------------------------------------------------------------------------
449
450//! \brief Modular vehicle part implementation
451//!
452//! Used for parts in modular vehicles where parts connect to a base chassis.
454{
455public:
456 //! \brief Constructor
457 //!
458 //! \param part The Vortex dynamics part interface
459 //! \param desc Part descriptor
460 //! \param parent Pointer to the parent part
461 DtVortexModularPart(VxSim::VxWeakInterface<VxDynamics::Part> part,
464
465 //! \brief Destructor
466 virtual ~DtVortexModularPart() override;
467
468 //! \brief Initializes the part
469 //!
470 //! \return True if initialization succeeded, false otherwise
471 virtual bool init() override;
472
473 //! \brief Updates the part state from Vortex
474 virtual void update() override;
475
476 //! \brief Resets the part to its initial state
477 virtual void reset() override;
478
479 //! \brief Checks if the parent transform is valid
480 //!
481 //! Needed because modular vehicles do not update their parts until the simulation starts.
482 //!
483 //! \return True if the parent transform is valid, false otherwise
485
486 //! \brief Updates the parent transform
487 virtual void updateParentTransform();
488
489 //! \brief Gets the local transform
490 //!
491 //! \return Local transform in Vortex coordinates
492 virtual Vx::VxTransform transform() const override;
493
494 //! \brief Gets the world transform
495 //!
496 //! \return World transform in Vortex coordinates
497 virtual Vx::VxTransform worldTransform() const override;
498
499 //! \brief Get an interface containing the part
500 //!
501 //! \return VxSmartInterface containing the underlying part
502 virtual VxSim::VxSmartInterface<VxDynamics::Part> getPartInterface();
503
504protected:
505 VxSim::VxWeakInterface<VxDynamics::Part> myPart; //!< The Vortex dynamics part
506 Vx::VxTransform myTransformToChassis; //!< Transform from part to chassis
507};
int myMotion
Supported motion types (bitmask)
Definition vortexPart.h:218
std::string myName
Part name.
Definition vortexPart.h:211
DtTaitBryan myOrientation
Current orientation.
Definition vortexPart.h:226
DtVector myPosition
Current position.
Definition vortexPart.h:222
DtVector myAngularVelocity
Current angular velocity.
Definition vortexPart.h:227
virtual void update()=0
Updates the part state.
virtual DtVector velocity() const
Gets the current velocity.
Definition vortexPart.h:186
virtual DtTaitBryan orientation() const
Gets the current orientation.
Definition vortexPart.h:196
virtual const std::string & name() const
Gets the part name.
Definition vortexPart.h:208
int myPartId
This part's ID.
Definition vortexPart.h:216
DtVortexBasePart * myParent
Parent part.
Definition vortexPart.h:212
std::vector< int > myParamterIds
Parameter IDs for this part.
Definition vortexPart.h:220
virtual int parentId() const
Gets the parent part ID.
Definition vortexPart.h:174
virtual DtVector position() const
Gets the position in NED coordinate system.
Definition vortexPart.h:181
makVre::DtVortexSimArtPartDescriptor * myDescriptor
Part descriptor.
Definition vortexPart.h:213
virtual ~DtVortexBasePart()
Virtual destructor.
virtual const std::vector< int > & paramIds() const
Gets the parameter IDs associated with this part.
Definition vortexPart.h:120
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:148
virtual void reset()
Resets the part to its initial state in Vortex.
virtual DtVector angularVelocity() const
Gets the current angular velocity.
Definition vortexPart.h:201
virtual int partId() const
Gets the part ID.
Definition vortexPart.h:169
DtPartMotion
Enumeration defining possible part motion types.
Definition vortexPart.h:94
@ X
Motion along X axis.
Definition vortexPart.h:95
@ Y
Motion along Y axis.
Definition vortexPart.h:96
@ Z
Motion along Z axis.
Definition vortexPart.h:97
@ ORIENTATION
All rotational motion.
Definition vortexPart.h:102
@ ELEVATION
Rotation around Y axis.
Definition vortexPart.h:100
@ TRANSLATION
All translational motion.
Definition vortexPart.h:98
@ AZIMUTH
Rotation around Z axis.
Definition vortexPart.h:99
@ ROTATION
Rotation around X axis.
Definition vortexPart.h:101
virtual DtVector acceleration() const
Gets the current acceleration.
Definition vortexPart.h:191
DtVortexBasePart(makVre::DtVortexSimArtPartDescriptor *desc, DtVortexBasePart *parent)
Constructor.
DtVector myVelocity
Current velocity.
Definition vortexPart.h:223
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:215
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:224
virtual bool init() override
Initializes the part.
VxData::FieldBase * myDynamicsTransform
The dynamics transform field.
Definition vortexPart.h:440
PartType myDynamicPartType
The type of dynamics part (wheel, track wheel, idler, sprocket)
Definition vortexPart.h:443
int getWheelId() const
Gets the wheel index for track wheels.
Definition vortexPart.h:413
virtual bool initializeCarWheel()
Initializes a car wheel.
VxMath::Vector3 restPosition() const
Gets the rest position of the part.
virtual bool initializeTrackSprocket()
Initializes a track sprocket.
PartType getDynamicPartType() const
Gets the type of this dynamics part.
Definition vortexPart.h:398
PartSide getDynamicPartSide() const
Gets the side of the vehicle this part is on.
Definition vortexPart.h:404
int myWheelId
The wheel index for track wheels, -1 otherwise.
Definition vortexPart.h:445
double myDynamicWheelRadius
Wheel radius for dynamics calculations.
Definition vortexPart.h:436
virtual Vx::VxTransform transform() const override
Gets the local transform.
virtual void reset() override
Resets the part to its initial state.
PartSide myDynamicPartSide
The side of the vehicle this part is on (left, right)
Definition vortexPart.h:444
PartSide
Enumerates the side of the vehicle the part is on.
Definition vortexPart.h:334
@ LEFT
Part is on the left side of the vehicle.
Definition vortexPart.h:336
@ UNKNOWN_SIDE
Unknown or uninitialized side.
Definition vortexPart.h:335
@ RIGHT
Part is on the right side of the vehicle.
Definition vortexPart.h:337
virtual Vx::VxTransform worldTransform() const override
Gets the world transform.
PartType
Enumerates the type of dynamics part.
Definition vortexPart.h:321
@ TRACK_WHEEL
Wheel on a tracked vehicle (position relative to sprocket)
Definition vortexPart.h:324
@ UNKNOWN_TYPE
Unknown or uninitialized part type.
Definition vortexPart.h:322
@ WHEEL
Standard car wheel.
Definition vortexPart.h:323
@ IDLER
Track idler wheel at the rear of a tracked vehicle.
Definition vortexPart.h:325
@ SPROCKET
Drive sprocket at the front of a tracked vehicle.
Definition vortexPart.h:326
VxData::FieldBase * myDynamicsContactMaterial
The dynamics contact material field.
Definition vortexPart.h:441
virtual bool initializeTrackIdler()
Initializes a track idler.
virtual void resetInitialPartPositions() override
Resets the initial part positions.
virtual ~DtVortexDynamicsPart() override
Destructor.
double myDynamicWheelWidth
Wheel width for dynamics calculations.
Definition vortexPart.h:437
Vx::VxTransform myDOFTransform
Degree of freedom transform.
Definition vortexPart.h:438
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.
double wheelWidth() const
Gets the wheel width.
double wheelRadius() const
Gets the wheel radius.
Vx::VxWeakPtr< VxSim::VxExtension > myDynamicsExt
The dynamics extension.
Definition vortexPart.h:439
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:506
VxSim::VxWeakInterface< VxDynamics::Part > myPart
The Vortex dynamics part.
Definition vortexPart.h:505
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.
virtual VxSim::VxSmartInterface< VxDynamics::Part > getPartInterface()
Get an interface containing the part.
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:304
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:20
Definition vortexConfiguration.h:29
!
Definition glsVreMessageUtil.h:50
Definition connectorAccessory.h:38