-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_13.cpp
More file actions
123 lines (94 loc) · 3.38 KB
/
Copy pathexample_13.cpp
File metadata and controls
123 lines (94 loc) · 3.38 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
#include "bitrl/bitrl_config.h"
#ifdef BITRL_CHRONO
#include "bitrl/bitrl_types.h"
#ifdef BITRL_LOG
#define BOOST_LOG_DYN_LINK
#include <boost/log/trivial.hpp>
#endif
#include "bitrl/bitrl_consts.h"
#include "chrono/core/ChRealtimeStep.h"
#include "chrono/physics/ChSystemNSC.h"
#include <chrono/physics/ChBodyEasy.h>
#include <chrono_irrlicht/ChVisualSystemIrrlicht.h>
#include "bitrl/rigid_bodies/chrono_robots/diff_drive_robot.h"
#include <filesystem>
#include <string>
namespace example_13
{
using namespace bitrl;
using namespace chrono::irrlicht;
// constants we will be using further below
const uint_t WINDOW_HEIGHT = 800;
const uint_t WINDOW_WIDTH = 1024;
const real_t DT = 0.01;
const real_t SIM_TIME = 5.0;
const std::string WINDOW_TITLE( "Example 13");
void prepare_visualization(chrono::irrlicht::ChVisualSystemIrrlicht& visual)
{
visual.SetWindowSize(WINDOW_WIDTH, WINDOW_WIDTH); //WINDOW_HEIGHT);
visual.SetWindowTitle(WINDOW_TITLE);
visual.Initialize();
visual.AddLogo();
visual.AddSkyBox();
visual.AddCamera({0, -2, 1}, {0, 0, 0});
visual.AddTypicalLights();
visual.BindAll();
}
} // namespace example_13
int main()
{
using namespace example_13;
chrono::ChSystemNSC sys;
sys.SetGravitationalAcceleration(chrono::ChVector3d(0, 0, -9.81));
sys.SetCollisionSystemType(chrono::ChCollisionSystem::Type::BULLET);
chrono::ChCollisionModel::SetDefaultSuggestedEnvelope(0.0025);
chrono::ChCollisionModel::SetDefaultSuggestedMargin(0.0025);
auto floor_mat = chrono_types::make_shared<chrono::ChContactMaterialNSC>();
auto mfloor = chrono_types::make_shared<chrono::ChBodyEasyBox>(20, 20, 1, 1000, true, true, floor_mat);
mfloor->SetPos(chrono::ChVector3d(0, 0, -1));
mfloor->SetFixed(true);
mfloor->GetVisualShape(0)->SetTexture(chrono::GetChronoDataFile("textures/concrete.jpg"));
sys.Add(mfloor);
bitrl::rb::bitrl_chrono::CHRONO_DiffDriveRobot robot(sys,
chrono::ChVector3d(0, 0, -0.45), chrono::QUNIT);
robot.init();
robot.set_motor_speed(bitrl::consts::maths::PI, 0);
robot.set_motor_speed(bitrl::consts::maths::PI, 1);
chrono::irrlicht::ChVisualSystemIrrlicht visual;
prepare_visualization(visual);
visual.AttachSystem(&sys);
// Simulation loop
// Timer for enforcing soft real-time
chrono::ChRealtimeStepTimer realtime_timer;
// bool removed = false;
while (visual.Run()) {
// Irrlicht must prepare frame to draw
visual.BeginScene();
// Irrlicht now draws simple lines in 3D world representing a
// skeleton of the mechanism, in this instant:
//
// .. draw items belonging to Irrlicht scene, if any
visual.Render();
// .. draw a grid
tools::drawGrid(&visual, 0.5, 0.5);
// .. draw GUI items belonging to Irrlicht screen, if any
visual.GetGUIEnvironment()->drawAll();
// ADVANCE SYSTEM STATE BY ONE STEP
sys.DoStepDynamics(DT);
// Enforce soft real-time
realtime_timer.Spin(DT);
// Irrlicht must finish drawing the frame
visual.EndScene();
}
return 0;
}
#else
#include <iostream>
int main()
{
std::cerr<<"You need PROJECTCHRONO configured with "
<<"bitrl in order to run this example "
<<"Reconfigure bitrl and set ENABLE_CHRONO=ON"<<std::endl;
return 1;
}
#endif