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 // Template for a rigid-body chassis vehicle subsystem. 16 // 17 // ============================================================================= 18 19 #ifndef CH_RIGID_CHASSIS_H 20 #define CH_RIGID_CHASSIS_H 21 22 #include <vector> 23 24 #include "chrono_vehicle/ChChassis.h" 25 #include "chrono/assets/ChColor.h" 26 27 namespace chrono { 28 namespace vehicle { 29 30 /// @addtogroup vehicle 31 /// @{ 32 33 // ----------------------------------------------------------------------------- 34 35 /// Template for a rigid-body main chassis vehicle subsystem. 36 class CH_VEHICLE_API ChRigidChassis : public ChChassis { 37 public: 38 /// Construct a vehicle subsystem with the specified name. 39 ChRigidChassis(const std::string& name, ///< [in] name of the subsystem 40 bool fixed = false ///< [in] is the chassis body fixed to ground? 41 ); 42 ~ChRigidChassis()43 virtual ~ChRigidChassis() {} 44 45 /// Get the name of the vehicle subsystem template. GetTemplateName()46 virtual std::string GetTemplateName() const override { return "RigidChassis"; } 47 48 /// Specifies whether or not collision shapes were defined. HasCollision()49 bool HasCollision() const { return m_geometry.m_has_collision; } 50 51 /// Specifies whether or not visualization primitives were defined. HasPrimitives()52 bool HasPrimitives() const { return m_geometry.m_has_primitives; } 53 54 /// Specifies whether or not a visualization mesh was defined. HasMesh()55 bool HasMesh() const { return m_geometry.m_has_mesh; } 56 57 /// Get the name of the Wavefront file with chassis visualization mesh. 58 /// An empty string is returned if no mesh was specified. GetMeshFilename()59 const std::string& GetMeshFilename() const { return m_geometry.m_vis_mesh_file; } 60 61 /// Enable/disable contact for the chassis. This function controls contact of 62 /// the chassis with all other collision shapes in the simulation. SetCollide(bool state)63 virtual void SetCollide(bool state) override { m_body->SetCollide(state); } 64 65 /// Initialize the chassis at the specified global position and orientation. 66 virtual void Initialize(ChSystem* system, ///< [in] containing system 67 const ChCoordsys<>& chassisPos, ///< [in] absolute chassis position 68 double chassisFwdVel, ///< [in] initial chassis forward velocity 69 int collision_family = 0 ///< [in] chassis collision family 70 ) override; 71 72 /// Add visualization assets to this subsystem, for the specified visualization mode. 73 virtual void AddVisualizationAssets(VisualizationType vis) override; 74 75 /// Remove all visualization assets from this subsystem. 76 virtual void RemoveVisualizationAssets() override final; 77 78 protected: 79 ChVehicleGeometry m_geometry; ///< collection of visualization and collision shapes 80 81 /// Load contact materials. A derived class must implement this only if it sets m_has_collision to 'true' and should 82 /// use contact materials consistent with the specified contact method. CreateContactMaterials(ChContactMethod contact_method)83 virtual void CreateContactMaterials(ChContactMethod contact_method) {} 84 85 virtual void ExportComponentList(rapidjson::Document& jsonDocument) const override; 86 87 virtual void Output(ChVehicleOutput& database) const override; 88 }; 89 90 // ----------------------------------------------------------------------------- 91 92 /// Template for a rigid-body rear chassis vehicle subsystem. 93 class CH_VEHICLE_API ChRigidChassisRear : public ChChassisRear { 94 public: 95 /// Construct a vehicle subsystem with the specified name. 96 ChRigidChassisRear(const std::string& name); 97 ~ChRigidChassisRear()98 virtual ~ChRigidChassisRear() {} 99 100 /// Get the name of the vehicle subsystem template. GetTemplateName()101 virtual std::string GetTemplateName() const override { return "RigidChassisRear"; } 102 103 /// Specifies whether or not collision shapes were defined. HasCollision()104 bool HasCollision() const { return m_geometry.m_has_collision; } 105 106 /// Specifies whether or not visualization primitives were defined. HasPrimitives()107 bool HasPrimitives() const { return m_geometry.m_has_primitives; } 108 109 /// Specifies whether or not a visualization mesh was defined. HasMesh()110 bool HasMesh() const { return m_geometry.m_has_mesh; } 111 112 /// Get the name of the Wavefront file with chassis visualization mesh. 113 /// An empty string is returned if no mesh was specified. GetMeshFilename()114 const std::string& GetMeshFilename() const { return m_geometry.m_vis_mesh_file; } 115 116 /// Enable/disable contact for the chassis. This function controls contact of 117 /// the chassis with all other collision shapes in the simulation. SetCollide(bool state)118 virtual void SetCollide(bool state) override { m_body->SetCollide(state); } 119 120 /// Initialize the rear chassis relative to the specified front chassis. 121 /// The orientation is set to be the same as that of the front chassis while the location is based on the connector 122 /// position on the front and rear chassis. 123 virtual void Initialize(std::shared_ptr<ChChassis> chassis, ///< [in] front chassis 124 int collision_family = 0 ///< [in] chassis collision family 125 ) override; 126 127 /// Add visualization assets to this subsystem, for the specified visualization mode. 128 virtual void AddVisualizationAssets(VisualizationType vis) override; 129 130 /// Remove all visualization assets from this subsystem. 131 virtual void RemoveVisualizationAssets() override final; 132 133 protected: 134 ChVehicleGeometry m_geometry; ///< collection of visualization and collision shapes 135 136 /// Load contact materials. A derived class must implement this only if it sets m_has_collision to 'true' and should 137 /// use contact materials consistent with the specified contact method. CreateContactMaterials(ChContactMethod contact_method)138 virtual void CreateContactMaterials(ChContactMethod contact_method) {} 139 140 virtual void ExportComponentList(rapidjson::Document& jsonDocument) const override; 141 142 virtual void Output(ChVehicleOutput& database) const override; 143 }; 144 145 /// @} vehicle 146 147 } // end namespace vehicle 148 } // end namespace chrono 149 150 #endif 151