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 13 // ============================================================================= 14 // 15 // Base class for a track assembly which consists of one sprocket, one idler, 16 // a collection of road wheel assemblies (suspensions), a collection of rollers, 17 // and a collection of track shoes. 18 // 19 // The reference frame for a vehicle follows the ISO standard: Z-axis up, X-axis 20 // pointing forward, and Y-axis towards the left of the vehicle. 21 // 22 // ============================================================================= 23 24 #ifndef CH_TRACK_ASSEMBLY_H 25 #define CH_TRACK_ASSEMBLY_H 26 27 #include <vector> 28 29 #include "chrono/physics/ChSystem.h" 30 #include "chrono/physics/ChBodyAuxRef.h" 31 32 #include "chrono_vehicle/ChApiVehicle.h" 33 #include "chrono_vehicle/ChPart.h" 34 35 #include "chrono_vehicle/tracked_vehicle/ChSprocket.h" 36 #include "chrono_vehicle/tracked_vehicle/ChIdler.h" 37 #include "chrono_vehicle/tracked_vehicle/ChTrackBrake.h" 38 #include "chrono_vehicle/tracked_vehicle/ChRoadWheelAssembly.h" 39 #include "chrono_vehicle/tracked_vehicle/ChRoller.h" 40 #include "chrono_vehicle/tracked_vehicle/ChTrackShoe.h" 41 42 namespace chrono { 43 namespace vehicle { 44 45 /// @addtogroup vehicle_tracked 46 /// @{ 47 48 /// Definition of a track assembly. 49 /// A track assembly consists of a sprocket, an idler (with tensioner mechanism), a set of 50 /// rollers, a set of suspensions (road-wheel assemblies), and a collection of track shoes. 51 class CH_VEHICLE_API ChTrackAssembly : public ChPart { 52 public: ~ChTrackAssembly()53 virtual ~ChTrackAssembly() {} 54 55 /// Return the vehicle side for this track assembly. GetVehicleSide()56 VehicleSide GetVehicleSide() const { return m_side; } 57 58 /// Get the number of suspensions. GetNumRoadWheelAssemblies()59 size_t GetNumRoadWheelAssemblies() const { return m_suspensions.size(); } 60 61 /// Get the number of rollers. GetNumRollers()62 size_t GetNumRollers() const { return m_rollers.size(); } 63 64 /// Get the number of track shoes. 65 virtual size_t GetNumTrackShoes() const = 0; 66 67 /// Get a handle to the sprocket. 68 virtual std::shared_ptr<ChSprocket> GetSprocket() const = 0; 69 70 /// Get a handle to the idler subsystem. GetIdler()71 std::shared_ptr<ChIdler> GetIdler() const { return m_idler; } 72 73 /// Get a handle to the brake subsystem. GetBrake()74 std::shared_ptr<ChTrackBrake> GetBrake() const { return m_brake; } 75 76 /// Get the list of suspension subsystems. GetRoadWheelAssemblies()77 const ChRoadWheelAssemblyList& GetRoadWheelAssemblies() const { return m_suspensions; } 78 79 /// Get a handle to the specified suspension subsystem. GetRoadWheelAssembly(size_t id)80 std::shared_ptr<ChRoadWheelAssembly> GetRoadWheelAssembly(size_t id) const { return m_suspensions[id]; } 81 82 /// Get a handle to the specified roller subsystem. GetRoller(size_t id)83 std::shared_ptr<ChRoller> GetRoller(size_t id) const { return m_rollers[id]; } 84 85 /// Get a handle to the specified road wheel subsystem. GetRoadWheel(size_t id)86 std::shared_ptr<ChRoadWheel> GetRoadWheel(size_t id) const { return m_suspensions[id]->GetRoadWheel(); } 87 88 /// Get a handle to the specified track shoe subsystem. 89 virtual std::shared_ptr<ChTrackShoe> GetTrackShoe(size_t id) const = 0; 90 91 /// Get the global location of the specified track shoe. 92 /// The returned location is that of the shoe body in the track shoe subsystem. GetTrackShoePos(size_t id)93 const ChVector<>& GetTrackShoePos(size_t id) const { return GetTrackShoe(id)->m_shoe->GetPos(); } 94 95 /// Get the orientation of the specified track shoe. 96 /// The track shoe body orientation is returned as a quaternion representing a 97 /// rotation with respect to the global reference frame. This is the orientation of 98 /// the shoe body in the track shoe subsystem. GetTrackShoeRot(size_t id)99 const ChQuaternion<>& GetTrackShoeRot(size_t id) const { return GetTrackShoe(id)->m_shoe->GetRot(); } 100 101 /// Get the linear velocity of the specified track shoe. 102 /// Return the linear velocity of the shoe body center, expressed in the global 103 /// reference frame. GetTrackShoeLinVel(size_t id)104 const ChVector<>& GetTrackShoeLinVel(size_t id) const { return GetTrackShoe(id)->m_shoe->GetPos_dt(); } 105 106 /// Get the angular velocity of the specified track shoe. 107 /// Return the angular velocity of the shoe body frame, expressed in the global 108 /// reference frame. GetTrackShoeAngVel(size_t id)109 ChVector<> GetTrackShoeAngVel(size_t id) const { return GetTrackShoe(id)->m_shoe->GetWvel_par(); } 110 111 /// Get the complete state for the specified track shoe. 112 /// This includes the location, orientation, linear and angular velocities, 113 /// all expressed in the global reference frame. 114 BodyState GetTrackShoeState(size_t id) const; 115 116 /// Get the complete states for all track shoes. 117 /// These include the locations, orientations, linear and angular velocities for 118 /// all track shoes in this track assembly, all expressed in the global reference frame. 119 /// It is assumed that the vector of body states was properly sized. 120 void GetTrackShoeStates(BodyStates& states) const; 121 122 /// Get the total mass of the track assembly. 123 /// This includes the masses of the sprocket, idler, suspensions, and track shoes. 124 double GetMass() const; 125 126 /// Get the relative location of the sprocket subsystem. 127 /// The track assembly reference frame is ISO, with origin at the sprocket center. 128 virtual const ChVector<> GetSprocketLocation() const = 0; 129 130 /// Get the relative location of the idler subsystem. 131 /// The track assembly reference frame is ISO, with origin at the sprocket center. 132 virtual const ChVector<> GetIdlerLocation() const = 0; 133 134 /// Get the relative location of the specified suspension subsystem. 135 /// The track assembly reference frame is ISO, with origin at the sprocket center. 136 virtual const ChVector<> GetRoadWhelAssemblyLocation(int which) const = 0; 137 138 /// Get the relative location of the specified roller subsystem. 139 /// The track assembly reference frame is ISO, with origin at the sprocket center. GetRollerLocation(int which)140 virtual const ChVector<> GetRollerLocation(int which) const { return ChVector<>(0, 0, 0); } 141 142 /// Initialize this track assembly subsystem. 143 /// The subsystem is initialized by attaching it to the specified chassis 144 /// at the specified location (with respect to and expressed in the reference 145 /// frame of the chassis). It is assumed that the track assembly reference frame 146 /// is always aligned with the chassis reference frame. 147 void Initialize(std::shared_ptr<ChChassis> chassis, ///< [in] chassis subsystem 148 const ChVector<>& location, ///< [in] location relative to the chassis frame 149 bool create_shoes = true ///< [in] control creation of the actual track 150 ); 151 152 /// Set visualization type for the sprocket subsystem. 153 void SetSprocketVisualizationType(VisualizationType vis); 154 155 // Set visualization type for the idler subsystem. 156 void SetIdlerVisualizationType(VisualizationType vis); 157 158 /// Set visualization type for the suspension subsystems. 159 void SetRoadWheelAssemblyVisualizationType(VisualizationType vis); 160 161 /// Set visualization type for the road-wheel subsystems. 162 void SetRoadWheelVisualizationType(VisualizationType vis); 163 164 /// Set visualization type for the roller subsystems. 165 void SetRollerVisualizationType(VisualizationType vis); 166 167 /// Set visualization type for the track shoe subsystems. 168 void SetTrackShoeVisualizationType(VisualizationType vis); 169 170 /// Set collision shape type for wheels. 171 void SetWheelCollisionType(bool roadwheel_as_cylinder, bool idler_as_cylinder, bool roller_as_cylinder); 172 173 /// Update the state of this track assembly at the current time. 174 void Synchronize(double time, ///< [in] current time 175 double braking, ///< [in] braking driver input 176 const TerrainForces& shoe_forces ///< [in] vector of tire force structures 177 ); 178 179 /// Enable/disable output for this subsystem. 180 /// This function overrides the output setting for all components of this track assembly. 181 virtual void SetOutput(bool state) override; 182 183 /// Log current constraint violations. 184 void LogConstraintViolations(); 185 IsRoadwheelCylinder()186 bool IsRoadwheelCylinder() const { return m_roadwheel_as_cylinder; } IsIdlerCylinder()187 bool IsIdlerCylinder() const { return m_idler_as_cylinder; } IsRolerCylinder()188 bool IsRolerCylinder() const { return m_roller_as_cylinder; } 189 190 protected: 191 ChTrackAssembly(const std::string& name, ///< [in] name of the subsystem 192 VehicleSide side ///< [in] assembly on left/right vehicle side 193 ); 194 195 /// Assemble track shoes over wheels. 196 /// Return true if the track shoes were initialized in a counter clockwise 197 /// direction and false otherwise. 198 virtual bool Assemble(std::shared_ptr<ChBodyAuxRef> chassis) = 0; 199 200 /// Remove all track shoes from assembly. 201 virtual void RemoveTrackShoes() = 0; 202 203 virtual void ExportComponentList(rapidjson::Document& jsonDocument) const override; 204 205 virtual void Output(ChVehicleOutput& database) const override; 206 207 VehicleSide m_side; ///< assembly on left/right vehicle side 208 std::shared_ptr<ChIdler> m_idler; ///< idler (and tensioner) subsystem 209 std::shared_ptr<ChTrackBrake> m_brake; ///< sprocket brake 210 ChRoadWheelAssemblyList m_suspensions; ///< road-wheel assemblies 211 ChRollerList m_rollers; ///< roller subsystems 212 213 bool m_roadwheel_as_cylinder; 214 bool m_idler_as_cylinder; 215 bool m_roller_as_cylinder; 216 217 friend class ChTrackedVehicle; 218 friend class ChTrackTestRig; 219 }; 220 221 /// @} vehicle_tracked 222 223 } // end namespace vehicle 224 } // end namespace chrono 225 226 #endif 227