31 : m_usbSerialNumber("ENOSE002"), m_COM_port(), m_COM_baud(115200)
33 m_sensorLabel =
"EnoseModular";
40 void CEnoseModular::loadConfig_sensorSpecific(
47 configSource.
read_string(iniSection,
"USB_serialname",
"",
false);
49 #ifdef MRPT_OS_WINDOWS 50 m_COM_port = configSource.
read_string(iniSection,
"COM_port_WIN",
"COM1");
53 configSource.
read_string(iniSection,
"COM_port_LIN", m_COM_port);
56 configSource.
read_uint64_t(iniSection,
"COM_baudRate", m_COM_baud);
64 CStream* CEnoseModular::checkConnectionAndConnect()
67 if (!m_stream_FTDI && !m_stream_SERIAL)
69 if (!m_COM_port.empty())
77 if (m_stream_FTDI->isOpen())
return m_stream_FTDI.get();
80 m_stream_FTDI->OpenBySerialNumber(m_usbSerialNumber);
81 std::this_thread::sleep_for(10ms);
82 m_stream_FTDI->Purge();
83 std::this_thread::sleep_for(10ms);
84 m_stream_FTDI->SetLatencyTimer(1);
85 m_stream_FTDI->SetTimeouts(10, 100);
86 return m_stream_FTDI.get();
90 m_stream_FTDI->Close();
97 if (m_stream_SERIAL->isOpen())
return m_stream_SERIAL.get();
100 m_stream_SERIAL->open(m_COM_port);
101 m_stream_SERIAL->setConfig(m_COM_baud);
103 m_stream_SERIAL->setTimeouts(50, 1, 100, 1, 20);
104 std::this_thread::sleep_for(10ms);
105 m_stream_SERIAL->purgeBuffers();
106 std::this_thread::sleep_for(10ms);
107 return m_stream_SERIAL.get();
111 m_stream_SERIAL->close();
125 CStream* comms = checkConnectionAndConnect();
129 cout <<
"ERORR: Problem connecting to Device." << endl;
144 bool time_out =
false;
146 double time_out_val = 1;
157 cout <<
"[CEnoseModular - getObservation] measurement Timed-Out" 167 size_t numSensors = (msg.
content.size() - 1) / 3;
176 if (enose_poses_x.size() != 0)
179 enose_poses_x[0], enose_poses_y[0], enose_poses_z[0],
180 enose_poses_yaw[0], enose_poses_pitch[0],
181 enose_poses_roll[0]);
190 for (
size_t idx = 0; idx < numSensors; idx++)
193 int sensorType_temp = 0;
197 &sensorType_temp, &msg.
content[idx * 3 + 1],
199 int sensorType = sensorType_temp << (8);
201 &sensorType, &msg.
content[idx * 3 + 2],
209 (msg.
content[idx * 3 + 3] * 0.6f) / 255.0f);
223 cout <<
"Message was empty" << endl;
229 cerr <<
"[CEnoseModular::getObservation] Returning false due to " 232 cerr << e.what() << endl;
249 void CEnoseModular::doProcess()
252 mrpt::make_aligned_shared<CObservationGasSensors>();
257 appendObservation(obs);
262 cout <<
"No observation received from the USB board!" << endl;
270 void CEnoseModular::purgeBuffers()
272 if (!checkConnectionAndConnect())
return;
276 m_stream_FTDI->Purge();
280 m_stream_SERIAL->purgeBuffers();
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
A communications serial port built as an implementation of a utils::CStream.
mrpt::system::TTimeStamp getCurrentTime()
Returns the current (UTC) system time.
float temperature
Sensed temperature in Celcius (valid if hasTemperature=true only)
Contains classes for various device interfaces.
vector_int sensorTypes
The kind of sensors in the array (size of "sensorTypes" is the same that the size of "readingsVoltage...
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
The structure for each e-nose.
mrpt::system::TTimeStamp getCurrentLocalTime()
Returns the current (local) time.
This class allows loading and storing values and vectors of different types from a configuration text...
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
This base provides a set of functions for maths stuff.
std::shared_ptr< CObservationGasSensors > Ptr
math::TPose3D eNosePoseOnTheRobot
The pose of the sensors on the robot.
bool hasTemperature
Must be true for "temperature" to contain a valid measurement.
This namespace contains representation of robot actions and observations.
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.
bool receiveMessage(utils::CMessage &msg)
Tries to receive a message from the device.
A definition of a CStream actually representing a USB connection to a FTDI chip.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
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...
uint64_t read_uint64_t(const std::string §ion, const std::string &name, uint64_t defaultValue, bool failIfNotFound=false) const
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 that contain generic messages, that can be sent and received from a "CClientTCPSocket" object...
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".