Main MRPT website > C++ reference for MRPT 1.9.9
CRoboticHeadInterface.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://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 0;
84  else
85  return 1;
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 }
mrpt::hwdrivers::CRoboticHeadInterface::head_pitch
int head_pitch
Definition: CRoboticHeadInterface.h:55
mrpt::math::CMatrixTemplate::setSize
void setSize(size_t row, size_t col, bool zeroNewElements=false)
Changes the size of matrix, maintaining the previous contents.
Definition: CMatrixTemplate.h:313
mrpt::hwdrivers::CRoboticHeadInterface::GetSoundLocation
void GetSoundLocation(int &ang)
This function return the angle where last sound where detected.
Definition: CRoboticHeadInterface.cpp:91
mrpt::math::CMatrixTemplate
This template class provides the basic functionality for a general 2D any-size, resizable container o...
Definition: CMatrixTemplate.h:72
mrpt::hwdrivers::CRoboticHeadInterface::m_usbConnection
mrpt::comms::CInterfaceFTDI m_usbConnection
Definition: CRoboticHeadInterface.h:51
mrpt::hwdrivers::CRoboticHeadInterface::loadConfig_sensorSpecific
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,...
Definition: CRoboticHeadInterface.cpp:41
mrpt::hwdrivers
Contains classes for various device interfaces.
Definition: C2DRangeFinderAbstract.h:22
mrpt::serialization::CMessage::type
uint32_t type
An identifier of the message type (only the least-sig byte is typically sent)
Definition: CMessage.h:34
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::utils::COutputLogger
mrpt::system::COutputLogger COutputLogger
Definition: utils/COutputLogger.h:7
THROW_EXCEPTION
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:41
mrpt::config::CConfigFileBase::read_string
std::string read_string(const std::string &section, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
Definition: CConfigFileBase.cpp:169
mrpt::config::CConfigFileBase::read_int
int read_int(const std::string &section, const std::string &name, int defaultValue, bool failIfNotFound=false) const
Definition: CConfigFileBase.cpp:125
mrpt::hwdrivers::CRoboticHeadInterface::gain
std::vector< int32_t > gain
Definition: CRoboticHeadInterface.h:54
mrpt::hwdrivers::CRoboticHeadInterface::msg
mrpt::serialization::CMessage msg
Definition: CRoboticHeadInterface.h:52
mrpt::hwdrivers::CRoboticHeadInterface::SetGain
bool SetGain(int &new_gain, int &channel)
Set the gain for the amplifier each ear.
Definition: CRoboticHeadInterface.cpp:73
MRPT_START
#define MRPT_START
Definition: exceptions.h:262
mrpt::config::CConfigFileBase
This class allows loading and storing values and vectors of different types from a configuration text...
Definition: config/CConfigFileBase.h:44
mrpt::serialization::CMessage::content
std::vector< uint8_t > content
The contents of the message (memory is automatically handled by the std::vector object)
Definition: CMessage.h:37
mrpt::hwdrivers::CRoboticHeadInterface::Get3SoundBuffer
void Get3SoundBuffer(mrpt::math::CMatrixTemplate< int > &buf)
Debug only!!! This function return the last 500 acquired samples for each sound channel.
Definition: CRoboticHeadInterface.cpp:104
mrpt::serialization
Definition: aligned_serialization.h:14
mrpt::hwdrivers::CRoboticHeadInterface::head_yaw
int head_yaw
Definition: CRoboticHeadInterface.h:55
mrpt::hwdrivers::CRoboticHeadInterface::GetGain
void GetGain(int &_gain, int &channel)
Read the gain for the amplifier of the ear "channel", where channel is 0, 1 or 2.
Definition: CRoboticHeadInterface.cpp:56
mrpt::serialization::archiveFrom
CArchiveStreamBase< STREAM > archiveFrom(STREAM &s)
Helper function to create a templatized wrapper CArchive object for a: MRPT's CStream,...
Definition: CArchive.h:561
MRPT_END
#define MRPT_END
Definition: exceptions.h:266
mrpt::math
This base provides a set of functions for maths stuff.
Definition: math/include/mrpt/math/bits_math.h:13
string
GLsizei const GLchar ** string
Definition: glext.h:4101
CArchive.h
CRoboticHeadInterface.h
mrpt::hwdrivers::CRoboticHeadInterface::m_serialNumber
std::string m_serialNumber
Definition: CRoboticHeadInterface.h:53
mrpt::config::CConfigFileBase::read_vector
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 ....
Definition: config/CConfigFileBase.h:171
hwdrivers-precomp.h



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST