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