AGX Dynamics  2.38.0.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>
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 }
agx::Real
double Real
Definition: Real.h:42
agx::OrthoMatrix3x3
Specialized types of matrices for holding orthogonal transformation matrices.
Definition: OrthoMatrix3x3.h:33
agx::Vector< agx::ConstraintRef >
agx::RigidBody
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:51
agxStream::Serializable
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:44
agxVehicle::Wheel::attachConstraint
agx::ref_ptr< T > attachConstraint(const agx::Name &name, agx::RigidBody *other, agx::Real wheelCenterOffset)
Create constraint with this wheel and some other rigid body.
Definition: Wheel.h:181
export.h
Constraint.h
agx::AffineMatrix4x4T< Real >
AGXSTREAM_DECLARE_SERIALIZABLE
#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
agxVehicle::Wheel::getRotationAxis
agx::Vec3 getRotationAxis() const
Plane.h
agx
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Definition: AddedMassInteraction.h:22
agx::RigidBody::getTransform
const agx::AffineMatrix4x4 & getTransform() const
Current model frame transform, given in world coordinate frame.
Definition: RigidBody.h:1256
agx::PlaneT
Class representing the mathematical concept of a plane, also called a half- space.
Definition: Plane.h:31
agx::ref_ptr
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
agx::Vec3T::x
T & x()
Definition: Vec3Template.h:493
agx::AffineMatrix4x4
AffineMatrix4x4T< Real > AffineMatrix4x4
Definition: AffineMatrix4x4.h:390
agxVehicle::Wheel::getUpAxis
agx::Vec3 getUpAxis() const
agxVehicle
This namespace contains classes related to vehicles dynamics.
agx::Name
Representation of a name string.
Definition: Name.h:32
agx::Referenced
Base class providing referencing counted objects.
Definition: Referenced.h:119
AGX_DECLARE_POINTER_TYPES
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
agxVehicle::Wheel::getCenterPosition
agx::Vec3 getCenterPosition() const
agx::Constraint
The base class for a constraint.
Definition: Constraint.h:88
agx::Hinge
The hinge constraint between two rigid bodies or one rigid body and the world.
Definition: Hinge.h:103
AGXVEHICLE_EXPORT
#define AGXVEHICLE_EXPORT
Definition: agxVehicle/export.h:38
agx::AffineMatrix4x4T::inverse
AffineMatrix4x4T< T > inverse() const
Quick inverse, transpose rotation part, and change sign of translation part.
Definition: AffineMatrix4x4.h:461
agx::Vec3T< Real >
agx::Frame
The object defining a frame of reference and providing transformations operations.
Definition: Frame.h:67
agxVehicle::Wheel
Abstraction of a wheel of arbitrary geometry.
Definition: Wheel.h:37