Wheel.cpp
Go to the documentation of this file.
00001 /*+-------------------------------------------------------------------------+
00002   |                       MultiVehicle simulator (libmvsim)                 |
00003   |                                                                         |
00004   | Copyright (C) 2014  Jose Luis Blanco Claraco (University of Almeria)    |
00005   | Copyright (C) 2017  Borys Tymchenko (Odessa Polytechnic University)     |
00006   | Distributed under GNU General Public License version 3                  |
00007   |   See <http://www.gnu.org/licenses/>                                    |
00008   +-------------------------------------------------------------------------+ */
00009 
00010 #include <mvsim/Wheel.h>
00011 #include <mrpt/opengl/CSetOfObjects.h>
00012 #include <mrpt/opengl/CCylinder.h>
00013 #include <mrpt/opengl/stock_objects.h>
00014 #include <rapidxml.hpp>
00015 
00016 #include "xml_utils.h"
00017 
00018 using namespace mvsim;
00019 using namespace std;
00020 
00021 Wheel::Wheel()
00022         : x(.0),
00023           y(-.5),
00024           yaw(.0),
00025           diameter(.4),
00026           width(.2),
00027           mass(2.0),
00028           Iyy(1.0),
00029           color(0xff323232),
00030           phi(.0),
00031           w(.0)
00032 {
00033         recalcInertia();
00034 }
00035 
00036 void Wheel::getAs3DObject(mrpt::opengl::CSetOfObjects& obj)
00037 {
00038         obj.clear();
00039 
00040         mrpt::opengl::CCylinder::Ptr gl_wheel =
00041                 mrpt::make_aligned_shared<mrpt::opengl::CCylinder>(
00042                         0.5 * diameter, 0.5 * diameter, this->width, 15, 1);
00043         gl_wheel->setColor(mrpt::utils::TColorf(color));
00044         gl_wheel->setPose(
00045                 mrpt::poses::CPose3D(
00046                         0, 0.5 * width, 0, 0, 0, mrpt::utils::DEG2RAD(90)));
00047 
00048         mrpt::opengl::CSetOfObjects::Ptr gl_wheel_frame =
00049                 mrpt::make_aligned_shared<mrpt::opengl::CSetOfObjects>();
00050         gl_wheel_frame->insert(gl_wheel);
00051         {
00052                 mrpt::opengl::CSetOfObjects::Ptr gl_xyz =
00053                         mrpt::opengl::stock_objects::CornerXYZSimple(0.9 * diameter, 2.0);
00054                 gl_wheel_frame->insert(gl_xyz);
00055         }
00056 
00057         obj.setPose(mrpt::math::TPose3D(x, y, 0.5 * diameter, yaw, 0.0, 0.0));
00058 
00059         obj.insert(gl_wheel_frame);
00060 }
00061 
00062 void Wheel::loadFromXML(const rapidxml::xml_node<char>* xml_node)
00063 {
00064         ASSERT_(xml_node)
00065         // Parse attributes:
00066         // <l_wheel pos="0.0 -0.5 [OPTIONAL_ANG]" mass="2.0" width="0.10"
00067         // diameter="0.30" />
00068         // pos:
00069         {
00070                 const rapidxml::xml_attribute<char>* attr =
00071                         xml_node->first_attribute("pos");
00072                 if (attr && attr->value())
00073                 {
00074                         const std::string sAttr = attr->value();
00075                         vec3 v = parseXYPHI(sAttr, true);
00076                         this->x = v.vals[0];
00077                         this->y = v.vals[1];
00078                         this->yaw = v.vals[2];
00079                 }
00080         }
00081 
00082         // Detect if inertia is manually set:
00083         const double INERTIA_NOT_SET = -1.;
00084         this->Iyy = INERTIA_NOT_SET;
00085 
00086         std::map<std::string, TParamEntry> attribs;
00087         attribs["mass"] = TParamEntry("%lf", &this->mass);
00088         attribs["width"] = TParamEntry("%lf", &this->width);
00089         attribs["diameter"] = TParamEntry("%lf", &this->diameter);
00090         attribs["color"] = TParamEntry("%color", &this->color);
00091         attribs["inertia"] = TParamEntry("%lf", &this->Iyy);
00092 
00093         parse_xmlnode_attribs(*xml_node, attribs, "[Wheel]");
00094 
00095         // If not manually overrided, calc automatically:
00096         if (Iyy == INERTIA_NOT_SET) this->recalcInertia();
00097 }
00098 
00099 // Recompute Iyy from mass, diameter and height.
00100 void Wheel::recalcInertia()
00101 {
00102         // Iyy = m*r^2 / 2
00103         Iyy = mass * (0.25 * diameter * diameter) * 0.5;
00104 }


mvsim
Author(s):
autogenerated on Thu Sep 7 2017 09:27:48