Main MRPT website > C++ reference for MRPT 1.9.9
test.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
15 #include <mrpt/system/filesystem.h>
17 #include <iostream>
18 
19 using namespace mrpt;
20 using namespace mrpt::system;
21 using namespace mrpt::obs;
22 using namespace std;
23 using namespace mrpt::config;
24 using namespace mrpt::io;
25 using namespace mrpt::math;
26 using namespace mrpt::serialization;
27 
28 int main(int argc, char** argv)
29 {
30  // Variables
31  string rawlog_file, sensorLabel;
32  int enoseID, sensorType, indexMonitoredSensor,
33  delay_value; // decimate_value, winNoise_size
35  bool have_estimation, apply_delay;
36 
37  // Load configuration:
38  if (mrpt::system::fileExists("./CONFIG_MOXmodel.ini"))
39  {
40  cout << "Using configuration from './CONFIG_MOXmodel.ini'" << endl;
41  CConfigFile conf("./CONFIG_MOXmodel.ini");
42 
43  rawlog_file = conf.read_string("", "rawlog_file", "", true);
44  sensorLabel = conf.read_string("", "sensorLabel", "Full_MCEnose", true);
45  enoseID = conf.read_int("", "enoseID", 0, true);
46  std::string sensorType_str =
47  conf.read_string("", "sensorType", "-1", true);
48  stringstream convert(sensorType_str);
49  convert >> std::hex >> sensorType;
50 
51  // Delays
52  apply_delay = conf.read_bool("", "apply_delay", false, true);
53  delay_value = conf.read_int("", "delay_value", 0, true);
54 
55  // MOX model parameters
56  MOSmodel.a_rise = conf.read_float("", "a_rise", 0.0, true);
57  MOSmodel.b_rise = conf.read_float("", "b_rise", 0.0, true);
58  MOSmodel.a_decay = conf.read_float("", "a_decay", 0.0, true);
59  MOSmodel.b_decay = conf.read_float("", "b_decay", 0.0, true);
60  MOSmodel.winNoise_size = conf.read_int("", "winNoise_size", 0, true);
61  MOSmodel.decimate_value = conf.read_int("", "decimate_value", 0, true);
62  // save_maplog = conf.read_bool("","save_maplog",false,true);
63 
64  indexMonitoredSensor = -1;
65  }
66  else
67  {
68  cout << "Configuration file (ini) cannot be found\n" << endl;
69  // If you are in VisualStudio, assure that the working directory in the
70  // project properties is correctly set
71  return -1;
72  }
73 
74  // Open Rawlogs
75  cout << "Processing Rawlog " << rawlog_file << endl;
76  cout << "Obtaining MOXmodel from " << sensorLabel << "(" << enoseID
77  << ") - sensor " << sensorType << endl;
78  CFileGZInputStream file_input;
79  CFileGZOutputStream file_output;
80 
81  file_input.open(rawlog_file);
82  file_output.open("MOX_model_output.rawlog");
83 
84  if (!file_input.fileOpenCorrectly() || !file_output.fileOpenCorrectly())
85  cout << "Error opening rawlog file" << endl;
86 
87  // Process rawlog
88  bool read = true;
89  while (read)
90  {
91  try
92  {
94  archiveFrom(file_input) >> o;
95 
96  if (o) // ASSERT_(o);
97  {
99  {
101  std::dynamic_pointer_cast<CObservationGasSensors>(o);
102 
103  // Correct delay on gas readings
104  if (apply_delay)
105  obs->timestamp =
106  obs->timestamp - delay_value * 10000000;
107 
108  if (obs->sensorLabel == sensorLabel)
109  {
110  //------------------------------------------------------
111  // Get reading from CH_i for gas distribution estimation
112  //------------------------------------------------------
113  float raw_reading;
114 
115  if (sensorType == 0)
116  { // compute the mean
117  raw_reading = math::mean(
118  obs->m_readings[enoseID].readingsVoltage);
119  }
120  else
121  {
122  // Get the reading of the specified sensorID
123  if (indexMonitoredSensor == -1)
124  {
125  // First reading, get the index according to
126  // sensorID
127  for (indexMonitoredSensor = 0;
128  indexMonitoredSensor <
129  (int)obs->m_readings[enoseID]
130  .sensorTypes.size();
131  indexMonitoredSensor++)
132  {
133  if (obs->m_readings[enoseID].sensorTypes.at(
134  indexMonitoredSensor) ==
135  std::vector<int>::value_type(
136  sensorType))
137  break;
138  }
139  }
140 
141  if (indexMonitoredSensor <
142  (int)obs->m_readings[enoseID]
143  .sensorTypes.size())
144  {
145  raw_reading =
146  obs->m_readings[enoseID].readingsVoltage.at(
147  indexMonitoredSensor);
148  }
149  else // Sensor especified not found, compute
150  // default mean value
151  {
152  cout << "sensorType not found. Computing the "
153  "mean value"
154  << endl;
155  raw_reading = math::mean(
156  obs->m_readings[enoseID].readingsVoltage);
157  }
158  }
159 
160  // Obtain MOX model output
161  TPose3D MOXmodel_pose =
162  obs->m_readings[enoseID].eNosePoseOnTheRobot;
163  float MOXmodel_estimation = raw_reading;
164  mrpt::system::TTimeStamp MOXmodel_timestamp =
165  obs->timestamp;
166 
167  have_estimation =
169  MOXmodel_estimation, MOXmodel_timestamp);
170 
171  if (have_estimation)
172  {
173  // Save as new obs
175  gd_est;
176  gd_est.hasTemperature = false;
177  gd_est.temperature = 0.0;
178  gd_est.isActive = false;
179  gd_est.sensorTypes.push_back(
180  0x0001); // indicates that is a MOXmodel output
181  gd_est.readingsVoltage.push_back(
182  MOXmodel_estimation);
183  gd_est.eNosePoseOnTheRobot = MOXmodel_pose;
184 
188  obs_GDM->sensorLabel = "GDM";
189  // modify timestamp to deal with the delay of the
190  // model
191  obs_GDM->timestamp = MOXmodel_timestamp;
192  obs_GDM->m_readings.push_back(gd_est);
193 
194  archiveFrom(file_output) << obs_GDM;
195  }
196  }
197  }
198 
199  // Save current sensor obs to the new Rawlog file
200  auto arch = archiveFrom(file_output);
201  arch << o;
202  }
203  }
204  catch (exception& e)
205  {
206  cout << "Exception: " << e.what() << endl;
207  file_input.close();
208  file_output.close();
209  read = false;
210  }
211  }
212 
213  return 0;
214 }
mrpt::obs::CObservationGasSensors::CMOSmodel::a_rise
float a_rise
tau = a*AMPLITUDE +b (linear relationship)
Definition: CObservationGasSensors.h:103
mrpt::config
Definition: config/CConfigFile.h:16
filesystem.h
ops_containers.h
mrpt::obs::CObservationGasSensors::CMOSmodel::b_rise
float b_rise
tau = a*AMPLITUDE +b (linear relationship)
Definition: CObservationGasSensors.h:105
mrpt::obs::CObservationGasSensors::TObservationENose::temperature
float temperature
Sensed temperature in Celcius (valid if hasTemperature=true only)
Definition: CObservationGasSensors.h:68
mrpt::obs::CObservation::sensorLabel
std::string sensorLabel
An arbitrary label that can be used to identify the sensor.
Definition: CObservation.h:62
mrpt::io
Definition: img/CImage.h:22
mrpt::serialization::CSerializable::Ptr
std::shared_ptr< CSerializable > Ptr
Definition: CSerializable.h:37
mrpt::obs::CObservationGasSensors::CMOSmodel::winNoise_size
size_t winNoise_size
The size of the mobile average window used to reduce noise on sensor reagings.
Definition: CObservationGasSensors.h:97
CObservationGasSensors.h
mrpt::math::mean
double mean(const CONTAINER &v)
Computes the mean value of a vector.
Definition: ops_containers.h:234
CConfigFile.h
CFileGZOutputStream.h
mrpt::obs::CObservationGasSensors::CMOSmodel
Declares a class within "CObservationGasSensors" that represents a set of gas concentration readings ...
Definition: CObservationGasSensors.h:90
mrpt::make_aligned_shared
std::shared_ptr< T > make_aligned_shared(Args &&... args)
Creates a shared_ptr with aligned memory via aligned_allocator_cpp11<>.
Definition: aligned_allocator.h:78
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::system::fileExists
bool fileExists(const std::string &fileName)
Test if a given file (or directory) exists.
Definition: filesystem.cpp:127
mrpt::obs::CObservationGasSensors::TObservationENose::sensorTypes
std::vector< int > sensorTypes
The kind of sensors in the array (size of "sensorTypes" is the same that the size of "readingsVoltage...
Definition: CObservationGasSensors.h:64
mrpt::obs
This namespace contains representation of robot actions and observations.
Definition: CParticleFilter.h:17
mrpt::system::TTimeStamp
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1,...
Definition: datetime.h:31
main
int main()
Definition: vision_stereo_rectify/test.cpp:78
mrpt::io::CFileGZInputStream::open
bool open(const std::string &fileName)
Opens the file for read.
Definition: CFileGZInputStream.cpp:36
mrpt::obs::CObservationGasSensors::TObservationENose::readingsVoltage
std::vector< float > readingsVoltage
The set of readings (in volts) from the array of sensors (size of "sensorTypes" is the same that the ...
Definition: CObservationGasSensors.h:53
mrpt::obs::CObservationGasSensors::TObservationENose::eNosePoseOnTheRobot
math::TPose3D eNosePoseOnTheRobot
The pose of the sensors on the robot.
Definition: CObservationGasSensors.h:50
mrpt::io::CFileGZInputStream
Transparently opens a compressed "gz" file and reads uncompressed data from it.
Definition: io/CFileGZInputStream.h:26
mrpt::io::CFileGZOutputStream
Saves data to a file and transparently compress the data using the given compression level.
Definition: io/CFileGZOutputStream.h:26
mrpt::io::CFileGZInputStream::close
void close()
Closes the file.
Definition: CFileGZInputStream.cpp:54
mrpt::obs::CObservationGasSensors::CMOSmodel::a_decay
float a_decay
tau = a*AMPLITUDE +b (linear relationship)
Definition: CObservationGasSensors.h:107
mrpt::obs::CObservationGasSensors::TObservationENose::isActive
bool isActive
True if the input to this chamber/enose is poluted air, False if clean air.
Definition: CObservationGasSensors.h:71
IS_CLASS
#define IS_CLASS(ptrObj, class_name)
Evaluates to true if the given pointer to an object (derived from mrpt::rtti::CObject) is of the give...
Definition: CObject.h:103
mrpt::math::TPose3D
Lightweight 3D pose (three spatial coordinates, plus three angular coordinates).
Definition: lightweight_geom_data.h:603
mrpt::obs::CObservationGasSensors::TObservationENose::hasTemperature
bool hasTemperature
Must be true for "temperature" to contain a valid measurement.
Definition: CObservationGasSensors.h:66
mrpt::serialization
Definition: aligned_serialization.h:14
mrpt::obs::CObservationGasSensors::TObservationENose
The structure for each e-nose.
Definition: CObservationGasSensors.h:38
mrpt::obs::CObservationGasSensors
Declares a class derived from "CObservation" that represents a set of readings from gas sensors.
Definition: CObservationGasSensors.h:27
mrpt::io::CFileGZOutputStream::fileOpenCorrectly
bool fileOpenCorrectly() const
Returns true if the file was open without errors.
Definition: CFileGZOutputStream.cpp:78
mrpt::io::CFileGZOutputStream::close
void close()
Close the file.
Definition: CFileGZOutputStream.cpp:46
mrpt::serialization::archiveFrom
CArchiveStreamBase< STREAM > archiveFrom(STREAM &s)
Helper function to create a templatized wrapper CArchive object for a: MRPT's CStream,...
Definition: CArchive.h:561
mrpt::io::CFileGZOutputStream::open
bool open(const std::string &fileName, int compress_level=1)
Open a file for write, choosing the compression level.
Definition: CFileGZOutputStream.cpp:32
mrpt::obs::CObservationGasSensors::CMOSmodel::b_decay
float b_decay
tau = a*AMPLITUDE +b (linear relationship)
Definition: CObservationGasSensors.h:109
mrpt::config::CConfigFile
This class allows loading and storing values and vectors of different types from "....
Definition: config/CConfigFile.h:33
CFileGZInputStream.h
mrpt::math
This base provides a set of functions for maths stuff.
Definition: math/include/mrpt/math/bits_math.h:13
string
GLsizei const GLchar ** string
Definition: glext.h:4101
mrpt::io::CFileGZInputStream::fileOpenCorrectly
bool fileOpenCorrectly() const
Returns true if the file was open without errors.
Definition: CFileGZInputStream.cpp:99
CArchive.h
mrpt::obs::CObservationGasSensors::CMOSmodel::get_GasDistribution_estimation
bool get_GasDistribution_estimation(float &reading, mrpt::system::TTimeStamp &timestamp)
Obtain an estimation of the gas distribution based on raw sensor readings
Definition: CObservationGasSensors.cpp:157
mrpt::obs::CObservationGasSensors::Ptr
std::shared_ptr< CObservationGasSensors > Ptr
Definition: CObservationGasSensors.h:29
mrpt::obs::CObservationGasSensors::CMOSmodel::decimate_value
int decimate_value
[useMOSmodel] The decimate frecuency applied after noise filtering
Definition: CObservationGasSensors.h:100
mrpt::system
This namespace provides a OS-independent interface to many useful functions: filenames manipulation,...
Definition: math_frwds.h:25



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST