34 m_sensorLabel =
"EnoseModular";
41 void CEnoseModular::loadConfig_sensorSpecific(
48 configSource.
read_string(iniSection,
"USB_serialname",
"",
false);
51 m_COM_port = configSource.
read_string(iniSection,
"COM_port_WIN",
"COM1");
54 configSource.
read_string(iniSection,
"COM_port_LIN", m_COM_port);
57 configSource.
read_uint64_t(iniSection,
"COM_baudRate", m_COM_baud);
65 CStream* CEnoseModular::checkConnectionAndConnect()
68 if (!m_stream_FTDI && !m_stream_SERIAL)
70 if (!m_COM_port.empty())
71 m_stream_SERIAL = std::make_unique<mrpt::comms::CSerialPort>();
73 m_stream_FTDI = std::make_unique<mrpt::comms::CInterfaceFTDI>();
78 if (m_stream_FTDI->isOpen())
return m_stream_FTDI.get();
81 m_stream_FTDI->OpenBySerialNumber(m_usbSerialNumber);
82 std::this_thread::sleep_for(10ms);
83 m_stream_FTDI->Purge();
84 std::this_thread::sleep_for(10ms);
85 m_stream_FTDI->SetLatencyTimer(1);
86 m_stream_FTDI->SetTimeouts(10, 100);
87 return m_stream_FTDI.get();
91 m_stream_FTDI->Close();
98 if (m_stream_SERIAL->isOpen())
return m_stream_SERIAL.get();
101 m_stream_SERIAL->open(m_COM_port);
102 m_stream_SERIAL->setConfig(m_COM_baud);
104 m_stream_SERIAL->setTimeouts(50, 1, 100, 1, 20);
105 std::this_thread::sleep_for(10ms);
106 m_stream_SERIAL->purgeBuffers();
107 std::this_thread::sleep_for(10ms);
108 return m_stream_SERIAL.get();
112 m_stream_SERIAL->close();
130 cout <<
"ERORR: Problem connecting to Device." << endl;
145 bool time_out =
false;
147 double time_out_val = 1;
151 while (!arch.receiveMessage(msg) && !time_out)
160 cout <<
"[CEnoseModular - getObservation] measurement Timed-Out" 170 size_t numSensors = (msg.
content.size() - 1) / 3;
179 if (enose_poses_x.size() != 0)
182 enose_poses_x[0], enose_poses_y[0], enose_poses_z[0],
183 enose_poses_yaw[0], enose_poses_pitch[0],
184 enose_poses_roll[0]);
193 for (
size_t idx = 0; idx < numSensors; idx++)
196 int sensorType_temp = 0;
200 &sensorType_temp, &msg.
content[idx * 3 + 1],
202 int sensorType = sensorType_temp << (8);
204 &sensorType, &msg.
content[idx * 3 + 2],
212 (msg.
content[idx * 3 + 3] * 0.6f) / 255.0f);
226 cout <<
"Message was empty" << endl;
232 cerr <<
"[CEnoseModular::getObservation] Returning false due to " 235 cerr << e.what() << endl;
252 void CEnoseModular::doProcess()
255 std::make_shared<CObservationGasSensors>();
260 appendObservation(obs);
265 cout <<
"No observation received from the USB board!" << endl;
273 void CEnoseModular::purgeBuffers()
275 if (!checkConnectionAndConnect())
return;
279 m_stream_FTDI->Purge();
283 m_stream_SERIAL->purgeBuffers();
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
mrpt::system::TTimeStamp getCurrentTime()
Returns the current (UTC) system time.
float temperature
Sensed temperature in Celcius (valid if hasTemperature=true only)
mrpt::system::TTimeStamp now()
A shortcut for system::getCurrentTime.
Contains classes for various device interfaces.
The structure for each e-nose.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
CArchiveStreamBase< STREAM > archiveFrom(STREAM &s)
Helper function to create a templatized wrapper CArchive object for a: MRPT's CStream, std::istream, std::ostream, std::stringstream.
#define ASSERT_(f)
Defines an assertion mechanism.
mrpt::Clock::time_point TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
This class allows loading and storing values and vectors of different types from a configuration text...
This base provides a set of functions for maths stuff.
math::TPose3D eNosePoseOnTheRobot
The pose of the sensors on the robot.
std::vector< int > sensorTypes
The kind of sensors in the array (size of "sensorTypes" is the same that the size of "readingsVoltage...
bool hasTemperature
Must be true for "temperature" to contain a valid measurement.
This namespace contains representation of robot actions and observations.
uint64_t read_uint64_t(const std::string §ion, const std::string &name, uint64_t defaultValue, bool failIfNotFound=false) const
Declares a class derived from "CObservation" that represents a set of readings from gas sensors...
GLsizei const GLchar ** string
#define IMPLEMENTS_GENERIC_SENSOR(class_name, NameSpace)
This must be inserted in all CGenericSensor classes implementation files:
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
std::string sensorLabel
An arbitrary label that can be used to identify the sensor.
bool isActive
True if the input to this chamber/enose is poluted air, False if clean air.
mrpt::system::TTimeStamp timestamp
The associated UTC time-stamp.
A class that contain generic messages, that can be sent and received from a "CClientTCPSocket" object...
std::vector< TObservationENose > m_readings
One entry per e-nose on the robot.
OBSERVATION_T::Ptr getObservation(mrpt::obs::CSensoryFrame::Ptr &observations, mrpt::obs::CObservation::Ptr &observation, bool priority_to_sf=true)
Given an mrpt::obs::CSensoryFrame and a mrpt::obs::CObservation pointer if a OBSERVATION_T type obser...
Lightweight 3D pose (three spatial coordinates, plus three angular coordinates).
std::vector< uint8_t > content
The contents of the message (memory is automatically handled by the std::vector object) ...
double timeDifference(const mrpt::system::TTimeStamp t_first, const mrpt::system::TTimeStamp t_later)
Returns the time difference from t1 to t2 (positive if t2 is posterior to t1), in seconds...
std::vector< float > readingsVoltage
The set of readings (in volts) from the array of sensors (size of "sensorTypes" is the same that the ...
A class for interfacing an e-NoseModular via a FTDI USB link.
void memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) noexcept
An OS and compiler independent version of "memcpy".