5 #if MRPT_VERSION >= 0x199 6 #include <mrpt/serialization/CArchive.h> 7 #include <mrpt/config/CConfigFile.h> 8 using mrpt::config::CConfigFile;
17 GenericSensorNode::GenericSensorNode() {}
19 GenericSensorNode::~GenericSensorNode() {}
21 void GenericSensorNode::init(
int argc,
char** argv)
26 nhlocal_.getParam(
"config_file", cfgfilename_);
27 nhlocal_.getParam(
"config_section", cfg_section_);
31 std::string driver_name =
32 iniFile.
read_string(cfg_section_,
"driver",
"",
true);
37 "Sensor class name not recognized: " << driver_name);
42 sensor_->loadConfig(iniFile, cfg_section_);
45 sensor_->initialize();
48 this->init_sensor_specific();
51 if (!out_rawlog_prefix_.empty())
55 std::string rawlog_postfix =
"_";
61 "%04u-%02u-%02u_%02uh%02um%02us", (
unsigned int)parts.
year,
62 (
unsigned int)parts.
month, (
unsigned int)parts.
day,
63 (
unsigned int)parts.
hour, (
unsigned int)parts.
minute,
64 (
unsigned int)parts.
second);
69 const std::string fil = out_rawlog_prefix_ + rawlog_postfix;
71 ROS_INFO(
"Writing rawlog to file: `%s`", fil.c_str());
73 out_rawlog_.open(fil, rawlog_GZ_compress_level_);
75 if (!out_rawlog_.is_open())
76 ROS_ERROR(
"Error opening output rawlog for writing");
79 catch (std::exception& e)
82 "Exception in GenericSensorNode::init(): " << e.what());
88 void GenericSensorNode::run()
90 ROS_INFO(
"Starting run() at %.02f Hz", sensor_->getProcessRate());
93 ROS_ERROR(
"Aborting: sensor object was not properly initialized.");
96 ros::Rate loop_rate(sensor_->getProcessRate());
103 sensor_->getObservations(lstObjs);
105 if (out_rawlog_.is_open())
107 #if MRPT_VERSION >= 0x199 108 auto out_arch = mrpt::serialization::archiveFrom(out_rawlog_);
110 auto& out_arch = out_rawlog_;
112 for (
const auto& o : lstObjs)
114 out_arch << *o.second;
void BASE_IMPEXP timestampToParts(TTimeStamp t, TTimeParts &p, bool localTime=false)
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
mrpt::system::TTimeStamp now()
static CGenericSensorPtr createSensorPtr(const std::string &className)
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
std::string BASE_IMPEXP fileNameStripInvalidChars(const std::string &filename, const char replacement_to_invalid_chars= '_')
#define ROS_ERROR_STREAM(args)
ROSCPP_DECL void spinOnce()
std::multimap< mrpt::system::TTimeStamp, mrpt::utils::CSerializablePtr > TListObservations