|
7 | 7 | * |
8 | 8 | */ |
9 | 9 |
|
| 10 | +#include "bitrl/bitrl_config.h" |
| 11 | + |
| 12 | +#ifdef BITRL_CHRONO |
| 13 | + |
10 | 14 | #include "bitrl/bitrl_types.h" |
| 15 | + |
| 16 | +#ifdef BITRL_LOG |
| 17 | +#define BOOST_LOG_DYN_LINK |
| 18 | +#include <boost/log/trivial.hpp> |
| 19 | +#endif |
| 20 | + |
| 21 | +#include <chrono/physics/ChSystemSMC.h> |
| 22 | +#include <chrono/physics/ChBodyEasy.h> |
| 23 | +#include <chrono_irrlicht/ChVisualSystemIrrlicht.h> |
| 24 | + |
| 25 | + |
11 | 26 | #include "bitrl/utils/geometry/geom_point.h" |
12 | 27 | #include "bitrl/utils/trajectory/line_segment_link.h" |
13 | 28 | #include "bitrl/utils/trajectory/waypoint.h" |
|
24 | 39 | namespace example_11 |
25 | 40 | { |
26 | 41 |
|
27 | | -using bitrl::Null; |
28 | | -using bitrl::real_t; |
29 | | -using bitrl::uint_t; |
30 | | -using bitrl::utils::geom::GeomPoint; |
31 | | -using bitrl::utils::trajectory::LineSegmentLink; |
32 | | -using bitrl::utils::trajectory::WayPoint; |
33 | | -using bitrl::utils::trajectory::WaypointTrajectory; |
| 42 | +using namespace bitrl; |
| 43 | +using namespace chrono::irrlicht; |
| 44 | + |
| 45 | +// constants we will be using further below |
| 46 | +const uint_t WINDOW_HEIGHT = 800; |
| 47 | +const uint_t WINDOW_WIDTH = 1024; |
| 48 | +const real_t DT = 0.0001; |
| 49 | +const real_t SIM_TIME = 5.0; |
| 50 | +const std::string WINDOW_TITLE( "Example 11"); |
34 | 51 |
|
35 | | -struct LineSegmentData |
| 52 | +void prepare_visualization(chrono::irrlicht::ChVisualSystemIrrlicht& visual) |
| 53 | +{ |
| 54 | + visual.SetWindowSize(WINDOW_WIDTH, WINDOW_WIDTH); //WINDOW_HEIGHT); |
| 55 | + visual.SetWindowTitle(WINDOW_TITLE); |
| 56 | + visual.Initialize(); |
| 57 | + |
| 58 | + visual.AddLogo(); |
| 59 | + visual.AddSkyBox(); |
| 60 | + visual.AddCamera({0, -2, 1}, {0, 0, 0}); |
| 61 | + visual.AddTypicalLights(); |
| 62 | + visual.BindAll(); |
| 63 | +} |
| 64 | + |
| 65 | +std::shared_ptr<chrono::ChBody> create_box(real_t xlength, real_t ylength, real_t zlength, |
| 66 | + real_t density, bool create_visualization) |
36 | 67 | { |
37 | | - /// \brief The maximum velocity |
38 | | - /// allowed on the edge |
39 | | - real_t Vmax{0.0}; |
40 | 68 |
|
41 | | - /// \brief The orientation of the |
42 | | - /// segment with respect to the global coordinate |
43 | | - /// frame. This may also dictate the orientation |
44 | | - /// that a reference vehicle may have on the segment |
45 | | - real_t theta{0.0}; |
| 69 | + // build the chassis of the robot |
| 70 | + auto box = chrono_types::make_shared<chrono::ChBodyEasyBox>(xlength, ylength, zlength, |
| 71 | + density, create_visualization); |
| 72 | + box -> SetMass(1.0); |
| 73 | + box -> SetPos(chrono::ChVector3d(0.0, 0.0, 0.22)); |
| 74 | + |
| 75 | + // allow the chassis to move |
| 76 | + box -> SetFixed(true); |
| 77 | + return box; |
| 78 | + |
| 79 | +} |
46 | 80 |
|
47 | | - /// \brief The angular velocity on the segment |
48 | | - real_t w{0.0}; |
49 | 81 |
|
50 | | - /// \brief The linear velocity on the segement |
51 | | - real_t v{0.0}; |
52 | | -}; |
53 | 82 |
|
54 | | -typedef LineSegmentLink<2, Null, LineSegmentData> link_type; |
55 | | -typedef link_type::w_point_type w_point_type; |
56 | 83 |
|
57 | 84 | } // namespace example_11 |
58 | 85 |
|
| 86 | +/* |
59 | 87 | int main() |
60 | 88 | { |
61 | 89 |
|
62 | 90 | using namespace example_11; |
| 91 | + chrono::ChSystemSMC sys; |
63 | 92 |
|
64 | | - // create a trajector of 4 links |
65 | | - // the waypoints carry not data |
66 | | - // but the the links |
67 | | - // carry objects of type LineSegmentData |
68 | | - WaypointTrajectory<link_type> trajectory(3); |
| 93 | + // build the body and add it to the system |
| 94 | + // we want to simulate |
| 95 | + auto box = create_box(1.0, 1.0, 1.0, 1.0, true); |
| 96 | + sys.Add(box); |
69 | 97 |
|
70 | | - // start adding the links |
71 | | - // that form the trajectory |
72 | | - w_point_type p0(GeomPoint<2>({0.0, 0.0}), static_cast<uint_t>(0)); |
73 | | - w_point_type p1(GeomPoint<2>({1.0, 0.0}), static_cast<uint_t>(1)); |
74 | | - LineSegmentData data{1.0, 0.0, 0.0, 0.95}; |
| 98 | + // create the object that handles the visualization |
| 99 | + chrono::irrlicht::ChVisualSystemIrrlicht visual; |
| 100 | + prepare_visualization(visual); |
| 101 | + visual.AttachSystem(&sys); |
75 | 102 |
|
76 | | - link_type l0(p0, p1, static_cast<uint_t>(0), data); |
77 | | - |
78 | | - w_point_type p2(GeomPoint<2>({1.0, 0.0}), static_cast<uint_t>(2)); |
79 | | - w_point_type p3(GeomPoint<2>({2.0, 2.0}), static_cast<uint_t>(3)); |
80 | | - data.theta = bitrl::utils::unit_converter::degrees_to_rad(45.0); |
81 | | - link_type l1(p2, p3, static_cast<uint_t>(1), data); |
| 103 | + while (visual.Run()) |
| 104 | + { |
82 | 105 |
|
83 | | - w_point_type p4(GeomPoint<2>({2.0, 2.0}), static_cast<uint_t>(4)); |
84 | | - w_point_type p5(GeomPoint<2>({2.0, 3.0}), static_cast<uint_t>(5)); |
85 | | - data.theta = bitrl::utils::unit_converter::degrees_to_rad(90.0); |
86 | | - link_type l2(p2, p3, static_cast<uint_t>(2), data); |
| 106 | + // Irrlicht must prepare frame to draw |
| 107 | + visual.BeginScene(); |
87 | 108 |
|
88 | | - trajectory[0] = l0; |
89 | | - trajectory[1] = l1; |
90 | | - trajectory[2] = l2; |
| 109 | + // .. draw items belonging to Irrlicht scene, if any |
| 110 | + visual.Render(); |
91 | 111 |
|
92 | | - std::cout << "Trajectory number of links: " << trajectory.size() << std::endl; |
| 112 | + // .. draw a grid |
| 113 | + tools::drawGrid(&visual, 0.5, 0.5); |
93 | 114 |
|
94 | | - for (const auto &link : trajectory) |
95 | | - { |
96 | | - std::cout << link.get_id() << std::endl; |
| 115 | + // Irrlicht must finish drawing the frame |
| 116 | + visual.EndScene(); |
97 | 117 | } |
98 | | - return 0; |
| 118 | +
|
| 119 | +}*/ |
| 120 | + |
| 121 | +int main() |
| 122 | +{ |
| 123 | + |
| 124 | + using namespace example_11; |
| 125 | + chrono::ChSystemSMC sys; |
| 126 | + |
| 127 | + // build the body and add it to the system |
| 128 | + // we want to simulate |
| 129 | + auto box = create_box(1.0, 1.0, 1.0, 1.0, true); |
| 130 | + sys.Add(box); |
| 131 | + |
| 132 | + auto position = box -> GetPos(); |
| 133 | + BOOST_LOG_TRIVIAL(info)<<"Position of CoM: "<<position; |
| 134 | + BOOST_LOG_TRIVIAL(info)<<"Linear velocity of CoM: "<<box -> GetLinVel(); |
| 135 | + auto pos_local = box->TransformPointParentToLocal(position); |
| 136 | + BOOST_LOG_TRIVIAL(info)<<"local position of CoM: "<<pos_local; |
99 | 137 | } |
| 138 | +#else |
| 139 | +#include <iostream> |
| 140 | +int main() |
| 141 | +{ |
| 142 | + std::cerr<<"You need PROJECTCHRONO configured with " |
| 143 | + <<"bitrl in order to run this example " |
| 144 | + <<"Reconfigure bitrl and set ENABLE_CHRONO=ON"<<std::endl; |
| 145 | + return 1; |
| 146 | +} |
| 147 | + |
| 148 | +#endif |
0 commit comments