Main MRPT website > C++ reference for MRPT 1.5.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-2017, 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 
13 
14 using namespace mrpt::utils;
15 using namespace mrpt::math;
16 using namespace mrpt::hwdrivers;
17 
18 /*-------------------------------------------------------------
19  CRoboticHeadInterface
20 -------------------------------------------------------------*/
21 CRoboticHeadInterface::CRoboticHeadInterface() :
22  mrpt::utils::COutputLogger("CRoboticHeadInterface")
23 {
25 
26  m_serialNumber = "OREJA001";
27  gain.resize(3);
28  gain[0]=127; //0x7F (maximo)
29  gain[1]=127; //0x7F (maximo)
30  gain[2]=127; //0x7F (maximo)
31  head_yaw = 0;
32  head_pitch = 0;
33 
34  MRPT_END
35 }
36 
37 /*-------------------------------------------------------------
38  loadConfig_sensorSpecific
39 -------------------------------------------------------------*/
41  const std::string &iniSection )
42 {
43  configSource->read_vector(iniSection.c_str(),"gain0",gain,gain);
44  m_serialNumber = configSource->read_string(iniSection.c_str(),"OREJA_serialNumber",m_serialNumber);
45  head_yaw = configSource->read_int(iniSection.c_str(),"HeadYaw",head_yaw);
46  head_pitch = configSource->read_int(iniSection.c_str(),"HeadPitch",head_pitch);
47 }
48 
49 /*-------------------------------------------------------------
50  GetGain
51 -------------------------------------------------------------*/
52 void CRoboticHeadInterface::GetGain(int &_gain,int &channel)
53 {
54  msg.type=0x58;
55  msg.content.resize(1);
56  msg.content[0]=(unsigned char)channel;
59  _gain = msg.content[0];
60  if (msg.content[0])
61  THROW_EXCEPTION("ERROR LEYENDO LA GANANCIA DEL AMPLIFICADOR DE LA OREJA \n");
62 }
63 
64 
65 /*-------------------------------------------------------------
66  SetGain
67 -------------------------------------------------------------*/
68 bool CRoboticHeadInterface::SetGain(int &new_gain,int &channel)
69 {
70  msg.type = 0x57;
71  msg.content.resize(2);
72  msg.content[0]=(unsigned char)channel;
73  msg.content[1]=(unsigned char)new_gain;
76  if (msg.content[0]==0)
77  return 0;
78  else
79  return 1;
80 }
81 
82 /*-------------------------------------------------------------
83  GetSoundLocation
84 -------------------------------------------------------------*/
86 {
87  msg.type = 0x59;
88  msg.content.resize(0);
91  ang = 256*(int)msg.content[1]+(int)msg.content[0];
92 }
93 
94 /*-------------------------------------------------------------
95  Get3SoundBuffer
96 -------------------------------------------------------------*/
98 {
99  buf.setSize(3,500); //3 channel, 500 samples per channel
100  msg.type = 0x51;
101  msg.content.resize(0);
103 
104  //Las lecturas se haran de 100 en 100 datos y hay 3 buffers de 500 muestras cada uno
105  for (size_t k = 0; k < 3; k++) //Lectura de cada canal
106  {
107  for (size_t j = 0; j < 500/100; j++) //Lectura de un canal completo
108  {
110  for (size_t i = 0; i < 100; i++) //Lectura de un envio
111  buf(k,100*j+i) = 256*(int)msg.content[2*i+1]+(int)msg.content[2*i];
112  }
113  }
114 }
void Get3SoundBuffer(mrpt::math::CMatrixTemplate< int > &buf)
Debug only!!! This function return the last 500 acquired samples for each sound channel.
bool SetGain(int &new_gain, int &channel)
Set the gain for the amplifier each ear.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
Definition: zip.h:16
#define THROW_EXCEPTION(msg)
Contains classes for various device interfaces.
std::string read_string(const std::string &section, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
void GetGain(int &_gain, int &channel)
Read the gain for the amplifier of the ear "channel", where channel is 0, 1 or 2. ...
This class allows loading and storing values and vectors of different types from a configuration text...
int read_int(const std::string &section, const std::string &name, int defaultValue, bool failIfNotFound=false) const
This base provides a set of functions for maths stuff.
Definition: CArrayNumeric.h:19
#define MRPT_END
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 ...
GLsizei const GLchar ** string
Definition: glext.h:3919
This template class provides the basic functionality for a general 2D any-size, resizable container o...
#define MRPT_START
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.
bool receiveMessage(utils::CMessage &msg)
Tries to receive a message from the device.
Definition: CStream.cpp:590
void sendMessage(const utils::CMessage &msg)
Send a message to the device.
Definition: CStream.cpp:556
std::vector< uint8_t > content
The contents of the message (memory is automatically handled by the std::vector object) ...
Definition: CMessage.h:33
void setSize(size_t row, size_t col, bool zeroNewElements=false)
Changes the size of matrix, maintaining the previous contents.
void loadConfig_sensorSpecific(const mrpt::utils::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 utils::CConfigFileBase and derived classes) See hwdrivers::CSonarSRF10 for the possible parameters.
uint32_t type
An identifier of the message type (only the least-sig byte is typically sent)
Definition: CMessage.h:32



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020