Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <mvsim/VehicleBase.h>
00011 #include <mvsim/Sensors/LaserScanner.h>
00012
00013 #include <rapidxml.hpp>
00014 #include <rapidxml_utils.hpp>
00015 #include <rapidxml_print.hpp>
00016 #if MRPT_VERSION>=0x199
00017 #include <mrpt/core/format.h>
00018 #else
00019 #include <mrpt/utils/utils_defs.h>
00020 #endif
00021
00022 #include <sstream>
00023 #include <map>
00024 #include <string>
00025
00026 using namespace mvsim;
00027
00028 TClassFactory_sensors mvsim::classFactory_sensors;
00029
00030
00031
00032 void register_all_sensors()
00033 {
00034 static bool done = false;
00035 if (done)
00036 return;
00037 else
00038 done = true;
00039
00040 REGISTER_SENSOR("laser", LaserScanner)
00041 }
00042
00043 SensorBase::SensorBase(VehicleBase& vehicle)
00044 : VisualObject(vehicle.getWorldObject()),
00045 m_sensor_period(0.1),
00046 m_vehicle(vehicle),
00047 m_sensor_last_timestamp(0)
00048 {
00049 }
00050
00051 SensorBase::~SensorBase() {}
00052 SensorBase* SensorBase::factory(
00053 VehicleBase& parent, const rapidxml::xml_node<char>* root)
00054 {
00055 register_all_sensors();
00056
00057 using namespace std;
00058 using namespace rapidxml;
00059
00060 if (!root) throw runtime_error("[SensorBase::factory] XML node is NULL");
00061 if (0 != strcmp(root->name(), "sensor"))
00062 throw runtime_error(
00063 mrpt::format(
00064 "[SensorBase::factory] XML root element is '%s' ('sensor' "
00065 "expected)",
00066 root->name()));
00067
00068
00069 const xml_attribute<>* sensor_class = root->first_attribute("class");
00070 if (!sensor_class || !sensor_class->value())
00071 throw runtime_error(
00072 "[VehicleBase::factory] Missing mandatory attribute 'class' in "
00073 "node <sensor>");
00074
00075 const string sName = string(sensor_class->value());
00076
00077
00078 SensorBase* we = classFactory_sensors.create(sName, parent, root);
00079
00080 if (!we)
00081 throw runtime_error(
00082 mrpt::format(
00083 "[SensorBase::factory] Unknown sensor type '%s'",
00084 root->name()));
00085
00086 return we;
00087 }