29 m_usbSerialNumber =
"SONAR001";
31 m_sensorLabel =
"SONAR1";
47 std::vector<double> aux;
50 m_usbSerialNumber = configSource.
read_string(iniSection,
"USB_serialNumber",m_usbSerialNumber,
true);
51 m_gain = configSource.
read_int(iniSection,
"gain",m_gain,
true);
52 m_maxRange = configSource.
read_float(iniSection,
"maxRange",m_maxRange,
true);
53 m_minTimeBetweenPings = configSource.
read_float(iniSection,
"minTimeBetweenPings",m_minTimeBetweenPings,
true);
55 ASSERT_( m_maxRange>0 && m_maxRange<=11 );
60 configSource.
read_vector( iniSection,
"firingOrder", m_firingOrder, m_firingOrder,
true );
65 configSource.
read_vector( iniSection,
"sonarGains", aux, aux,
true );
69 for( itSonar = m_firingOrder.begin(), itAux = aux.begin(); itSonar != m_firingOrder.end(); ++itSonar, ++itAux )
70 m_sonarGains[ *itSonar ] = *itAux;
72 ASSERT_( aux.size() == m_firingOrder.size() );
76 for( itSonar = m_firingOrder.begin(); itSonar != m_firingOrder.end(); ++itSonar )
78 configSource.
read_vector( iniSection,
format(
"pose%i",*itSonar), aux, aux,
true );
82 ASSERT_( m_sonarGains.size() == m_firingOrder.size() );
90 bool CBoardSonars::queryFirmwareVersion(
string &out_firmwareVersion )
97 if (!checkConnectionAndConnect())
return false;
102 if (receiveMessage(msgRx) )
121 bool CBoardSonars::sendConfigCommands()
125 if (!isOpen())
return false;
135 if (i<m_firingOrder.size())
136 msg.
content[i] = m_firingOrder[i];
140 if (!receiveMessage(msgRx) )
return false;
156 if( m_sonarGains.find(i) != m_sonarGains.end() )
157 msg.
content[i] = m_sonarGains[i];
161 if (!receiveMessage(msgRx) )
return false;
167 msg.
content[0] = (int)((m_maxRange/0.043f) - 1);
169 if (!receiveMessage(msgRx) )
return false;
179 if (!receiveMessage(msgRx) )
return false;
209 if (!checkConnectionAndConnect())
return false;
214 if (receiveMessage(msgRx) )
224 for (
size_t i=0;i<
data.size() / 2;i++)
228 if ( sonar_range_cm!=0xFFFF && sonar_idx<16 )
231 obsRange.
sensorPose = m_sonarPoses[sonar_idx];
251 bool CBoardSonars::programI2CAddress(
uint8_t currentAddress,
uint8_t newAddress )
258 if (!checkConnectionAndConnect())
return false;
262 msg.
content[0] = currentAddress;
268 return receiveMessage(msgRx);
280 bool CBoardSonars::checkConnectionAndConnect()
287 OpenBySerialNumber( m_usbSerialNumber );
292 SetTimeouts(300,100);
294 return sendConfigCommands();
307 void CBoardSonars::doProcess()
311 appendObservation( obs );
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".
Declares a class derived from "CObservation" that encapsules a single range measurement, and associated parameters.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
unsigned __int16 uint16_t
float minSensorDistance
The data members.
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...
float sensorConeApperture
Cone aperture of each ultrasonic beam, in radians.
float read_float(const std::string §ion, const std::string &name, float defaultValue, bool failIfNotFound=false) const
mrpt::system::TTimeStamp BASE_IMPEXP getCurrentTime()
Returns the current (UTC) system time.
static CObservationRangePtr Create()
Contains classes for various device interfaces.
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
This class allows loading and storing values and vectors of different types from a configuration text...
int read_int(const std::string §ion, const std::string &name, int defaultValue, bool failIfNotFound=false) const
float sensedDistance
The measured range, in meters (or a value of 0 if there was no detected echo).
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...
This "software driver" implements the communication protocol for interfacing a Ultrasonic range finde...
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 BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
double DEG2RAD(const double x)
Degrees to radians.
GLsizei const GLchar ** string
#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.
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...
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.
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) ...
GLsizei GLsizei GLenum GLenum const GLvoid * data
A class that contain generic messages, that can be sent and received from a "CClientTCPSocket" object...
TMeasurementList sensedData
All the measurements.
uint32_t type
An identifier of the message type (only the least-sig byte is typically sent)