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: Alessandro Tasora
13 // =============================================================================
14 //
15 // Simple brake created with constant torque opposing sprocket rotation.
16 // It just uses a speed-dependent torque.
17 //
18 // =============================================================================
19 
20 #include "chrono/physics/ChLinkLock.h"
21 
22 #include "chrono_vehicle/tracked_vehicle/brake/ChTrackBrakeSimple.h"
23 
24 namespace chrono {
25 namespace vehicle {
26 
ChTrackBrakeSimple(const std::string & name)27 ChTrackBrakeSimple::ChTrackBrakeSimple(const std::string& name) : ChTrackBrake(name), m_braking(0) {
28     m_brake = chrono_types::make_shared<ChLinkBrake>();
29 }
30 
~ChTrackBrakeSimple()31 ChTrackBrakeSimple::~ChTrackBrakeSimple() {
32     auto sys = m_brake->GetSystem();
33     if (sys) {
34         sys->Remove(m_brake);
35     }
36 }
37 
Initialize(std::shared_ptr<ChChassis> chassis,std::shared_ptr<ChSprocket> sprocket)38 void ChTrackBrakeSimple::Initialize(std::shared_ptr<ChChassis> chassis, std::shared_ptr<ChSprocket> sprocket) {
39     auto hub = sprocket->GetRevolute();
40     auto sys = hub->GetSystem();
41 
42     // Reuse the same bodies and link coordinate of the hub revolute joint.
43     // Note that we wrap raw pointers in local shared_ptr.  For this, we must provide
44     // custom empty deleters (to prevent deleting the objects when the local shared_ptr
45     // go out of scope).
46     std::shared_ptr<ChBodyFrame> mbf1(hub->GetBody1(), [](ChBodyFrame*){});
47     std::shared_ptr<ChBodyFrame> mbf2(hub->GetBody2(), [](ChBodyFrame*){});
48 
49     // Downcast to ChBody shared_ptr
50     auto mb1 = std::dynamic_pointer_cast<ChBody>(mbf1);
51     auto mb2 = std::dynamic_pointer_cast<ChBody>(mbf2);
52 
53     m_brake->Initialize(mb1, mb2, true, hub->GetMarker1()->GetCoord(), hub->GetMarker2()->GetCoord());
54     sys->AddLink(m_brake);
55 }
56 
Synchronize(double braking)57 void ChTrackBrakeSimple::Synchronize(double braking) {
58     m_braking = braking;
59     m_brake->Set_brake_torque(braking * GetMaxBrakingTorque());
60 }
61 
62 }  // end namespace vehicle
63 }  // end namespace chrono
64