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 
19 #ifndef ROBOTIS_MANIPULATOR_LOG_H
20 #define ROBOTIS_MANIPULATOR_LOG_H
21 
22 #include <unistd.h>
23 #include <vector>
24 
25 #if defined(__OPENCR__)
26  #include <Eigen.h>
27  #include <WString.h>
28  #include "variant.h"
29 
30  #define DEBUG SerialBT2
31 #else
32  #include <string>
33 
34  #define ANSI_COLOR_RED "\x1b[31m"
35  #define ANSI_COLOR_GREEN "\x1b[32m"
36  #define ANSI_COLOR_YELLOW "\x1b[33m"
37  #define ANSI_COLOR_BLUE "\x1b[34m"
38  #define ANSI_COLOR_MAGENTA "\x1b[35m"
39  #define ANSI_COLOR_CYAN "\x1b[36m"
40  #define ANSI_COLOR_RESET "\x1b[0m"
41 #endif
42 
43 #if defined(__OPENCR__)
44  typedef String STRING;
45 #else
46  typedef std::string STRING;
47 #endif
48 
49 namespace robotis_manipulator
50 {
51 namespace log{
52 
53  void print(STRING str, STRING color = "DEFAULT");
54  void print(STRING str, double data, uint8_t decimal_point = 3, STRING color = "DEFAULT");
55  void print(const char* str, STRING color = "DEFAULT");
56  void print(const char* str, double data, uint8_t decimal_point = 3, STRING color = "DEFAULT");
57 
58  void println(STRING str, STRING color = "DEFAULT");
59  void println(STRING str, double data, uint8_t decimal_point = 3, STRING color = "DEFAULT");
60  void println(const char* str, STRING color = "DEFAULT");
61  void println(const char* str, double data, uint8_t decimal_point = 3, STRING color = "DEFAULT");
62 
63  void info(STRING str);
64  void info(STRING str, double data, uint8_t decimal_point = 3);
65  void info(const char* str);
66  void info(const char* str, double data, uint8_t decimal_point = 3);
67  void warn(STRING str);
68  void warn(STRING str, double data, uint8_t decimal_point = 3);
69  void warn(const char* str);
70  void warn(const char* str, double data, uint8_t decimal_point = 3);
71  void error(STRING str);
72  void error(STRING str, double data, uint8_t decimal_point = 3);
73  void error(const char* str);
74  void error(const char* str, double data, uint8_t decimal_point = 3);
75 
76  template <typename T> void print_vector(std::vector<T> &vec, uint8_t decimal_point = 3)
77  {
78  #if defined(__OPENCR__)
79  DEBUG.print("(");
80  for (uint8_t i = 0; i < vec.size(); i++)
81  {
82  DEBUG.print(vec.at(i), decimal_point);
83  if(i != vec.size()-1)
84  DEBUG.print(", ");
85  else
86  DEBUG.println(")");
87  }
88  #else
89  printf("(");
90  for (uint8_t i = 0; i < vec.size(); i++)
91  {
92  printf("%.*lf", decimal_point, vec.at(i));
93  if(i != vec.size()-1)
94  printf(", ");
95  else
96  printf(")\n");
97  }
98  #endif
99  }
100 
101  template <typename vector> void print_vector(vector &vec, uint8_t decimal_point = 3)
102  {
103  #if defined(__OPENCR__)
104  DEBUG.print("(");
105  for (uint8_t i = 0; i < vec.size(); i++)
106  {
107  DEBUG.print(vec(i), decimal_point);
108  if(i != vec.size()-1)
109  DEBUG.print(", ");
110  else
111  DEBUG.println(")");
112  }
113  #else
114  printf("(");
115  for (uint8_t i = 0; i < vec.size(); i++)
116  {
117  printf("%.*lf", decimal_point, vec(i));
118  if(i != vec.size()-1)
119  printf(", ");
120  else
121  printf(")\n");
122  }
123  #endif
124  }
125 
126  template <typename matrix> void print_matrix(matrix &m, uint8_t decimal_point = 3)
127  {
128  #if defined(__OPENCR__)
129 
130  for (uint8_t i = 0; i < m.rows(); i++)
131  {
132  if(i == 0)
133  DEBUG.print("(");
134  else
135  DEBUG.print(" ");
136  for (uint8_t j = 0; j < m.cols(); j++)
137  {
138  DEBUG.print(m(i, j), decimal_point);
139  if(j != m.cols()-1)
140  DEBUG.print(", ");
141  }
142  if(i != m.rows()-1)
143  DEBUG.println("");
144  else
145  DEBUG.println(")");
146  }
147  #else
148 
149  for (uint8_t i = 0; i < m.rows(); i++)
150  {
151  if(i == 0)
152  printf("(");
153  else
154  printf(" ");
155  for (uint8_t j = 0; j < m.cols(); j++)
156  {
157  printf("%.*lf", decimal_point, m(i, j));
158  if(j != m.cols()-1)
159  printf(", ");
160  }
161  if(i != m.rows()-1)
162  printf("\n");
163  else
164  printf(")\n");
165  }
166  #endif
167  }
168 
169 } //log
170 } //robotis_manipulator
171 
172 #endif // ROBOTIS_MANIPULATOR_LOG_H
void println(STRING str, STRING color="DEFAULT")
void print_vector(std::vector< T > &vec, uint8_t decimal_point=3)
void print(STRING str, STRING color="DEFAULT")
std::string STRING
void print_matrix(matrix &m, uint8_t decimal_point=3)


robotis_manipulator
Author(s): Hye-Jong KIM , Darby Lim , Yong-Ho Na , Ryan Shim
autogenerated on Sat Oct 3 2020 03:14:51