AGX Dynamics  2.35.0.1
Wheel.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. 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 
79 
84 
89 
94 
99 
104 
109 
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 
144 
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 }
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
#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
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:45
Abstraction of a wheel of arbitrary geometry.
Definition: Wheel.h:38
agx::Hinge * attachHinge(const agx::Name &name, agx::RigidBody *other, agx::Real wheelCenterOffset)
Specialized version of attachConstraint to create a hinge with this wheel body and other.
virtual ~Wheel()
Reference counted object - protected destructor.
agx::Vec3 getCenterPosition() const
const ConstraintContainer & getConstraints() const
agx::Frame * getLocalFrame() const
Wheel(agx::Real radius, agx::RigidBody *rb, agx::Frame *rbRelFrame=nullptr)
Construct wheel given radius, wheel body and frame defining wheel center, up and rotation axes in the...
agx::RigidBody * getRigidBody() const
agx::Plane getRotationAxisPlane() const
agx::Real getRadius() const
Wheel()
Default constructor used only when this object is restored.
agx::Constraint * getConstraint(const agx::Name &name) const
agx::Vec3 getRotationAxis() const
agx::Constraint * getConstraint() const
agx::Vec3 getUpAxis() const
agx::AffineMatrix4x4 getTransform() const
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
Wheel(agx::Real radius, agx::RigidBody *rb, agx::AffineMatrix4x4 rbRelTransform)
Construct wheel given radius, wheel body and transform defining wheel center, up and rotation axes in...
AffineMatrix4x4T< T > inverse() const
Quick inverse, transpose rotation part, and change sign of translation part.
The base class for a constraint.
Definition: Constraint.h:89
The object defining a frame of reference and providing transformations operations.
Definition: agx/Frame.h:68
The hinge constraint between two rigid bodies or one rigid body and the world.
Definition: Hinge.h:104
Representation of a name string.
Definition: Name.h:33
Specialized types of matrices for holding orthogonal transformation matrices.
Class representing the mathematical concept of a plane, also called a half- space.
Definition: agx/Plane.h:32
Base class providing referencing counted objects.
Definition: Referenced.h:114
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:55
const agx::AffineMatrix4x4 & getTransform() const
Current model frame transform, given in world coordinate frame.
Definition: RigidBody.h:1633
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:30
This namespace contains classes related to vehicles dynamics.
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
double Real
Definition: Real.h:42
AffineMatrix4x4T< Real > AffineMatrix4x4