1 // ============================================================================= 2 // PROJECT CHRONO - http://projectchrono.org 3 // 4 // Copyright (c) 2014 projectchrono.org 5 // All rights reserved. 6 // 7 // Use of this source code is governed by a BSD-style license that can be found 8 // in the LICENSE file at the top level of the distribution and at 9 // http://projectchrono.org/license-chrono.txt. 10 // 11 // ============================================================================= 12 // Authors: Radu Serban, Justin Madsen 13 // ============================================================================= 14 // 15 // Base class for a vehicle wheel. 16 // A wheel subsystem does not own a body. Instead, when attached to a suspension 17 // subsystem, the wheel's mass properties are used to update those of the 18 // spindle body owned by the suspension. 19 // A concrete wheel subsystem can optionally carry its own visualization assets 20 // (which are associated with the suspension's spindle body). 21 // 22 // ============================================================================= 23 24 #ifndef CH_WHEEL_H 25 #define CH_WHEEL_H 26 27 #include <vector> 28 29 #include "chrono/physics/ChBody.h" 30 #include "chrono/assets/ChCylinderShape.h" 31 #include "chrono/assets/ChTriangleMeshShape.h" 32 33 #include "chrono_vehicle/ChApiVehicle.h" 34 #include "chrono_vehicle/ChPart.h" 35 36 namespace chrono { 37 namespace vehicle { 38 39 // Forward declaration 40 class ChTire; 41 42 /// @addtogroup vehicle_wheeled_wheel 43 /// @{ 44 45 /// Base class for a vehicle wheel subsystem. 46 /// A wheel subsystem does not own a body. Instead, when attached to a suspension 47 /// subsystem, the wheel's mass properties are used to update those of the 48 /// spindle body owned by the suspension. 49 /// A concrete wheel subsystem can optionally carry its own visualization assets 50 /// (which are associated with the suspension's spindle body). 51 class CH_VEHICLE_API ChWheel : public ChPart { 52 public: 53 ChWheel(const std::string& name ///< [in] name of the subsystem 54 ); 55 ~ChWheel()56 virtual ~ChWheel() {} 57 58 /// Get the name of the vehicle subsystem template. GetTemplateName()59 virtual std::string GetTemplateName() const override { return "Wheel"; } 60 61 /// Get the wheel mass. 62 virtual double GetMass() const = 0; 63 64 /// Get the wheel moments of inertia. 65 virtual ChVector<> GetInertia() const = 0; 66 67 /// Get the wheel radius (for visualization only). GetRadius()68 virtual double GetRadius() const { return 0; } 69 70 /// Get the wheel width (for visualization only). GetWidth()71 virtual double GetWidth() const { return 0; } 72 73 /// Initialize this wheel subsystem by associating it to an existing spindle of a suspension subsystem. 74 /// The optional 'offset' argument allows models with double wheels(tires). The default value offset=0 corresponds 75 /// to an axle with a single tire. A positive offset corresponds to an "outer" wheel, while a negative offset 76 /// corresponds to an "inner" wheel. The wheel mass and inertia are used to increment those of the associated 77 /// spindle body. 78 virtual void Initialize(std::shared_ptr<ChBody> spindle, ///< associated suspension spindle body 79 VehicleSide side, ///< wheel mounted on left/right side 80 double offset = 0 ///< offset from associated spindle center 81 ); 82 83 /// Synchronize the wheel subsystem. 84 /// This queries the forces from the attached tire and passes it to the associated suspension. 85 void Synchronize(); 86 87 /// Get the tire attached to this wheel. GetTire()88 std::shared_ptr<ChTire> GetTire() const { return m_tire; } 89 90 /// Associate the given tire with this wheel. SetTire(std::shared_ptr<ChTire> tire)91 void SetTire(std::shared_ptr<ChTire> tire) { m_tire = tire; } 92 93 /// Get the associated spindle body. GetSpindle()94 std::shared_ptr<ChBody> GetSpindle() const { return m_spindle; } 95 96 /// Get the vehicle side on which this wheel is mounted. GetSide()97 VehicleSide GetSide() const { return m_side; } 98 99 /// Get wheel position (expressed in absolute frame). 100 ChVector<> GetPos() const; 101 102 /// Get the current state for this wheel. 103 /// This includes the location, orientation, linear and angular velocities, 104 /// all expressed in the global reference frame, as well as the wheel angular 105 /// speed about its rotation axis. 106 WheelState GetState() const; 107 108 /// Add visualization assets for the wheel subsystem. 109 /// This default implementation uses primitives. 110 virtual void AddVisualizationAssets(VisualizationType vis) override; 111 112 /// Remove visualization assets for the wheel subsystem. 113 virtual void RemoveVisualizationAssets() override; 114 115 /// Get the name of the Wavefront file with wheel visualization mesh. 116 /// An empty string is returned if no mesh was specified. GetMeshFilename()117 const std::string& GetMeshFilename() const { return m_vis_mesh_file; } 118 119 protected: 120 std::shared_ptr<ChBody> m_spindle; ///< associated suspension spindle body 121 std::shared_ptr<ChTire> m_tire; ///< attached tire subsystem 122 VehicleSide m_side; ///< wheel mounted on left/right side 123 double m_offset; ///< offset from spindle center 124 125 std::string m_vis_mesh_file; ///< visualization mesh file (may be empty) 126 std::shared_ptr<ChTriangleMeshShape> m_trimesh_shape; ///< visualization mesh asset 127 std::shared_ptr<ChCylinderShape> m_cyl_shape; ///< visualization cylinder asset 128 129 friend class ChTire; 130 friend class ChWheeledVehicle; 131 }; 132 133 /// Vector of handles to wheel subsystems. 134 typedef std::vector<std::shared_ptr<ChWheel> > ChWheelList; 135 136 /// @} vehicle_wheeled_wheel 137 138 } // end namespace vehicle 139 } // end namespace chrono 140 141 #endif 142