Wheel.cpp
Go to the documentation of this file.
1 /*+-------------------------------------------------------------------------+
2  | MultiVehicle simulator (libmvsim) |
3  | |
4  | Copyright (C) 2014-2020 Jose Luis Blanco Claraco |
5  | Copyright (C) 2017 Borys Tymchenko (Odessa Polytechnic University) |
6  | Distributed under 3-clause BSD License |
7  | See COPYING |
8  +-------------------------------------------------------------------------+ */
9 
10 #include <mrpt/img/TColor.h>
11 #include <mrpt/opengl/CCylinder.h>
14 #include <mvsim/Wheel.h>
15 
16 #include <rapidxml.hpp>
17 
18 #include "xml_utils.h"
19 
20 using namespace mvsim;
21 using namespace std;
22 
23 Wheel::Wheel() { recalcInertia(); }
24 
26 {
27  obj.clear();
28 
29  auto gl_wheel = mrpt::opengl::CCylinder::Create(
30  0.5 * diameter, 0.5 * diameter, this->width, 15);
31  gl_wheel->setColor_u8(color);
32  gl_wheel->setPose(
33  mrpt::poses::CPose3D(0, 0.5 * width, 0, 0, 0, mrpt::DEG2RAD(90)));
34 
35  auto gl_wheel_frame = mrpt::opengl::CSetOfObjects::Create();
36  gl_wheel_frame->insert(gl_wheel);
37  {
38  mrpt::opengl::CSetOfObjects::Ptr gl_xyz =
40  gl_wheel_frame->insert(gl_xyz);
41  }
42 
43  obj.setPose(mrpt::math::TPose3D(x, y, 0.5 * diameter, yaw, 0.0, 0.0));
44 
45  obj.insert(gl_wheel_frame);
46 }
47 
49 {
50  ASSERT_(xml_node);
51  // Parse attributes:
52  // <l_wheel pos="0.0 -0.5 [OPTIONAL_ANG]" mass="2.0" width="0.10"
53  // diameter="0.30" />
54  // pos:
55  {
56  const rapidxml::xml_attribute<char>* attr =
57  xml_node->first_attribute("pos");
58  if (attr && attr->value())
59  {
60  const std::string sAttr = attr->value();
61  mrpt::math::TPose2D v = parseXYPHI(sAttr, true);
62  this->x = v.x;
63  this->y = v.y;
64  this->yaw = v.phi;
65  }
66  }
67 
68  // Detect if inertia is manually set:
69  const double INERTIA_NOT_SET = -1.;
70  this->Iyy = INERTIA_NOT_SET;
71 
72  parse_xmlnode_attribs(*xml_node, m_params, {}, "[Wheel]");
73 
74  // If not manually overrided, calc automatically:
75  if (Iyy == INERTIA_NOT_SET) this->recalcInertia();
76 }
77 
78 // Recompute Iyy from mass, diameter and height.
80 {
81  // Iyy = m*r^2 / 2
82  Iyy = mass * (0.25 * diameter * diameter) * 0.5;
83 }
const GLdouble * v
This file contains rapidxml parser and DOM implementation.
GLint GLint GLint GLint GLint GLint y
Ch * value() const
Definition: rapidxml.hpp:692
void recalcInertia()
Recompute Iyy from mass, diameter and height.
Definition: Wheel.cpp:79
void loadFromXML(const rapidxml::xml_node< char > *xml_node)
Definition: Wheel.cpp:48
void getAs3DObject(mrpt::opengl::CSetOfObjects &obj)
Definition: Wheel.cpp:25
void parse_xmlnode_attribs(const rapidxml::xml_node< char > &xml_node, const TParameterDefinitions &params, const std::map< std::string, std::string > &variableNamesValues={}, const char *functionNameContext="")
Definition: xml_utils.cpp:140
CSetOfObjectsPtr OPENGL_IMPEXP CornerXYZSimple(float scale=1.0, float lineWidth=1.0)
GLint GLint GLint GLint GLint x
GLhandleARB obj
GLuint color
xml_attribute< Ch > * first_attribute(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
Definition: rapidxml.hpp:1025
CRenderizable & setPose(const mrpt::poses::CPose3D &o)
#define ASSERT_(f)
static CCylinderPtr Create(const float baseRadius, const float topRadius, const float height=1, const int slices=10, const int stacks=10)
GLint GLint GLint GLint GLint GLint GLsizei width
void insert(const CRenderizablePtr &newObject)
mrpt::math::TPose2D parseXYPHI(const std::string &s, bool allow_missing_angle=false, double default_angle_radians=0.0)
Definition: xml_utils.cpp:198


mvsim
Author(s):
autogenerated on Fri May 7 2021 03:05:51