30 m_usbSerialNumber ("ENOSE001"),
34 m_stream_SERIAL (NULL)
36 m_sensorLabel =
"ENOSE";
40 CBoardENoses::~CBoardENoses( )
49 void CBoardENoses::loadConfig_sensorSpecific(
55 m_usbSerialNumber = configSource.
read_string(iniSection,
"USB_serialname",
"",
false);
57 #ifdef MRPT_OS_WINDOWS 58 m_COM_port = configSource.
read_string(iniSection,
"COM_port_WIN",m_COM_port);
60 m_COM_port = configSource.
read_string(iniSection,
"COM_port_LIN",m_COM_port);
62 m_COM_baud = configSource.
read_uint64_t(iniSection,
"COM_baudRate",m_COM_baud);
64 configSource.
read_vector( iniSection,
"enose_poses_x", vector<float>(0), enose_poses_x,
true);
65 configSource.
read_vector( iniSection,
"enose_poses_y", vector<float>(0), enose_poses_y,
true);
66 configSource.
read_vector( iniSection,
"enose_poses_z", vector<float>(0), enose_poses_z,
true);
68 configSource.
read_vector( iniSection,
"enose_poses_yaw", vector<float>(0), enose_poses_yaw,
true);
69 configSource.
read_vector( iniSection,
"enose_poses_pitch", vector<float>(0), enose_poses_pitch,
true);
70 configSource.
read_vector( iniSection,
"enose_poses_roll", vector<float>(0), enose_poses_roll,
true);
72 ASSERT_( enose_poses_x.size() == enose_poses_y.size() );
73 ASSERT_( enose_poses_x.size() == enose_poses_z.size() );
74 ASSERT_( enose_poses_x.size() == enose_poses_yaw.size() );
75 ASSERT_( enose_poses_x.size() == enose_poses_pitch.size() );
76 ASSERT_( enose_poses_x.size() == enose_poses_roll.size() );
79 enose_poses_yaw *=
M_PIf / 180.0f;
80 enose_poses_pitch *=
M_PIf / 180.0f;
81 enose_poses_roll *=
M_PIf / 180.0f;
90 bool CBoardENoses::queryFirmwareVersion(
string &out_firmwareVersion )
97 CStream *comms = checkConnectionAndConnect();
125 CStream *CBoardENoses::checkConnectionAndConnect()
128 if (!m_stream_FTDI && !m_stream_SERIAL)
130 if (!m_COM_port.empty())
138 if (m_stream_FTDI->isOpen())
139 return m_stream_FTDI;
142 m_stream_FTDI->OpenBySerialNumber( m_usbSerialNumber );
144 m_stream_FTDI->Purge();
146 m_stream_FTDI->SetLatencyTimer(1);
147 m_stream_FTDI->SetTimeouts(10,100);
148 return m_stream_FTDI;
152 m_stream_FTDI->Close();
159 if (m_stream_SERIAL->isOpen())
160 return m_stream_SERIAL;
163 m_stream_SERIAL->open(m_COM_port);
164 m_stream_SERIAL->setConfig(m_COM_baud);
166 m_stream_SERIAL->purgeBuffers();
169 m_stream_SERIAL->setTimeouts(50,1,100, 1,20);
170 return m_stream_SERIAL;
174 m_stream_SERIAL->close();
189 CStream *comms = checkConnectionAndConnect();
219 vector<uint16_t> readings( msg.
content.size() / 2 );
227 size_t NumberOfChambers = (size_t)readings[0];
228 size_t ActiveChamber = (size_t)readings[1];
231 ASSERT_( ((readings.size() - 4) % NumberOfChambers)==0 );
232 size_t wordsPereNose = (readings.size() - 4) / NumberOfChambers;
236 for (
size_t i=0; i<NumberOfChambers; i++)
243 if (i<enose_poses_x.size())
250 enose_poses_pitch[i],
251 enose_poses_roll[i]);
263 if (i == (ActiveChamber))
267 for (
size_t idx=0 ; idx<wordsPereNose/2 ; idx++)
269 if ( readings[i*wordsPereNose + 2*idx + 2] != 0x0000 )
272 if (readings[i*wordsPereNose + 2*idx + 2] == 0xFFFF)
280 newRead.
sensorTypes.push_back( readings[i*wordsPereNose + 2*idx + 2] );
283 newRead.
readingsVoltage.push_back( ( readings[i*wordsPereNose + 2*idx + 3] * 5.0f) / 4096.0f );
298 (
uint16_t*)&readings[readings.size() - 2];
308 first_reading =
false;
322 for (
size_t ch=0; ch<obs.
m_readings.size(); ch++)
324 if( (obs.
m_readings[ch].sensorTypes.size() != 7) || (obs.
m_readings[ch].readingsVoltage.size() != 7) )
334 printf(
"Error en la observacion");
341 cerr <<
"[CBoardENoses::getObservation] Returning false due to exception: " << endl;
342 cerr << e.what() << endl;
359 void CBoardENoses::doProcess()
361 CObservationGasSensorsPtr obs= CObservationGasSensors::Create();
366 appendObservation( obs );
382 void CBoardENoses::initialize()
397 bool CBoardENoses::setActiveChamber(
unsigned char chamber )
402 CStream *comms = checkConnectionAndConnect();
408 unsigned char buf[1];
409 buf[0] = ((chamber & 15) << 2) | 130;
void BASE_IMPEXP memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) MRPT_NO_THROWS
An OS and compiler independent version of "memcpy".
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
unsigned __int16 uint16_t
OBSERVATION_T::Ptr getObservation(mrpt::obs::CSensoryFramePtr &observations, mrpt::obs::CObservationPtr &observation, bool priority_to_sf=true)
Given an mrpt::obs::CSensoryFrame and a mrpt::obs::CObservation pointer if a OBSERVATION_T type obser...
A communications serial port built as an implementation of a utils::CStream.
mrpt::system::TTimeStamp BASE_IMPEXP getCurrentTime()
Returns the current (UTC) system time.
float temperature
Sensed temperature in Celcius (valid if hasTemperature=true only)
void WriteBuffer(const void *Buffer, size_t Count)
Writes a block of bytes to the stream from Buffer.
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.
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.
void delete_safe(T *&ptr)
Calls "delete" to free an object only if the pointer is not NULL, then set the pointer to NULL...
math::TPose3D eNosePoseOnTheRobot
The pose of the sensors on the robot.
void BASE_IMPEXP sleep(int time_ms) MRPT_NO_THROWS
An OS-independent method for sending the current thread to "sleep" for a given period of time...
void read_vector(const std::string §ion, const std::string &name, const VECTOR_TYPE &defaultValue, VECTOR_TYPE &outValues, bool failIfNotFound=false) const
Reads a configuration parameter of type vector, stored in the file as a string: "[v1 v2 v3 ...
A class for interfacing an e-Noses via a FTDI USB link.
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.
void getContentAsString(std::string &str)
Gets the contents of the message as a string.
mrpt::system::TTimeStamp timestamp
The associated UTC time-stamp. Where available, this should contain the accurate satellite-based time...
bool receiveMessage(utils::CMessage &msg)
Tries to receive a message from the device.
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.
uint64_t read_uint64_t(const std::string §ion, const std::string &name, uint64_t defaultValue, bool failIfNotFound=false) const
void sendMessage(const utils::CMessage &msg)
Send a message to the device.
std::vector< uint8_t > content
The contents of the message (memory is automatically handled by the std::vector object) ...
mrpt::system::TTimeStamp BASE_IMPEXP secondsToTimestamp(const double nSeconds)
Transform a time interval (in seconds) into TTimeStamp (e.g.
std::vector< float > readingsVoltage
The set of readings (in volts) from the array of sensors (size of "sensorTypes" is the same that the ...
A definition of a CStream actually representing a USB connection to a FTDI chip.
A class that contain generic messages, that can be sent and received from a "CClientTCPSocket" object...
uint32_t type
An identifier of the message type (only the least-sig byte is typically sent)