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-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 mrpt::utils::CConfigFileBase* configSource,
42  const std::string& iniSection)
43 {
44  configSource->read_vector(iniSection.c_str(), "gain0", gain, gain);
45  m_serialNumber = configSource->read_string(
46  iniSection.c_str(), "OREJA_serialNumber", m_serialNumber);
47  head_yaw = configSource->read_int(iniSection.c_str(), "HeadYaw", head_yaw);
48  head_pitch =
49  configSource->read_int(iniSection.c_str(), "HeadPitch", head_pitch);
50 }
51 
52 /*-------------------------------------------------------------
53  GetGain
54 -------------------------------------------------------------*/
55 void CRoboticHeadInterface::GetGain(int& _gain, int& channel)
56 {
57  msg.type = 0x58;
58  msg.content.resize(1);
59  msg.content[0] = (unsigned char)channel;
62  ;
63  _gain = msg.content[0];
64  if (msg.content[0])
66  "ERROR LEYENDO LA GANANCIA DEL AMPLIFICADOR DE LA OREJA \n");
67 }
68 
69 /*-------------------------------------------------------------
70  SetGain
71 -------------------------------------------------------------*/
72 bool CRoboticHeadInterface::SetGain(int& new_gain, int& channel)
73 {
74  msg.type = 0x57;
75  msg.content.resize(2);
76  msg.content[0] = (unsigned char)channel;
77  msg.content[1] = (unsigned char)new_gain;
80  ;
81  if (msg.content[0] == 0)
82  return 0;
83  else
84  return 1;
85 }
86 
87 /*-------------------------------------------------------------
88  GetSoundLocation
89 -------------------------------------------------------------*/
91 {
92  msg.type = 0x59;
93  msg.content.resize(0);
96  ;
97  ang = 256 * (int)msg.content[1] + (int)msg.content[0];
98 }
99 
100 /*-------------------------------------------------------------
101  Get3SoundBuffer
102 -------------------------------------------------------------*/
104 {
105  buf.setSize(3, 500); // 3 channel, 500 samples per channel
106  msg.type = 0x51;
107  msg.content.resize(0);
109 
110  // Las lecturas se haran de 100 en 100 datos y hay 3 buffers de 500 muestras
111  // cada uno
112  for (size_t k = 0; k < 3; k++) // Lectura de cada canal
113  {
114  for (size_t j = 0; j < 500 / 100; j++) // Lectura de un canal completo
115  {
117  ;
118  for (size_t i = 0; i < 100; i++) // Lectura de un envio
119  buf(k, 100 * j + i) =
120  256 * (int)msg.content[2 * i + 1] + (int)msg.content[2 * i];
121  }
122  }
123 }
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.
#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:4101
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:686
mrpt::comms::CInterfaceFTDI m_usbConnection
void sendMessage(const utils::CMessage &msg)
Send a message to the device.
Definition: CStream.cpp:649
std::vector< uint8_t > content
The contents of the message (memory is automatically handled by the std::vector object) ...
Definition: CMessage.h:39
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:36



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019