AGX Dynamics 2.42.3.1
Loading...
Searching...
No Matches
agxVehicle/Track.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#pragma once
18
26
27#include <agxCollide/Geometry.h>
28
30
31namespace agxVehicle
32{
35
40 {
41 public:
47 using OnNodeInitializeCallback = std::function<void( const TrackNode& )>;
49
50 public:
55 static Track* get( agx::RigidBody* rb );
56
61 static const Track* get( const agx::RigidBody* rb );
62
67 static Track* get( Wheel* wheel );
68
73 static const Track* get( const Wheel* wheel );
74
81 static Track* find( agxSDK::Simulation* simulation, const agx::Name& name );
82
89 static Track* find( agxSDK::Simulation* simulation, const agx::Uuid& uuid );
90
97
104 static TrackPtrVector findAll( agxSDK::Simulation* simulation, const agx::Name& name );
105
106 public:
120 Track( agx::RigidBody* referenceRigidBody,
121 agx::UInt numberOfNodes,
122 agx::Real width,
123 agx::Real thickness,
124 InitialTrackTension initialTension = {} );
125
137 Track( agx::UInt numberOfNodes,
138 agx::Real width,
139 agx::Real thickness,
140 agx::Real initialDistanceTension = agx::Real( 0 ) );
141
149 Track( TrackRoute* route, InitialTrackTension initialTension );
150
157 agx::Bool add( TrackWheelRef wheel, bool addToAssembly = true);
158
165
169#ifndef SWIG // for the work-around until SWIG upgrade to work
171#endif
172
182
190
195
202
207
215
220
224#ifndef SWIG // for the work-around until SWIG upgrade to work
226
230 NodeRange nodes( IndexRange range ) const;
231#endif
232
236 TrackWheel* getWheel( const agx::RigidBody* rb ) const;
237
241 agx::UInt getNumNodes() const;
242
246 TrackNode* getNode( agx::UInt index ) const;
247
252 template<typename T>
253 TrackNode* getNode( const T* obj ) const;
254
261 TrackNode* findNode( const agx::Vec3& worldPoint ) const;
262
266 agx::UInt getNodeIndex( const agx::RigidBody* rb ) const;
267
271 Iterator getIterator( agx::UInt index ) const;
272
277 template<typename T>
278 Iterator getIterator( const T* obj ) const;
279
284
289
294 void setProperties( TrackProperties* properties );
295
303
307 agx::Real getTension( const TrackNode& node ) const;
308
312 const InitialTrackTension& getInitialTension( ) const;
313
317 InitialTrackTension& getInitialTension( );
318
319#ifndef SWIG
327
334#endif
335
351 bool setEnableFullDegreeModel( bool enable );
352
357
363
364 public:
365#ifndef SWIG
377 virtual agx::Bool initialize( OnNodeInitializeCallback onInitializeCallback );
378#endif
379
391 virtual agx::Bool initialize( TrackNodeOnInitializeCallback* onInitializeCallback = nullptr );
392
396 bool isInitialized() const;
397
399
400
403 TrackImplementation* getTrackImplementation() const;
404
411 void setTrackImplementation( TrackImplementation* implementation, bool active = true );
412
426 virtual agx::Bool reinitialize( agx::UInt numberOfNodes,
427 agx::Real width,
428 agx::Real thickness,
429 agx::Real initialDistanceTension = agx::Real( 0 ) );
430
436 void registerAsImplementationObject( agx::RigidBody* rb ) const;
437
439
440 public:
442
443 virtual bool onContact( agxCollide::GeometryContact* gc );
444
445 void onPostContact( agxCollide::GeometryContact* geometryContact );
446
447 protected:
448 enum StateEnum : agx::UInt32
449 {
450 INITIALIZED = 1 << 0, // After add notification and route successfully initialized.
451 ACTIVE_TRACK_IMPLEMENTATION = 1 << 1 // Track implementation is assigned and active.
452 };
453 using State = agx::BitState<StateEnum, agx::UInt32>;
454
455 protected:
457 virtual ~Track();
458
459 virtual void onAddNotification( agxSDK::Simulation* simulation ) override;
460 virtual void onRemoveNotification( agxSDK::Simulation* simulation ) override;
461 virtual void onMaterialNew() override;
462 virtual void onGroupAdd( const agxSDK::LinkedStructure::IdData& group ) override;
463 virtual void onGroupRemove( const agxSDK::LinkedStructure::IdData& group ) override;
464 virtual void onSetEnableCollisions( agxCollide::Geometry* geometry, agx::Bool enable ) override;
465 virtual void onPreCollideStep() override;
466 virtual void onPreStep() override;
467 virtual void onPostStep() override;
468 virtual void onLastStep() override;
469 virtual void onPostIntegrate() override;
470
471 private:
472 struct ContactData
473 {
475 using WheelNodeContacts = agx::HashTable<const TrackWheel*, NodeContacts>;
476
477 ContactData()
478 : wheelNodeContacts{}
479 , nodeContacts{}
480 , otherContacts()
481 {
482 }
483
484 WheelNodeContacts wheelNodeContacts;
485 NodeContacts nodeContacts;
486 GeometryContactContainer otherContacts;
487 };
488
489 struct TrackNodeTriplet
490 {
491 agx::Bool isValid() const { return prev != nullptr && node != nullptr && next != nullptr; }
492
493 TrackNode* prev;
494 TrackNode* node;
495 TrackNode* next;
496
498 agx::UInt nodeIndex;
500 };
501
502 private:
503 TrackNodeTriplet findTrackNodeTriplet( agx::UInt nodeIndex ) const;
504 TrackNodeTriplet findTrackNodeTriplet( const agx::RigidBody* nodeRb ) const;
505
506 void onPreStepMergeNodes( TrackWheel& wheel, const ContactData::NodeContacts* contacts, agx::UIntVector& mergedNodeIndices );
507 void onPreStepHandleNonMergedNodes( TrackWheel& wheel, agx::UIntVector& mergedNodeIndices );
508 void onPreStepSplitWheelMergedNodes( TrackWheel& wheel, agx::UIntVector& mergedNodeIndices );
509 void onPreInternalMergeNodes( const TrackInternalMergeProperties& properties );
510
511 void addAndConstrain( TrackNodeRef node, TrackNodeRef prev );
512 void constrain( TrackNode& curr, TrackNode& prev );
513 void merge( TrackWheel& wheel, TrackNode& node );
514 void merge( TrackNode& node1, TrackNode& node2, agx::MergedBody& mergedBody );
515 agx::Bool split( TrackNode& node );
516 void transformToWheel( TrackNode& node, const TrackWheel& wheel ) const;
517
518 private:
519 TrackWheelContainer m_wheels;
520 RigidBodyTrackWheelTable m_rbWheelTable;
521 TrackRouteRef m_route;
522 ContactData m_contactData;
523 State m_state;
524 TrackInternalMergeProperties m_internalMergeProperties;
525 TrackPropertiesRef m_properties;
526 TrackImplementationRef m_trackImplementation;
527 InitialTrackTension m_initialTension;
528 agx::UInt32 m_supportGroupId;
529 bool m_enableCollisionsWithSupport;
530 };
531
533 {
534 return LinkedStructure::getT<Track>( rb );
535 }
536
537 inline const Track* Track::get( const agx::RigidBody* rb )
538 {
539 return LinkedStructure::getT<Track>( rb );
540 }
541
542 inline Track::TrackNodeTriplet Track::findTrackNodeTriplet( agx::UInt nodeIndex ) const
543 {
544 if ( nodeIndex == agx::InvalidIndex )
545 return { nullptr, nullptr, nullptr, agx::InvalidIndex, agx::InvalidIndex, agx::InvalidIndex };
546
547 Iterator nodeIt = getIterator( nodeIndex );
548 agxAssert( nodeIt.index() < getNumNodes() );
549 Iterator prevIt = nodeIt - 1ul;
550 Iterator nextIt = nodeIt + 1ul;
551 return
552 {
553 *prevIt, *nodeIt, *nextIt,
554 prevIt.index(), nodeIt.index(), nextIt.index()
555 };
556 }
557
558 inline Track::TrackNodeTriplet Track::findTrackNodeTriplet( const agx::RigidBody* nodeRb ) const
559 {
560 return findTrackNodeTriplet( getNodeIndex( nodeRb ) );
561 }
562
563 inline TrackWheel* Track::getWheel( const agx::RigidBody* rb ) const
564 {
565 return m_rbWheelTable.get_or_return_default( rb );
566 }
567
569 {
570 return getNumSegments();
571 }
572
573 inline TrackNode* Track::getNode( agx::UInt index ) const
574 {
575 return getSegment( index )->as<TrackNode>();
576 }
577
578 template<>
579 inline TrackNode* Track::getNode( const agx::RigidBody* obj ) const
580 {
581 auto node = LinkedStructure::getSegment( obj );
582 return node != nullptr ? node->as<TrackNode>() : nullptr;
583 }
584
586 {
587 return LinkedStructure::getSegmentIndex( rb );
588 }
589
591 {
592 return LinkedStructure::getSegmentIterator<TrackNode>( index, true );
593 }
594
595 template<>
597 {
598 return LinkedStructure::getSegmentIterator<TrackNode>( obj, true );
599 }
600
601 template<>
603 {
604 if ( obj == nullptr )
606 return getIterator( obj->getRigidBody() );
607 }
608
610 {
611 return m_initialTension;
612 }
613
615 {
616 return m_initialTension;
617 }
618}
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
Definition: Serializable.h:207
#define AGXVEHICLE_EXPORT
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
Optionally unbounded linked structure segment iterator object to iterate segments in a SegmentStructu...
static LinkedSegmentIterator end(const agxSDK::LinkedSegmentContainer &segments)
Segment range object for linked structure.
agx::RigidBody * getRigidBody() const
Basic implementation of any structure where bodies are linked/constrained together in a well defined ...
const agxSDK::LinkedSegmentContainer & getSegmentsContainer() const
LinkedSegment * getSegment(agx::UInt index) const
agx::UInt getNumSegments() const
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:131
Base class for a custom track implementation.
Properties and thresholds for internal merging of nodes in agxVehicle::Track.
Track node initialize callback, called when a track node has been created and is about to be added to...
Node/segment/shoe object in agxVehicle::Track.
Definition: TrackNode.h:47
Object containing properties of an agxVehicle::Track.
Track route object to initialize tracks.
Definition: TrackRoute.h:89
Wheel used in tracked vehicles.
Definition: TrackWheel.h:32
Assembly object representing a continuous track with a given number of shoes (nodes).
TrackWheel * findReferenceWheel() const
Reference wheel's rotation axis is defining the plane in which this track will be created.
NodeRange nodes() const
agx::UInt32Vector onPreGetNodesWheelContacts(const TrackWheel *wheel) const
Node indices in contact with the given wheel.
agx::Bool remove(TrackWheelRef wheel)
Remove track wheel.
bool isInitialized() const
const GeometryContactContainer & onPreGetNodeOtherContacts(const TrackNode *node) const
Collected contacts of node vs.
agx::UInt getNumNodes() const
virtual void onPreStep() override
Called on simulation pre step event - after user preStep.
TrackInternalMergeProperties * getInternalMergeProperties() const
const GeometryContactContainer & onPreGetOtherContacts() const
Collected contacts that matches Track::get(rb) == this but isn't nodes vs.
TrackProperties * getProperties() const
virtual void onSetEnableCollisions(agxCollide::Geometry *geometry, agx::Bool enable) override
Called when collision state changed for given geometry.
TrackNode * findNode(const agx::Vec3 &worldPoint) const
Find the node closest to the given world point.
virtual agx::Bool initialize(TrackNodeOnInitializeCallback *onInitializeCallback=nullptr)
Initialize this track given already assigned route, added wheels, number of nodes and an initialize n...
virtual void onPostStep() override
Called on simulation post step event - after user postStep.
agx::UInt getNodeIndex(const agx::RigidBody *rb) const
bool getEnableFullDegreeModel() const
static const Track * get(const Wheel *wheel)
agx::UInt32 getSupportGroupId() const
static Track * find(agxSDK::Simulation *simulation, const agx::Uuid &uuid)
Find track instance given simulation and unique id.
static Track * find(agxSDK::Simulation *simulation, const agx::Name &name)
Find track instance given simulation and name.
Track(agx::UInt numberOfNodes, agx::Real width, agx::Real thickness, agx::Real initialDistanceTension=agx::Real(0))
Construct track given number of nodes, size and initial tension distance.
virtual void onGroupRemove(const agxSDK::LinkedStructure::IdData &group) override
Called when an existing group has been removed.
TrackNodeIterator Iterator
static TrackPtrVector findAll(agxSDK::Simulation *simulation)
Finds all agxVehicle::Track instances in the given simulation.
virtual void onGroupAdd(const agxSDK::LinkedStructure::IdData &group) override
Called when a new group has been added.
virtual void onAddNotification(agxSDK::Simulation *simulation) override
Called when addNotification is executed when this linked structure is added to the simulation.
Track(TrackRoute *route, InitialTrackTension initialTension)
Construct given a track route.
bool getEnableCollisionsWithSupport() const
Track(agx::RigidBody *referenceRigidBody, agx::UInt numberOfNodes, agx::Real width, agx::Real thickness, InitialTrackTension initialTension={})
Construct track given number of nodes, size and initial tension.
virtual void onMaterialNew() override
Called when a new material has been assigned.
virtual void onLastStep() override
Called on simulation last step event - after user lastStep.
Iterator getIterator(const T *obj) const
agx::Real getTension(const TrackNode &node) const
agx::Bool add(TrackWheelRef wheel, bool addToAssembly=true)
Add track wheel to this track before this track has been initialized.
std::function< void(const TrackNode &)> OnNodeInitializeCallback
TrackWheel * getWheel(const agx::RigidBody *rb) const
Iterator getIterator(agx::UInt index) const
agx::Bool removeSupportGroupId(agxCollide::Geometry *geometry) const
Remove this track's support group id from geometry.
TrackNode * getNode(agx::UInt index) const
static Track * get(agx::RigidBody *rb)
NodeRange nodes(IndexRange range) const
const Track::TrackWheelContainer & getWheels() const
TrackRoute * getRoute() const
virtual void onRemoveNotification(agxSDK::Simulation *simulation) override
Called when removeNotification is executed when this linked structure is removed from the simulation.
const InitialTrackTension & getInitialTension() const
agx::RigidBody * getReferenceRigidBody() const
virtual agx::Bool initialize(OnNodeInitializeCallback onInitializeCallback)
Initialize this track given already assigned route, added wheels, number of nodes and an initialize n...
static TrackPtrVector findAll(agxSDK::Simulation *simulation, const agx::Name &name)
Finds all track instances given simulation and name.
void setEnableCollisionsWithSupport(bool enable)
Enable/disable collisions between this track and geometries carrying this track's support group id.
static Track * get(Wheel *wheel)
agx::BitState< StateEnum, agx::UInt32 > State
agx::Bool addSupportGroupId(agxCollide::Geometry *geometry) const
Add this track's support group id to geometry.
virtual void onPostIntegrate() override
Called on simulation post integrate event - when transforms has been updated given current velocities...
virtual void onPreCollideStep() override
Called on simulation pre-collide step event - after user preCollide.
bool setEnableFullDegreeModel(bool enable)
Activates or deactivates the full degrees-of-freedom track model.
void setProperties(TrackProperties *properties)
Assign properties to this track.
TrackNode * getNode(const T *obj) const
Abstraction of a wheel of arbitrary geometry.
Definition: Wheel.h:43
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: HashVector.h:41
const ValueT get_or_return_default(const KeyT &k) const
Inheritance with partial specialization due to bug with ref_ptr containers.
Structure holding several "normal" rigid bodies.
Definition: MergedBody.h:55
Representation of a name string.
Definition: Name.h:33
T * as()
Subclass casting.
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:49
A UUID, or Universally unique identifier, is intended to uniquely identify information in a distribut...
Definition: Uuid.h:42
Vector containing 'raw' data.
Definition: agx/Vector.h:246
#define agxAssert(expr)
Definition: debug.h:143
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:89
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:88
This namespace consists of a set of classes for handling geometric intersection tests including boole...
T nextIndex(T index, T size)
Definition: TrackUtils.h:122
T prevIndex(T index, T size)
Definition: TrackUtils.h:112
This namespace contains classes related to vehicles dynamics.
agx::ref_ptr< TrackRoute > TrackRouteRef
Definition: TrackRoute.h:29
agx::ref_ptr< TrackProperties > TrackPropertiesRef
agx::ref_ptr< TrackImplementation > TrackImplementationRef
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint32_t UInt32
Definition: Integer.h:32
bool Bool
Definition: Integer.h:40
uint64_t UInt
Definition: Integer.h:27
double Real
Definition: Real.h:41
AGXCORE_EXPORT const InvalidIndexStruct InvalidIndex
Group id 'union' of int id and name id.
Initial track tension representing either legacy distance offset per node, or an actual initial tensi...
Definition: TrackRoute.h:36