Robotis Manipulator  1.0.0
robotis_manipulator_log.h
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright 2018 ROBOTIS CO., LTD.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *******************************************************************************/
16 
17 /* Authors: Darby Lim, Hye-Jong KIM, Ryan Shim, Yong-Ho Na */
18 
25 #ifndef ROBOTIS_MANIPULATOR_LOG_H
26 #define ROBOTIS_MANIPULATOR_LOG_H
27 
28 #include <unistd.h>
29 #include <vector>
30 
31 #if defined(__OPENCR__)
32  #include <Eigen.h>
33  #include <WString.h>
34  #include "variant.h"
35 
36  #define DEBUG SerialBT2
37 #else
38  #include <string>
39 
40  #define ANSI_COLOR_RED "\x1b[31m"
41  #define ANSI_COLOR_GREEN "\x1b[32m"
42  #define ANSI_COLOR_YELLOW "\x1b[33m"
43  #define ANSI_COLOR_BLUE "\x1b[34m"
44  #define ANSI_COLOR_MAGENTA "\x1b[35m"
45  #define ANSI_COLOR_CYAN "\x1b[36m"
46  #define ANSI_COLOR_RESET "\x1b[0m"
47 #endif
48 
49 #if defined(__OPENCR__)
50  typedef String STRING;
51 #else
52  typedef std::string STRING;
53 #endif
54 
55 namespace robotis_manipulator
56 {
57 namespace log{
63  void print(STRING str, STRING color = "DEFAULT");
71  void print(STRING str, double data, uint8_t decimal_point = 3, STRING color = "DEFAULT");
77  void print(const char* str, STRING color = "DEFAULT");
85  void print(const char* str, double data, uint8_t decimal_point = 3, STRING color = "DEFAULT");
86 
92  void println(STRING str, STRING color = "DEFAULT");
100  void println(STRING str, double data, uint8_t decimal_point = 3, STRING color = "DEFAULT");
106  void println(const char* str, STRING color = "DEFAULT");
114  void println(const char* str, double data, uint8_t decimal_point = 3, STRING color = "DEFAULT");
115 
120  void info(STRING str);
127  void info(STRING str, double data, uint8_t decimal_point = 3);
132  void info(const char* str);
139  void info(const char* str, double data, uint8_t decimal_point = 3);
140 
145  void warn(STRING str);
152  void warn(STRING str, double data, uint8_t decimal_point = 3);
157  void warn(const char* str);
164  void warn(const char* str, double data, uint8_t decimal_point = 3);
165 
170  void error(STRING str);
177  void error(STRING str, double data, uint8_t decimal_point = 3);
182  void error(const char* str);
189  void error(const char* str, double data, uint8_t decimal_point = 3);
190 
196  template <typename T> void print_vector(std::vector<T> &vec, uint8_t decimal_point = 3)
197  {
198  #if defined(__OPENCR__)
199  DEBUG.print("(");
200  for (uint8_t i = 0; i < vec.size(); i++)
201  {
202  DEBUG.print(vec.at(i), decimal_point);
203  if(i != vec.size()-1)
204  DEBUG.print(", ");
205  else
206  DEBUG.println(")");
207  }
208  #else
209  printf("(");
210  for (uint8_t i = 0; i < vec.size(); i++)
211  {
212  printf("%.*lf", decimal_point, vec.at(i));
213  if(i != vec.size()-1)
214  printf(", ");
215  else
216  printf(")\n");
217  }
218  #endif
219  }
220 
226  template <typename vector> void print_vector(vector &vec, uint8_t decimal_point = 3)
227  {
228  #if defined(__OPENCR__)
229  DEBUG.print("(");
230  for (uint8_t i = 0; i < vec.size(); i++)
231  {
232  DEBUG.print(vec(i), decimal_point);
233  if(i != vec.size()-1)
234  DEBUG.print(", ");
235  else
236  DEBUG.println(")");
237  }
238  #else
239  printf("(");
240  for (uint8_t i = 0; i < vec.size(); i++)
241  {
242  printf("%.*lf", decimal_point, vec(i));
243  if(i != vec.size()-1)
244  printf(", ");
245  else
246  printf(")\n");
247  }
248  #endif
249  }
250 
256  template <typename matrix> void print_matrix(matrix &m, uint8_t decimal_point = 3)
257  {
258  #if defined(__OPENCR__)
259 
260  for (uint8_t i = 0; i < m.rows(); i++)
261  {
262  if(i == 0)
263  DEBUG.print("(");
264  else
265  DEBUG.print(" ");
266  for (uint8_t j = 0; j < m.cols(); j++)
267  {
268  DEBUG.print(m(i, j), decimal_point);
269  if(j != m.cols()-1)
270  DEBUG.print(", ");
271  }
272  if(i != m.rows()-1)
273  DEBUG.println("");
274  else
275  DEBUG.println(")");
276  }
277  #else
278 
279  for (uint8_t i = 0; i < m.rows(); i++)
280  {
281  if(i == 0)
282  printf("(");
283  else
284  printf(" ");
285  for (uint8_t j = 0; j < m.cols(); j++)
286  {
287  printf("%.*lf", decimal_point, m(i, j));
288  if(j != m.cols()-1)
289  printf(", ");
290  }
291  if(i != m.rows()-1)
292  printf("\n");
293  else
294  printf(")\n");
295  }
296  #endif
297  }
298 
299 } //log
300 } //robotis_manipulator
301 
302 #endif // ROBOTIS_MANIPULATOR_LOG_H
main namespace
void println(STRING str, STRING color="DEFAULT")
println
void print_vector(std::vector< T > &vec, uint8_t decimal_point=3)
print_vector
void print(STRING str, STRING color="DEFAULT")
print
std::string STRING
void print_matrix(matrix &m, uint8_t decimal_point=3)
print_matrix