-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrover_simulation.cpp
More file actions
142 lines (109 loc) · 5.45 KB
/
rover_simulation.cpp
File metadata and controls
142 lines (109 loc) · 5.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// =============================================================================
// PROJECT CHRONO - http://projectchrono.org
//
// Copyright (c) 2014 projectchrono.org
// All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found
// in the LICENSE file at the top level of the distribution and at
// http://projectchrono.org/license-chrono.txt.
//
// =============================================================================
// A very simple example that can be used as template project for
// a Chrono::Engine simulator with 3D view.
// =============================================================================
#include "chrono/physics/ChSystemNSC.h"
#include "chrono/physics/ChBodyEasy.h"
#include "chrono/physics/ChLinkMate.h"
#include "chrono/assets/ChTexture.h"
#include "chrono/assets/ChColorAsset.h"
#include "chrono_irrlicht/ChIrrApp.h"
// Use the namespace of Chrono
using namespace chrono;
using namespace chrono::irrlicht;
// Use the main namespaces of Irrlicht
using namespace irr;
using namespace irr::core;
using namespace irr::scene;
using namespace irr::video;
using namespace irr::io;
using namespace irr::gui;
int main(int argc, char* argv[]) {
// Set path to Chrono data directory
SetChronoDataPath(CHRONO_DATA_DIR);
// Create a Chrono physical system
ChSystemNSC mphysicalSystem;
// Create the Irrlicht visualization (open the Irrlicht device,
// bind a simple user interface, etc. etc.)
ChIrrApp application(&mphysicalSystem, L"A simple project template", core::dimension2d<u32>(1920, 1080),
false); // screen dimensions
// Easy shortcuts to add camera, lights, logo and sky in Irrlicht scene:
application.AddTypicalLights();
application.AddTypicalCamera(core::vector3df(2, 2, -5),
core::vector3df(0, 1, 0)); // to change the position of camera
// application.AddLightWithShadow(vector3df(1,25,-5), vector3df(0,0,0), 35, 0.2,35, 55, 512, video::SColorf(1,1,1));
//======================================================================
// HERE YOU CAN POPULATE THE PHYSICAL SYSTEM WITH BODIES AND LINKS.
//
// An example: a pendulum.
// 1-Create a floor that is fixed (that is used also to represent the absolute reference)
auto floorBody = std::make_shared<ChBodyEasyBox>(10, 2, 10, // x, y, z dimensions
3000, // density
false, // no contact geometry
false // enable visualization geometry
);
floorBody->SetPos(ChVector<>(0, -2, 0));
floorBody->SetBodyFixed(true);
mphysicalSystem.Add(floorBody);
// 2-Create a pendulum
auto pendulumBody = std::make_shared<ChBodyEasyBox>(0.5, 2, 0.5, // x, y, z dimensions
3000, // density
false, // no contact geometry
true // enable visualization geometry
);
pendulumBody->SetPos(ChVector<>(0, 3, 0));
pendulumBody->SetPos_dt(ChVector<>(1, 0, 0));
mphysicalSystem.Add(pendulumBody);
// 3-Create a spherical constraint.
// Here we'll use a ChLinkMateGeneric, but we could also use ChLinkLockSpherical
auto sphericalLink =
std::make_shared<ChLinkMateGeneric>(true, true, true, false, false, false); // x,y,z,Rx,Ry,Rz constrains
ChFrame<> link_position_abs(ChVector<>(0, 4, 0));
sphericalLink->Initialize(pendulumBody, // the 1st body to connect
floorBody, // the 2nd body to connect
false, // the two following frames are in absolute, not relative, coords.
link_position_abs, // the link reference attached to 1st body
link_position_abs); // the link reference attached to 2nd body
mphysicalSystem.Add(sphericalLink);
// Optionally, attach a RGB color asset to the floor, for better visualization
auto color = std::make_shared<ChColorAsset>();
color->SetColor(ChColor(0.2f, 0.25f, 0.25f));
floorBody->AddAsset(color);
// Optionally, attach a texture to the pendulum, for better visualization
auto texture = std::make_shared<ChTexture>();
texture->SetTextureFilename(GetChronoDataFile("rock.jpg")); // texture in ../data
pendulumBody->AddAsset(texture);
//======================================================================
// Use this function for adding a ChIrrNodeAsset to all items
// Otherwise use application.AssetBind(myitem); on a per-item basis.
application.AssetBindAll();
// Use this function for 'converting' assets into Irrlicht meshes
application.AssetUpdateAll();
// Adjust some settings:
application.SetTimestep(0.005);
application.SetTryRealtime(false);
//
// THE SOFT-REAL-TIME CYCLE
//
int i = 0;
while (application.GetDevice()->run()) {
application.BeginScene();
application.DrawAll();
// This performs the integration timestep!
application.DoStep();
std::cout << "Step number" << i << std::endl;
i++;
application.EndScene();
}
return 0;
}