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 double roller (template definition).
16 // A double roller is of type CENTRAL_PIN.
17 //
18 // =============================================================================
19 
20 #include "chrono/core/ChGlobal.h"
21 #include "chrono/assets/ChCylinderShape.h"
22 #include "chrono/assets/ChTexture.h"
23 
24 #include "chrono_vehicle/ChSubsysDefs.h"
25 #include "chrono_vehicle/tracked_vehicle/roller/ChDoubleRoller.h"
26 #include "chrono_vehicle/tracked_vehicle/ChTrackAssembly.h"
27 
28 namespace chrono {
29 namespace vehicle {
30 
31 // -----------------------------------------------------------------------------
32 // -----------------------------------------------------------------------------
ChDoubleRoller(const std::string & name)33 ChDoubleRoller::ChDoubleRoller(const std::string& name) : ChRoller(name) {}
34 
35 // -----------------------------------------------------------------------------
36 // -----------------------------------------------------------------------------
Initialize(std::shared_ptr<ChBodyAuxRef> chassis,const ChVector<> & location,ChTrackAssembly * track)37 void ChDoubleRoller::Initialize(std::shared_ptr<ChBodyAuxRef> chassis,
38                                 const ChVector<>& location,
39                                 ChTrackAssembly* track) {
40     // Invoke the base class method
41     ChRoller::Initialize(chassis, location, track);
42 
43     CreateContactMaterial(m_wheel->GetSystem()->GetContactMethod());
44     assert(m_material && m_material->GetContactMethod() == m_wheel->GetSystem()->GetContactMethod());
45 
46     // Add contact geometry.
47     double radius = GetRadius();
48     double width = 0.5 * (GetWidth() - GetGap());
49     double offset = 0.25 * (GetWidth() + GetGap());
50 
51     m_wheel->SetCollide(true);
52 
53     m_wheel->GetCollisionModel()->ClearModel();
54 
55     m_wheel->GetCollisionModel()->SetFamily(TrackedCollisionFamily::ROLLERS);
56     m_wheel->GetCollisionModel()->SetFamilyMaskNoCollisionWithFamily(TrackedCollisionFamily::WHEELS);
57     m_wheel->GetCollisionModel()->SetFamilyMaskNoCollisionWithFamily(TrackedCollisionFamily::IDLERS);
58 
59     if (track->IsIdlerCylinder()) {
60         m_wheel->GetCollisionModel()->AddCylinder(m_material, radius, radius, width / 2, ChVector<>(0, +offset, 0));
61         m_wheel->GetCollisionModel()->AddCylinder(m_material, radius, radius, width / 2, ChVector<>(0, -offset, 0));
62     } else {
63         m_wheel->GetCollisionModel()->AddCylindricalShell(m_material, radius, width / 2, ChVector<>(0, +offset, 0));
64         m_wheel->GetCollisionModel()->AddCylindricalShell(m_material, radius, width / 2, ChVector<>(0, -offset, 0));
65     }
66 
67     m_wheel->GetCollisionModel()->BuildModel();
68 }
69 
70 // -----------------------------------------------------------------------------
71 // -----------------------------------------------------------------------------
AddVisualizationAssets(VisualizationType vis)72 void ChDoubleRoller::AddVisualizationAssets(VisualizationType vis) {
73     if (vis == VisualizationType::NONE)
74         return;
75 
76     double radius = GetRadius();
77     double width = GetWidth();
78     double gap = GetGap();
79 
80     auto cyl_1 = chrono_types::make_shared<ChCylinderShape>();
81     cyl_1->GetCylinderGeometry().p1 = ChVector<>(0, width / 2, 0);
82     cyl_1->GetCylinderGeometry().p2 = ChVector<>(0, gap / 2, 0);
83     cyl_1->GetCylinderGeometry().rad = radius;
84     m_wheel->AddAsset(cyl_1);
85 
86     auto cyl_2 = chrono_types::make_shared<ChCylinderShape>();
87     cyl_2->GetCylinderGeometry().p1 = ChVector<>(0, -width / 2, 0);
88     cyl_2->GetCylinderGeometry().p2 = ChVector<>(0, -gap / 2, 0);
89     cyl_2->GetCylinderGeometry().rad = radius;
90     m_wheel->AddAsset(cyl_2);
91 
92     auto tex = chrono_types::make_shared<ChTexture>();
93     tex->SetTextureFilename(chrono::GetChronoDataFile("textures/redwhite.png"));
94     m_wheel->AddAsset(tex);
95 }
96 
RemoveVisualizationAssets()97 void ChDoubleRoller::RemoveVisualizationAssets() {
98     m_wheel->GetAssets().clear();
99 }
100 
101 }  // end namespace vehicle
102 }  // end namespace chrono
103