32 m_usbSerialNumber =
"SONAR001";
34 m_sensorLabel =
"SONAR1";
45 void CBoardSonars::loadConfig_sensorSpecific(
51 std::vector<double> aux;
55 iniSection,
"USB_serialNumber", m_usbSerialNumber,
true);
56 m_gain = configSource.
read_int(iniSection,
"gain", m_gain,
true);
58 configSource.
read_float(iniSection,
"maxRange", m_maxRange,
true);
59 m_minTimeBetweenPings = configSource.
read_float(
60 iniSection,
"minTimeBetweenPings", m_minTimeBetweenPings,
true);
62 ASSERT_(m_maxRange > 0 && m_maxRange <= 11);
67 iniSection,
"firingOrder", m_firingOrder, m_firingOrder,
true);
72 configSource.
read_vector(iniSection,
"sonarGains", aux, aux,
true);
76 for (itSonar = m_firingOrder.begin(), itAux = aux.begin();
77 itSonar != m_firingOrder.end(); ++itSonar, ++itAux)
78 m_sonarGains[*itSonar] = *itAux;
80 ASSERT_(aux.size() == m_firingOrder.size());
84 for (itSonar = m_firingOrder.begin(); itSonar != m_firingOrder.end();
88 iniSection,
format(
"pose%i", *itSonar), aux, aux,
91 aux[0], aux[1], aux[2],
DEG2RAD((
float)aux[3]),
95 ASSERT_(m_sonarGains.size() == m_firingOrder.size());
103 bool CBoardSonars::queryFirmwareVersion(
string& out_firmwareVersion)
110 if (!checkConnectionAndConnect())
return false;
115 if (receiveMessage(msgRx))
133 bool CBoardSonars::sendConfigCommands()
137 if (!isOpen())
return false;
145 for (i = 0; i < 16; i++)
147 if (i < m_firingOrder.size())
148 msg.
content[i] = m_firingOrder[i];
153 if (!receiveMessage(msgRx))
return false;
167 for (i = 0; i < 16; i++)
169 if (m_sonarGains.find(i) != m_sonarGains.end())
170 msg.
content[i] = m_sonarGains[i];
175 if (!receiveMessage(msgRx))
return false;
181 msg.
content[0] = (int)((m_maxRange / 0.043f) - 1);
183 if (!receiveMessage(msgRx))
return false;
193 if (!receiveMessage(msgRx))
return false;
223 if (!checkConnectionAndConnect())
return false;
228 if (receiveMessage(msgRx))
230 if (msgRx.
content.empty())
return false;
237 for (
size_t i = 0; i <
data.size() / 2; i++)
241 if (sonar_range_cm != 0xFFFF && sonar_idx < 16)
245 m_sonarPoses[sonar_idx];
273 if (!checkConnectionAndConnect())
return false;
277 msg.
content[0] = currentAddress;
281 std::this_thread::sleep_for(10ms);
283 return receiveMessage(msgRx);
295 bool CBoardSonars::checkConnectionAndConnect()
297 if (isOpen())
return true;
301 OpenBySerialNumber(m_usbSerialNumber);
302 std::this_thread::sleep_for(10ms);
304 std::this_thread::sleep_for(10ms);
306 SetTimeouts(300, 100);
308 return sendConfigCommands();
321 void CBoardSonars::doProcess()
324 mrpt::make_aligned_shared<mrpt::obs::CObservationRange>();
#define IMPLEMENTS_GENERIC_SENSOR(class_name, NameSpace)
This must be inserted in all CGenericSensor classes implementation files:
This "software driver" implements the communication protocol for interfacing a Ultrasonic range finde...
std::string sensorLabel
An arbitrary label that can be used to identify the sensor.
mrpt::system::TTimeStamp timestamp
The associated UTC time-stamp.
Declares a class derived from "CObservation" that encapsules a single range measurement,...
std::shared_ptr< CObservationRange > Ptr
float sensorConeApperture
Cone aperture of each ultrasonic beam, in radians.
TMeasurementList sensedData
All the measurements.
float minSensorDistance
The data members.
This class allows loading and storing values and vectors of different types from a configuration text...
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 ....
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
int read_int(const std::string §ion, const std::string &name, int defaultValue, bool failIfNotFound=false) const
float read_float(const std::string §ion, const std::string &name, float defaultValue, bool failIfNotFound=false) const
A class that contain generic messages, that can be sent and received from a "CClientTCPSocket" object...
void getContentAsString(std::string &str)
Gets the contents of the message as a string.
std::vector< uint8_t > content
The contents of the message (memory is automatically handled by the std::vector object)
uint32_t type
An identifier of the message type (only the least-sig byte is typically sent)
GLsizei GLsizei GLenum GLenum const GLvoid * data
GLsizei const GLchar ** string
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...
void memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) noexcept
An OS and compiler independent version of "memcpy".
mrpt::system::TTimeStamp getCurrentTime()
Returns the current (UTC) system time.
Contains classes for various device interfaces.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values,...
double DEG2RAD(const double x)
Degrees to radians.
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
unsigned __int16 uint16_t
Lightweight 3D pose (three spatial coordinates, plus three angular coordinates).
uint16_t sensorID
Some kind of sensor ID which identifies it on the bus (if applicable, 0 otherwise)
math::TPose3D sensorPose
The 6D position of the sensor on the robot.
float sensedDistance
The measured range, in meters (or a value of 0 if there was no detected echo).