ocra-recipes
Doxygen documentation for the ocra-recipes repository
TaskYarpInterfaceVocab.cpp
Go to the documentation of this file.
2 
3 
4 using namespace ocra;
5 
6 const std::vector<std::string> TaskMessageHandler::TASK_MESSAGES_AS_STRINGS(
7 {
8 "OCRA_FAILURE",
9 "OCRA_SUCCESS",
10 "OCRA_WARNING",
11 "GET_CURRENT_STATE",
12 "GET_STIFFNESS",
13 "GET_DAMPING",
14 "GET_WEIGHTS",
15 "GET_ACTIVITY_STATUS",
16 "GET_DIMENSION",
17 "GET_TYPE",
18 "GET_TYPE_AS_STRING",
19 "GET_NAME",
20 "GET_CONTROL_PORT_NAMES",
21 "GET_TASK_PORT_NAME",
22 "GET_TASK_ERROR",
23 "GET_TASK_STATE",
24 "GET_DESIRED_TASK_STATE",
25 "GET_TASK_POSITION",
26 "GET_DESIRED_TASK_POSITION",
27 "SET_STIFFNESS",
28 "SET_STIFFNESS_VECTOR",
29 "SET_STIFFNESS_MATRIX",
30 "SET_DAMPING",
31 "SET_DAMPING_VECTOR",
32 "SET_DAMPING_MATRIX",
33 "SET_WEIGHT",
34 "SET_WEIGHT_VECTOR",
35 "SET_DESIRED_TASK_STATE",
36 "SET_DESIRED_TASK_POSITION",
37 "ACTIVATE",
38 "DEACTIVATE",
39 "TASK_IS_ACTIVATED",
40 "TASK_IS_DEACTIVATED",
41 "OPEN_CONTROL_PORTS",
42 "CLOSE_CONTROL_PORTS",
43 "HELP"
44 });
45 
46 
48 {
49  if ((msg >= TASK_MESSAGES_AS_STRINGS.size()) || msg < 0) {
50  return "";
51  }
52  return TASK_MESSAGES_AS_STRINGS[msg];
53 }
54 
55 std::string TaskMessageHandler::removeUnderscores(std::string s)
56 {
57  std::regex e ("_*");
58  std::string empty("");
59  return std::regex_replace (s,e,empty);
60 }
61 
63 {
64  // Convert to upper case
65  std::transform(testString.begin(), testString.end(),testString.begin(), ::toupper);
66  // Check tags "as is" i.e. with the underscores.
67  for (int i=0; i<TASK_MESSAGES_AS_STRINGS.size(); ++i)
68  {
69  std::string s = TASK_MESSAGES_AS_STRINGS[i];
70  if (testString == s) {
71  return TASK_MESSAGE(i);
72  }
73  }
74  // If the match hasn't been found then loop through again and check without underscores
75  for (int i=0; i<TASK_MESSAGES_AS_STRINGS.size(); ++i)
76  {
77  std::string s = removeUnderscores(TASK_MESSAGES_AS_STRINGS[i]);
78  if (testString == s) {
79  return TASK_MESSAGE(i);
80  }
81  }
82 
84 }
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
static std::string taskManagerMessageTagToString(TASK_MESSAGE msg)
static TASK_MESSAGE stringToTaskManagerMessageTag(std::string testString)
static std::string removeUnderscores(std::string s)
static const std::vector< std::string > TASK_MESSAGES_AS_STRINGS