Wheel.cpp
Go to the documentation of this file.
1 /*+-------------------------------------------------------------------------+
2  | MultiVehicle simulator (libmvsim) |
3  | |
4  | Copyright (C) 2014 Jose Luis Blanco Claraco (University of Almeria) |
5  | Copyright (C) 2017 Borys Tymchenko (Odessa Polytechnic University) |
6  | Distributed under GNU General Public License version 3 |
7  | See <http://www.gnu.org/licenses/> |
8  +-------------------------------------------------------------------------+ */
9 
10 #include <mvsim/Wheel.h>
11 #include <mrpt/opengl/CSetOfObjects.h>
12 #include <mrpt/opengl/CCylinder.h>
13 #include <mrpt/opengl/stock_objects.h>
14 #include <rapidxml.hpp>
15 
16 #include "xml_utils.h"
17 
18 #include <mrpt/version.h>
19 #if MRPT_VERSION<0x199
20 #include <mrpt/utils/TColor.h>
21 using mrpt::utils::TColor;
22 using mrpt::utils::TColorf;
23 using mrpt::utils::DEG2RAD;
24 #else
25 #include <mrpt/img/TColor.h>
26 using mrpt::img::TColor;
27 using mrpt::img::TColorf;
28 using mrpt::DEG2RAD;
29 #endif
30 
31 
32 using namespace mvsim;
33 using namespace std;
34 
36  : x(.0),
37  y(-.5),
38  yaw(.0),
39  diameter(.4),
40  width(.2),
41  mass(2.0),
42  Iyy(1.0),
43  color(0xff323232),
44  phi(.0),
45  w(.0)
46 {
47  recalcInertia();
48 }
49 
50 void Wheel::getAs3DObject(mrpt::opengl::CSetOfObjects& obj)
51 {
52  obj.clear();
53 
54  auto gl_wheel = mrpt::opengl::CCylinder::Create(
55  0.5 * diameter, 0.5 * diameter, this->width, 15, 1);
56  gl_wheel->setColor(TColorf(color));
57  gl_wheel->setPose(
58  mrpt::poses::CPose3D(
59  0, 0.5 * width, 0, 0, 0, DEG2RAD(90)));
60 
61  auto gl_wheel_frame = mrpt::opengl::CSetOfObjects::Create();
62  gl_wheel_frame->insert(gl_wheel);
63  {
64  mrpt::opengl::CSetOfObjects::Ptr gl_xyz =
65  mrpt::opengl::stock_objects::CornerXYZSimple(0.9 * diameter, 2.0);
66  gl_wheel_frame->insert(gl_xyz);
67  }
68 
69  obj.setPose(mrpt::math::TPose3D(x, y, 0.5 * diameter, yaw, 0.0, 0.0));
70 
71  obj.insert(gl_wheel_frame);
72 }
73 
75 {
76  ASSERT_(xml_node);
77  // Parse attributes:
78  // <l_wheel pos="0.0 -0.5 [OPTIONAL_ANG]" mass="2.0" width="0.10"
79  // diameter="0.30" />
80  // pos:
81  {
82  const rapidxml::xml_attribute<char>* attr =
83  xml_node->first_attribute("pos");
84  if (attr && attr->value())
85  {
86  const std::string sAttr = attr->value();
87  vec3 v = parseXYPHI(sAttr, true);
88  this->x = v.vals[0];
89  this->y = v.vals[1];
90  this->yaw = v.vals[2];
91  }
92  }
93 
94  // Detect if inertia is manually set:
95  const double INERTIA_NOT_SET = -1.;
96  this->Iyy = INERTIA_NOT_SET;
97 
98  std::map<std::string, TParamEntry> attribs;
99  attribs["mass"] = TParamEntry("%lf", &this->mass);
100  attribs["width"] = TParamEntry("%lf", &this->width);
101  attribs["diameter"] = TParamEntry("%lf", &this->diameter);
102  attribs["color"] = TParamEntry("%color", &this->color);
103  attribs["inertia"] = TParamEntry("%lf", &this->Iyy);
104 
105  parse_xmlnode_attribs(*xml_node, attribs, "[Wheel]");
106 
107  // If not manually overrided, calc automatically:
108  if (Iyy == INERTIA_NOT_SET) this->recalcInertia();
109 }
110 
111 // Recompute Iyy from mass, diameter and height.
113 {
114  // Iyy = m*r^2 / 2
115  Iyy = mass * (0.25 * diameter * diameter) * 0.5;
116 }
This file contains rapidxml parser and DOM implementation.
double width
Length(diameter) and width of the wheel rectangle [m].
Definition: Wheel.h:43
Ch * value() const
Definition: rapidxml.hpp:692
void recalcInertia()
Recompute Iyy from mass, diameter and height.
Definition: Wheel.cpp:112
double vals[3]
Definition: basic_types.h:64
void loadFromXML(const rapidxml::xml_node< char > *xml_node)
Definition: Wheel.cpp:74
TColor color
constructor and at loadFromXML(), but can be overrided.
Definition: Wheel.h:48
void getAs3DObject(mrpt::opengl::CSetOfObjects &obj)
Definition: Wheel.cpp:50
TFSIMD_FORCE_INLINE const tfScalar & y() const
double x
Definition: Wheel.h:41
void parse_xmlnode_attribs(const rapidxml::xml_node< char > &xml_node, const std::map< std::string, TParamEntry > &params, const char *function_name_context="")
Definition: xml_utils.cpp:160
double y
Definition: Wheel.h:41
double diameter
[m,rad] (in local coords)
Definition: Wheel.h:43
xml_attribute< Ch > * first_attribute(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
Definition: rapidxml.hpp:1025
TFSIMD_FORCE_INLINE const tfScalar & x() const
double yaw
Definition: Wheel.h:41
vec3 parseXYPHI(const std::string &s, bool allow_missing_angle=false, double default_angle_radians=0.0)
Definition: xml_utils.cpp:214
double Iyy
Definition: Wheel.h:46
TFSIMD_FORCE_INLINE const tfScalar & w() const
double mass
[kg]
Definition: Wheel.h:45


mvsim
Author(s):
autogenerated on Thu Jun 6 2019 19:36:40