iCub-main
SkinDiagnostics.h
Go to the documentation of this file.
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 
4 /*
5  * Copyright (C) 2014 Francesco Giovannini, iCub Facility - Istituto Italiano di Tecnologia
6  * Authors: Francesco Giovannini
7  * email: francesco.giovannini@iit.it
8  * website: www.robotcub.org
9  * Permission is granted to copy, distribute, and/or modify this program
10  * under the terms of the GNU General Public License, version 2 or any
11  * later version published by the Free Software Foundation.
12  *
13  * A copy of the license can be found at
14  * http://www.robotcub.org/icub/license/gpl.txt
15  *
16  * This program is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
19  * Public License for more details
20  */
21 
22 #ifndef SKIN_DIAGNOSTIC_DEFINITIONS
23 #define SKIN_DIAGNOSTIC_DEFINITIONS
24 
25 #include <string>
26 #include <stdint.h>
27 #include <sstream>
28 
29 
30 namespace iCub {
31  namespace skin {
32  namespace diagnostics {
33 
42  struct DetectedError {
43  short net;
44  short board;
45  short sensor;
46  int error;
47  };
48 
52  struct SkinErrorCode {
53  public:
54  enum ErrorCode {
55  // Error flags
56  // Stuck taxels - (Value < 0) || (Value > 255)
57  TaxelStuck11 = 0x8000,
58  TaxelStuck10 = 0x4000,
59  TaxelStuck09 = 0x2000,
60  TaxelStuck08 = 0x1000,
61  TaxelStuck07 = 0x0800,
62  TaxelStuck06 = 0x0400,
63  TaxelStuck05 = 0x0200,
64  TaxelStuck04 = 0x0100,
65  TaxelStuck03 = 0x0080,
66  TaxelStuck02 = 0x0040,
67  TaxelStuck01 = 0x0020,
68  TaxelStuck00 = 0x0010,
69 
70  // Error codes
71  StatusOK = 0x0000,
72  ErrorReading12C = 0x0001,
73  ErrorACK4C = 0x0002
74  };
75 
78  operator ErrorCode () const {return t_;}
79 
80  private:
81  // Prevent automatic conversion for any other built-in types such as bool, int, etc
82  template<typename T>
83  operator T () const;
84  };
85 
86  /* inline std::string printErrorCode(int code)
87  {
88  std::string s;
89 
90  if (code & (1<<0)) {s+="1";} else {s+="0";}
91  if (code & (1<<1)) {s+="1";} else {s+="0";}
92  s+="R";
93  s+="R";
94  s+=".";
95  for (int i=4; i<16; i++)
96  {
97  if (code & (1<<i)) {s+="1";} else {s+="0";}
98  if (i%4==3 && i!=15) s+=".";
99  }
100  return s;
101  }
102  */
103 
104  inline std::string printErrorCode(int code)
105  {
106  std::string errortype_str;
107 
108  uint8_t error_type = code & 0x000f;
109  uint16_t outofrange_error = (code & 0xfff0)>>4;
110  //printf("sono nella print error code %d", code);
111  switch(error_type)
112  {
113  case 0: //no_ack see mtb code
114  {
115  errortype_str+="";
116  break;
117  }
118  case 1: //no_ack see mtb code
119  {
120  errortype_str+="no ack";
121  break;
122  }
123  case 2: //no_ack see mtb code
124  {
125  errortype_str+="not connected";
126  break;
127  }
128  default:
129  {
130  errortype_str+="unknown error";
131  break;
132  }
133  }
134 
135  std::stringstream ss;
136  int numoftaxel_in_error = 0;
137  for(int i=0; i<12; i++)
138  {
139  if(outofrange_error & (1<<i))
140  {
141  numoftaxel_in_error++;
142  ss << i <<", ";
143  }
144  }
145 
146  std::stringstream outs;
147  if(numoftaxel_in_error>0)
148  {
149  outs << numoftaxel_in_error <<" taxels are out of range:"<< ss.str();
150  }
151  else
152  {
153  outs << "None taxels are out of range";
154  }
155 
156  if(error_type!=0)
157  outs << ". Triangle error is "<< errortype_str;
158  else
159  outs << ". Triangle has not error ";
160 
161  return outs.str();
162  }
163  }
164  }
165 }
166 
167 #endif // SKIN_DIAGNOSTIC_DEFINITIONS
std::string printErrorCode(int code)
This file contains the definition of unique IDs for the body parts and the skin parts of the robot.
Enum to provide intelligible error codes for the skin.