MRPT  1.9.9
CRoboticHeadInterface.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "hwdrivers-precomp.h" // Precompiled headers
11 
14 
15 using namespace mrpt::math;
16 using namespace mrpt::hwdrivers;
17 using namespace mrpt::serialization;
18 
19 /*-------------------------------------------------------------
20  CRoboticHeadInterface
21 -------------------------------------------------------------*/
22 CRoboticHeadInterface::CRoboticHeadInterface()
23  : mrpt::system::COutputLogger("CRoboticHeadInterface")
24 {
26 
27  m_serialNumber = "OREJA001";
28  gain.resize(3);
29  gain[0] = 127; // 0x7F (maximo)
30  gain[1] = 127; // 0x7F (maximo)
31  gain[2] = 127; // 0x7F (maximo)
32  head_yaw = 0;
33  head_pitch = 0;
34 
35  MRPT_END
36 }
37 
38 /*-------------------------------------------------------------
39  loadConfig_sensorSpecific
40 -------------------------------------------------------------*/
42  const mrpt::config::CConfigFileBase* configSource,
43  const std::string& iniSection)
44 {
45  configSource->read_vector(iniSection.c_str(), "gain0", gain, gain);
46  m_serialNumber = configSource->read_string(
47  iniSection.c_str(), "OREJA_serialNumber", m_serialNumber);
48  head_yaw = configSource->read_int(iniSection.c_str(), "HeadYaw", head_yaw);
49  head_pitch =
50  configSource->read_int(iniSection.c_str(), "HeadPitch", head_pitch);
51 }
52 
53 /*-------------------------------------------------------------
54  GetGain
55 -------------------------------------------------------------*/
56 void CRoboticHeadInterface::GetGain(int& _gain, int& channel)
57 {
58  msg.type = 0x58;
59  msg.content.resize(1);
60  msg.content[0] = (unsigned char)channel;
61  archiveFrom(m_usbConnection).sendMessage(msg);
62  while (!archiveFrom(m_usbConnection).receiveMessage(msg))
63  ;
64  _gain = msg.content[0];
65  if (msg.content[0])
67  "ERROR LEYENDO LA GANANCIA DEL AMPLIFICADOR DE LA OREJA \n");
68 }
69 
70 /*-------------------------------------------------------------
71  SetGain
72 -------------------------------------------------------------*/
73 bool CRoboticHeadInterface::SetGain(int& new_gain, int& channel)
74 {
75  msg.type = 0x57;
76  msg.content.resize(2);
77  msg.content[0] = (unsigned char)channel;
78  msg.content[1] = (unsigned char)new_gain;
79  archiveFrom(m_usbConnection).sendMessage(msg);
80  while (!archiveFrom(m_usbConnection).receiveMessage(msg))
81  ;
82  if (msg.content[0] == 0)
83  return false;
84  else
85  return true;
86 }
87 
88 /*-------------------------------------------------------------
89  GetSoundLocation
90 -------------------------------------------------------------*/
92 {
93  msg.type = 0x59;
94  msg.content.resize(0);
95  archiveFrom(m_usbConnection).sendMessage(msg);
96  while (!archiveFrom(m_usbConnection).receiveMessage(msg))
97  ;
98  ang = 256 * (int)msg.content[1] + (int)msg.content[0];
99 }
100 
101 /*-------------------------------------------------------------
102  Get3SoundBuffer
103 -------------------------------------------------------------*/
105 {
106  buf.setSize(3, 500); // 3 channel, 500 samples per channel
107  msg.type = 0x51;
108  msg.content.resize(0);
109  archiveFrom(m_usbConnection).sendMessage(msg);
110 
111  // Las lecturas se haran de 100 en 100 datos y hay 3 buffers de 500 muestras
112  // cada uno
113  for (size_t k = 0; k < 3; k++) // Lectura de cada canal
114  {
115  for (size_t j = 0; j < 500 / 100; j++) // Lectura de un canal completo
116  {
117  while (!archiveFrom(m_usbConnection).receiveMessage(msg))
118  ;
119  for (size_t i = 0; i < 100; i++) // Lectura de un envio
120  buf(k, 100 * j + i) =
121  256 * (int)msg.content[2 * i + 1] + (int)msg.content[2 * i];
122  }
123  }
124 }
bool SetGain(int &new_gain, int &channel)
Set the gain for the amplifier each ear.
#define MRPT_START
Definition: exceptions.h:241
std::string read_string(const std::string &section, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:67
uint32_t type
An identifier of the message type (only the least-sig byte is typically sent)
Definition: CMessage.h:32
Contains classes for various device interfaces.
void GetGain(int &_gain, int &channel)
Read the gain for the amplifier of the ear "channel", where channel is 0, 1 or 2. ...
mrpt::system::COutputLogger COutputLogger
int read_int(const std::string &section, 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&#39;s CStream, std::istream, std::ostream, std::stringstream.
Definition: CArchive.h:591
This class allows loading and storing values and vectors of different types from a configuration text...
This base provides a set of functions for maths stuff.
GLsizei const GLchar ** string
Definition: glext.h:4116
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void GetSoundLocation(int &ang)
This function return the angle where last sound where detected.
void loadConfig_sensorSpecific(const mrpt::config::CConfigFileBase *configSource, const std::string &iniSection)
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::CSonarSRF10 for the possible parameters.
void setSize(size_t row, size_t col, bool zeroNewElements=false)
Changes the size of matrix, maintaining the previous contents.
#define MRPT_END
Definition: exceptions.h:245
mrpt::comms::CInterfaceFTDI m_usbConnection
void Get3SoundBuffer(mrpt::math::CMatrixDynamic< int > &buf)
Debug only!!! This function return the last 500 acquired samples for each sound channel.
std::vector< uint8_t > content
The contents of the message (memory is automatically handled by the std::vector object) ...
Definition: CMessage.h:35
This template class provides the basic functionality for a general 2D any-size, resizable container o...
void read_vector(const std::string &section, 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 ...



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 0cbd40372 Sun Nov 17 09:43:05 2019 +0100 at dom nov 17 09:45:09 CET 2019