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 all vehicle subsystems. 16 // 17 // ============================================================================= 18 19 #ifndef CH_PART_H 20 #define CH_PART_H 21 22 #include <string> 23 24 #include "chrono/physics/ChBody.h" 25 #include "chrono/physics/ChShaft.h" 26 #include "chrono/physics/ChLink.h" 27 #include "chrono/physics/ChShaftsCouple.h" 28 #include "chrono/physics/ChLinkTSDA.h" 29 #include "chrono/physics/ChLinkRotSpringCB.h" 30 #include "chrono/physics/ChLoadsBody.h" 31 #include "chrono/physics/ChMaterialSurfaceNSC.h" 32 #include "chrono/physics/ChMaterialSurfaceSMC.h" 33 34 #include "chrono_vehicle/ChApiVehicle.h" 35 #include "chrono_vehicle/ChSubsysDefs.h" 36 #include "chrono_vehicle/ChVehicleJoint.h" 37 #include "chrono_vehicle/ChVehicleOutput.h" 38 39 #include "chrono_thirdparty/rapidjson/document.h" 40 41 namespace chrono { 42 namespace vehicle { 43 44 /// @addtogroup vehicle 45 /// @{ 46 47 /// Base class for a vehicle subsystem. 48 /// It manages the part's name, visualization assets, and output. 49 class CH_VEHICLE_API ChPart { 50 public: 51 /// Construct a vehicle subsystem with the specified name. 52 ChPart(const std::string& name ///< [in] name of the subsystem 53 ); 54 ~ChPart()55 virtual ~ChPart() {} 56 57 /// Get the name identifier for this subsystem. GetName()58 const std::string& GetName() const { return m_name; } 59 60 /// Set the name identifier for this subsystem. SetName(const std::string & name)61 void SetName(const std::string& name) { m_name = name; } 62 63 /// Get the name of the vehicle subsystem template. 64 virtual std::string GetTemplateName() const = 0; 65 66 /// Set the visualization mode for this subsystem. 67 void SetVisualizationType(VisualizationType vis); 68 69 /// Add visualization assets to this subsystem, for the specified visualization mode. AddVisualizationAssets(VisualizationType vis)70 virtual void AddVisualizationAssets(VisualizationType vis) {} 71 72 /// Remove all visualization assets from this subsystem. RemoveVisualizationAssets()73 virtual void RemoveVisualizationAssets() {} 74 75 /// Enable/disable output for this subsystem. SetOutput(bool state)76 virtual void SetOutput(bool state) { m_output = state; } 77 78 /// Return the output state for this subsystem. OutputEnabled()79 bool OutputEnabled() const { return m_output; } 80 81 /// Export this subsystem's component list to the specified JSON object. 82 /// Derived classes should override this function and first invoke the base class implementation, 83 /// followed by calls to the various static Export***List functions, as appropriate. 84 virtual void ExportComponentList(rapidjson::Document& jsonDocument) const; 85 86 /// Output data for this subsystem's component list to the specified database. Output(ChVehicleOutput & database)87 virtual void Output(ChVehicleOutput& database) const {} 88 89 /// Utility function for transforming inertia tensors between centroidal frames. 90 /// It converts an inertia matrix specified in a centroidal frame aligned with the 91 /// vehicle reference frame to an inertia matrix expressed in a centroidal body 92 /// reference frame. 93 static ChMatrix33<> TransformInertiaMatrix( 94 const ChVector<>& moments, ///< moments of inertia in vehicle-aligned centroidal frame 95 const ChVector<>& products, ///< products of inertia in vehicle-aligned centroidal frame 96 const ChMatrix33<>& vehicle_rot, ///< vehicle absolute orientation matrix 97 const ChMatrix33<>& body_rot ///< body absolute orientation matrix 98 ); 99 100 protected: 101 /// Create a vehicle subsystem from JSON data. 102 /// A derived class must override this function and first invoke the base class implementation. 103 virtual void Create(const rapidjson::Document& d); 104 105 /// Export the list of bodies to the specified JSON document. 106 static void ExportBodyList(rapidjson::Document& jsonDocument, std::vector<std::shared_ptr<ChBody>> bodies); 107 108 /// Export the list of shafts to the specified JSON document. 109 static void ExportShaftList(rapidjson::Document& jsonDocument, std::vector<std::shared_ptr<ChShaft>> shafts); 110 111 /// Export the list of joints to the specified JSON document. 112 static void ExportJointList(rapidjson::Document& jsonDocument, std::vector<std::shared_ptr<ChLink>> joints); 113 114 /// Export the list of shaft couples to the specified JSON document. 115 static void ExportCouplesList(rapidjson::Document& jsonDocument, std::vector<std::shared_ptr<ChShaftsCouple>> couples); 116 117 /// Export the list of markers to the specified JSON document. 118 static void ExportMarkerList(rapidjson::Document& jsonDocument, std::vector<std::shared_ptr<ChMarker>> markers); 119 120 /// Export the list of translational springs to the specified JSON document. 121 static void ExportLinSpringList(rapidjson::Document& jsonDocument, 122 std::vector<std::shared_ptr<ChLinkTSDA>> springs); 123 124 /// Export the list of rotational springs to the specified JSON document. 125 static void ExportRotSpringList(rapidjson::Document& jsonDocument, 126 std::vector<std::shared_ptr<ChLinkRotSpringCB>> springs); 127 128 /// Export the list of body-body loads to the specified JSON document. 129 static void ExportBodyLoadList(rapidjson::Document& jsonDocument, std::vector<std::shared_ptr<ChLoadBodyBody>> loads); 130 131 std::string m_name; ///< subsystem name 132 133 bool m_output; ///< specifies whether or not output is generated for this subsystem 134 }; 135 136 // Utility class with material information for a collision shape. 137 class CH_VEHICLE_API MaterialInfo { 138 public: 139 float mu; // coefficient of friction 140 float cr; // coefficient of restitution 141 float Y; // Young's modulus 142 float nu; // Poisson ratio 143 float kn; // normal stiffness 144 float gn; // normal viscous damping 145 float kt; // tangential stiffness 146 float gt; // tangential viscous damping 147 148 MaterialInfo(); 149 MaterialInfo(float mu_, float cr_, float Y_, float nu_, float kn_, float gn_, float kt_, float gt_); 150 151 // Construct a contact material, consistent with the specified method, using the data in the provided structure. 152 std::shared_ptr<ChMaterialSurface> CreateMaterial(ChContactMethod contact_method); 153 }; 154 155 /// @} vehicle 156 157 } // end namespace vehicle 158 } // end namespace chrono 159 160 #endif 161