31 m_usbSerialNumber =
"SONAR001";
33 m_sensorLabel =
"SONAR1";
46 const std::string& iniSection)
50 std::vector<double> aux;
54 iniSection,
"USB_serialNumber", m_usbSerialNumber,
true);
55 m_gain = configSource.
read_int(iniSection,
"gain", m_gain,
true);
57 configSource.
read_float(iniSection,
"maxRange", m_maxRange,
true);
58 m_minTimeBetweenPings = configSource.
read_float(
59 iniSection,
"minTimeBetweenPings", m_minTimeBetweenPings,
true);
61 ASSERT_(m_maxRange > 0 && m_maxRange <= 11);
66 iniSection,
"firingOrder", m_firingOrder, m_firingOrder,
true);
71 configSource.
read_vector(iniSection,
"sonarGains", aux, aux,
true);
73 std::vector<int32_t>::iterator itSonar;
74 std::vector<double>::iterator itAux;
75 for (itSonar = m_firingOrder.begin(), itAux = aux.begin();
76 itSonar != m_firingOrder.end(); ++itSonar, ++itAux)
77 m_sonarGains[*itSonar] = *itAux;
79 ASSERT_(aux.size() == m_firingOrder.size());
83 for (itSonar = m_firingOrder.begin(); itSonar != m_firingOrder.end();
87 iniSection,
format(
"pose%i", *itSonar), aux, aux,
90 aux[0], aux[1], aux[2],
DEG2RAD((
float)aux[3]),
94 ASSERT_(m_sonarGains.size() == m_firingOrder.size());
109 if (!checkConnectionAndConnect())
return false;
113 arch.sendMessage(msg);
115 if (arch.receiveMessage(msgRx))
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 arch.sendMessage(msg);
154 if (!arch.receiveMessage(msgRx))
return false;
168 for (i = 0; i < 16; i++)
170 if (m_sonarGains.find(i) != m_sonarGains.end())
171 msg.
content[i] = m_sonarGains[i];
175 arch.sendMessage(msg);
176 if (!arch.receiveMessage(msgRx))
return false;
182 msg.
content[0] = (int)((m_maxRange / 0.043f) - 1);
183 arch.sendMessage(msg);
184 if (!arch.receiveMessage(msgRx))
return false;
190 auto T = (uint16_t)(m_minTimeBetweenPings * 1000.0f);
193 arch.sendMessage(msg);
194 if (!arch.receiveMessage(msgRx))
return false;
224 if (!checkConnectionAndConnect())
return false;
229 arch.sendMessage(msg);
231 if (arch.receiveMessage(msgRx))
233 if (msgRx.
content.empty())
return false;
240 for (
size_t i = 0; i <
data.size() / 2; i++)
242 uint16_t sonar_idx =
data[2 * i + 0];
243 uint16_t sonar_range_cm =
data[2 * i + 1];
244 if (sonar_range_cm != 0xFFFF && sonar_idx < 16)
248 m_sonarPoses[sonar_idx];
276 if (!checkConnectionAndConnect())
return false;
281 msg.
content[0] = currentAddress;
283 arch.sendMessage(msg);
285 std::this_thread::sleep_for(10ms);
287 return arch.receiveMessage(msgRx);
301 if (isOpen())
return true;
305 OpenBySerialNumber(m_usbSerialNumber);
306 std::this_thread::sleep_for(10ms);
308 std::this_thread::sleep_for(10ms);
310 SetTimeouts(300, 100);
312 return sendConfigCommands();
void doProcess() override
This method will be invoked at a minimum rate of "process_rate" (Hz)
bool queryFirmwareVersion(std::string &out_firmwareVersion)
Query the firmware version on the device (can be used to test communications).
Declares a class derived from "CObservation" that encapsules a single range measurement, and associated parameters.
bool checkConnectionAndConnect()
Tries to connect to the USB device (if disconnected).
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
float minSensorDistance
The data members.
float sensorConeApperture
Cone aperture of each ultrasonic beam, in radians.
std::string std::string format(std::string_view fmt, ARGS &&... args)
mrpt::system::TTimeStamp getCurrentTime()
Returns the current (UTC) system time.
uint32_t type
An identifier of the message type (only the least-sig byte is typically sent)
void loadConfig_sensorSpecific(const mrpt::config::CConfigFileBase &configSource, const std::string &iniSection) override
Loads specific configuration for the device from a given source of configuration parameters, for example, an ".ini" file, loading from the section "[iniSection]" (see config::CConfigFileBase and derived classes) See hwdrivers::CBoardSonars for the possible parameters.
Contains classes for various device interfaces.
float read_float(const std::string §ion, const std::string &name, float defaultValue, bool failIfNotFound=false) const
int read_int(const std::string §ion, const std::string &name, int defaultValue, bool failIfNotFound=false) const
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.
static Ptr Create(Args &&... args)
This class allows loading and storing values and vectors of different types from a configuration text...
float sensedDistance
The measured range, in meters (or a value of 0 if there was no detected echo).
constexpr double DEG2RAD(const double x)
Degrees to radians.
This "software driver" implements the communication protocol for interfacing a Ultrasonic range finde...
#define IMPLEMENTS_GENERIC_SENSOR(class_name, NameSpace)
This must be inserted in all CGenericSensor classes implementation files:
std::string sensorLabel
An arbitrary label that can be used to identify the sensor.
mrpt::system::TTimeStamp timestamp
The associated UTC time-stamp.
uint16_t sensorID
Some kind of sensor ID which identifies it on the bus (if applicable, 0 otherwise) ...
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.
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...
math::TPose3D sensorPose
The 6D position of the sensor on the robot.
bool sendConfigCommands()
Sends the configuration (max range, gain,...) to the USB board.
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) ...
bool programI2CAddress(uint8_t currentAddress, uint8_t newAddress)
Requests a command of "change address" for a given SRF10 device.
TMeasurementList sensedData
All the measurements.
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 ...
void memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) noexcept
An OS and compiler independent version of "memcpy".
static struct FontData data
bool getObservation(mrpt::obs::CObservationRange &obs)
Request the latest range measurements.