AGX Dynamics 2.42.3.1
Loading...
Searching...
No Matches
TrackFrictionModels.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
20
21#include <agx/FrictionModel.h>
22
23namespace agxVehicle
24{
28
30 const agxCollide::Geometry* g2,
31 const agx::Vec3& normal,
32 agx::Vec3& ret_u,
33 agx::Vec3& ret_v );
34
42 template<typename T>
43 class TrackFrictionModelImpl : public T
44 {
45 public:
46 using Impl = T;
47
48 public:
49 using Impl::Impl;
50
51 public:
57 virtual void calculateTangentPlane( const agxCollide::Geometry* geometry1,
58 const agxCollide::Geometry* geometry2,
59 const agx::Vec3& point,
60 const agx::Vec3& normal,
61 const agx::Real depth,
62 agx::Vec3& ret_u,
63 agx::Vec3& ret_v ) const override;
64
65 protected:
66 virtual ~TrackFrictionModelImpl() = default;
67 };
68
69#ifdef SWIG
70 %template(TrackBoxFrictionModelImpl) TrackFrictionModelImpl<agx::BoxFrictionModel>;
71 %template(TrackScaleBoxFrictionModelImpl) TrackFrictionModelImpl<agx::ScaleBoxFrictionModel>;
72 %template(TrackIterativeProjectedConeFrictionModelImpl) TrackFrictionModelImpl<agx::IterativeProjectedConeFriction>;
73#endif
74
86 {
87 public:
89
90 public:
106 agx::Real constantNormalForceMagnitude = 0.0,
107 bool scaleWithDepth = false );
108
114
119
124 void setConstantNormalForceMagnitude( agx::Real constantNormalForceMagnitude );
125
130
138 void setEnableScaleWithDepth( bool enable );
139
144
145 public:
150 const agxCollide::Geometry* geometry2,
151 const agx::Vec3& point,
152 const agx::Vec3& normal,
153 const agx::Real depth,
154 const agx::Real dt,
155 const size_t numPoints ) const override;
156
158
159 protected:
160 virtual ~TrackBoxFrictionModel() = default;
161
162 private:
163 struct InternalState
164 {
165 enum Flag : agx::UInt16
166 {
167 CONSTANT_NORMAL_FORCE = 1 << 0,
168 SCALE_WITH_DEPTH = 1 << 1,
169 };
170
171 using Flags = agx::BitState<Flag, std::underlying_type_t<Flag>>;
172
173 Flags flags{};
174 agx::Real constantNormalForceMagnitude{};
175 };
176
177 private:
178 InternalState m_state;
179 };
180
186 {
187 public:
189
190 public:
191#ifndef SWIG
192 using Base::TrackFrictionModelImpl;
193#else
195#endif
196
198
199 protected:
200 virtual ~TrackScaleBoxFrictionModel() = default;
201 };
202
208 {
209 public:
211
212 public:
213#ifndef SWIG
214 using Base::TrackFrictionModelImpl;
215#else
217#endif
218
220
221 protected:
223 };
224
226
228 const agxCollide::Geometry* g2,
229 const agx::Vec3& normal,
230 agx::Vec3& ret_u,
231 agx::Vec3& ret_v )
232 {
233 const auto t1 = Track::get( g1->getRigidBody() );
234 const auto t2 = t1 != nullptr ? nullptr : Track::get( g2->getRigidBody() );
235 auto primaryDirectionWorld = agx::Vec3::X_AXIS();
236 agx::Real sign = 1.0;
237 if ( t1 != nullptr || t2 != nullptr ) {
238 const auto t = t1 != nullptr ? t1 : t2;
239 const auto rb = t1 != nullptr ? g1->getRigidBody() : g2->getRigidBody();
240 sign *= 1.0 - 2.0 * agx::Real( t1 == nullptr );
241 // A track segment has +z forward (along the track), +x "up" towards the track center line.
242 if ( utils::isTrackSegment( *t, *rb ) )
243 primaryDirectionWorld = rb->getFrame()->transformVectorToWorld( agx::Vec3::Z_AXIS() );
244 // A track wheel rotates, the only well defined axis is the rotation axis. Contact
245 // normal cross the rotation axis is, normally, along the track.
246 else if ( const auto wheel = utils::findWheel( *t, *rb ) )
247 primaryDirectionWorld = normal.cross( sign * wheel->getRotationAxis() ).normal();
248 }
249
250 agx::FrictionModel::calculateTangentPlane( primaryDirectionWorld, sign * normal, ret_u, ret_v );
251 }
252
253 template<typename T>
255 const agxCollide::Geometry* geometry2,
256 const agx::Vec3& /*point*/,
257 const agx::Vec3& normal,
258 const agx::Real /*depth*/,
259 agx::Vec3& ret_u,
260 agx::Vec3& ret_v ) const
261 {
262 calculateTrackTangentPlane( geometry1, geometry2, normal, ret_u, ret_v );
263 }
264}
#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
agx::RigidBody * getRigidBody()
Definition: Geometry.h:790
The agx::BoxFrictionModel with oriented friction directions calculated from interacting track instanc...
void setEnableScaleWithDepth(bool enable)
Enable/disable scale of the given normal force with the contact point depth resulting in a maximum fr...
agx::Real getConstantNormalForceMagnitude() const
void setEnableConstantNormalForceMagnitude(bool enable)
Enable/disable use of given/constant normal force magnitude.
TrackBoxFrictionModel(agx::FrictionModel::SolveType solveType=agx::FrictionModel::SPLIT, agx::Real constantNormalForceMagnitude=0.0, bool scaleWithDepth=false)
Construct given solve type, (optional) constant normal force magnitude and/or (optional) state to sca...
virtual agx::Real calculateNormalForce(const agxCollide::Geometry *geometry1, const agxCollide::Geometry *geometry2, const agx::Vec3 &point, const agx::Vec3 &normal, const agx::Real depth, const agx::Real dt, const size_t numPoints) const override
void setConstantNormalForceMagnitude(agx::Real constantNormalForceMagnitude)
Assign normal force magnitude.
bool getEnableConstantNormalForceMagnitude() const
virtual ~TrackBoxFrictionModel()=default
Track friction model that calculates the friction directions given the well defined coordinate frames...
virtual void calculateTangentPlane(const agxCollide::Geometry *geometry1, const agxCollide::Geometry *geometry2, const agx::Vec3 &point, const agx::Vec3 &normal, const agx::Real depth, agx::Vec3 &ret_u, agx::Vec3 &ret_v) const override
Calculating the friction directions such as the primary direction is along the first interacting trac...
virtual ~TrackFrictionModelImpl()=default
The agx::IterativeProjectedConeFriction with oriented friction directions calculated from interacting...
The agx::ScaleBoxFrictionModel with oriented friction directions calculated from interacting track in...
virtual ~TrackScaleBoxFrictionModel()=default
static Track * get(agx::RigidBody *rb)
@ SPLIT
First Normal equation is calculated in the DIRECT solver, then in a second pass the normal and the fr...
Definition: FrictionModel.h:62
static void calculateTangentPlane(const Vec3 &primaryDirectionWorld, const Vec3 &normal, Vec3 &ret_u, Vec3 &ret_v)
Calculates friction tangents directions given primaryDirectionWorld and contact normal.
static Vec3T Z_AXIS()
Definition: Vec3Template.h:783
Vec3T normal() const
Definition: Vec3Template.h:722
const Vec3T cross(const Vec3T &rhs) const
Cross product method.
Definition: Vec3Template.h:561
static Vec3T X_AXIS()
Definition: Vec3Template.h:771
AGXVEHICLE_EXPORT bool isTrackSegment(const Track &track, const agx::RigidBody &rb)
Check if the given rb is a track segment type of body, e.g., a node or a segment sensor.
AGXVEHICLE_EXPORT const TrackWheel * findWheel(const Track &track, const agx::RigidBody &rb)
Finds the wheel instance in the given track if rb is a track sensor of the wheel.
This namespace contains classes related to vehicles dynamics.
static void calculateTrackTangentPlane(const agxCollide::Geometry *g1, const agxCollide::Geometry *g2, const agx::Vec3 &normal, agx::Vec3 &ret_u, agx::Vec3 &ret_v)
uint16_t UInt16
Definition: Integer.h:31
double Real
Definition: Real.h:41