AGX Dynamics  2.37.3.2
Wheel.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 #pragma once
18 
19 #include <agxVehicle/export.h>
20 
21 #include <agx/Constraint.h>
22 #include <agx/Plane.h>
23 
24 namespace agx
25 {
26  class Hinge;
27 }
28 
29 namespace agxVehicle
30 {
32 
38  {
39  public:
41 
42  public:
57  Wheel( agx::Real radius, agx::RigidBody* rb, agx::Frame* rbRelFrame = nullptr );
58 
73  Wheel( agx::Real radius, agx::RigidBody* rb, agx::AffineMatrix4x4 rbRelTransform );
74 
78  agx::Real getRadius() const;
79 
83  agx::RigidBody* getRigidBody() const;
84 
88  agx::Frame* getLocalFrame() const;
89 
93  agx::AffineMatrix4x4 getTransform() const;
94 
98  agx::Vec3 getCenterPosition() const;
99 
103  agx::Vec3 getRotationAxis() const;
104 
108  agx::Vec3 getUpAxis() const;
109 
113  agx::Plane getRotationAxisPlane() const;
114 
127  template<typename T>
128  agx::ref_ptr<T> attachConstraint( const agx::Name& name, agx::RigidBody* other, agx::Real wheelCenterOffset );
129 
138  agx::Hinge* attachHinge( const agx::Name& name, agx::RigidBody* other, agx::Real wheelCenterOffset );
139 
143  const ConstraintContainer& getConstraints() const;
144 
148  agx::Constraint* getConstraint() const;
149 
154  agx::Constraint* getConstraint( const agx::Name& name ) const;
155 
156  public:
158 
159  protected:
163  Wheel();
164 
168  virtual ~Wheel();
169 
170  private:
171  void addConstraint( const agx::Name& name, agx::Constraint* constraint );
172 
173  private:
174  agx::Real m_radius;
175  agx::RigidBodyRef m_rb;
176  agx::FrameRef m_rbRelFrame;
177  ConstraintContainer m_constraints;
178  };
179 
180  template<typename T>
181  agx::ref_ptr<T> Wheel::attachConstraint( const agx::Name& name, agx::RigidBody* other, agx::Real wheelCenterOffset )
182  {
183  if ( m_rb == nullptr )
184  return agx::ref_ptr<T>( nullptr );
185 
186  // x y z
187  const auto xAxis = getRotationAxis() ^ getUpAxis();
188  agx::OrthoMatrix3x3 rotation( getUpAxis().x(), getUpAxis().y(), getUpAxis().z(),
189  xAxis.x(), xAxis.y(), xAxis.z(),
190  getRotationAxis().x(), getRotationAxis().y(), getRotationAxis().z() );
191 
192  const auto constraintFrame = agx::AffineMatrix4x4( rotation,
193  getCenterPosition() + wheelCenterOffset * getRotationAxis() );
194  agx::FrameRef wheelFrame = new agx::Frame( constraintFrame * m_rb->getTransform().inverse() );
195  agx::FrameRef otherFrame = new agx::Frame( constraintFrame * ( other != nullptr ? other->getTransform().inverse() : agx::AffineMatrix4x4() ) );
196 
197  agx::ref_ptr<T> constraint = new T( m_rb, wheelFrame, other, otherFrame );
198  addConstraint( name, constraint );
199 
200  return constraint;
201  }
202 }
Abstraction of a wheel of arbitrary geometry.
Definition: Wheel.h:37
AffineMatrix4x4T< Real > AffineMatrix4x4
#define AGXVEHICLE_EXPORT
The base class for a constraint.
Definition: Constraint.h:88
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
Representation of a name string.
Definition: Name.h:32
Class representing the mathematical concept of a plane, also called a half- space.
Definition: Plane.h:31
const agx::AffineMatrix4x4 & getTransform() const
Current model frame transform, given in world coordinate frame.
Definition: RigidBody.h:1609
Base class providing referencing counted objects.
Definition: Referenced.h:119
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
The hinge constraint between two rigid bodies or one rigid body and the world.
Definition: Hinge.h:103
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
This namespace contains classes related to vehicles dynamics.
The object defining a frame of reference and providing transformations operations.
Definition: Frame.h:67
#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
AffineMatrix4x4T< T > inverse() const
Quick inverse, transpose rotation part, and change sign of translation part.
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:44
double Real
Definition: Real.h:42
Specialized types of matrices for holding orthogonal transformation matrices.