iCub-main
common.h
Go to the documentation of this file.
1 
22 #ifndef __COMMON_H__
23 #define __COMMON_H__
24 
25 #include <yarp/sig/Vector.h>
26 #include <yarp/sig/Matrix.h>
27 #include <string>
28 #include <vector>
29 #include <map>
30 #include <list>
31 
32 namespace iCub
33 {
34 
35 namespace skinDynLib
36 {
37 
39 
40 // DEFINE BODY PARTS AND SKIN PARTS OF ICUB ROBOT
41 #ifndef NAO_SKIN
42 
43 // List of the parts of the iCub body
44 enum BodyPart {
48 };
50  "unknown_body_part",
51  "torso", "head", "left_arm", "right_arm", "left_leg", "right_leg",
52  "all_body_parts", "lower_body_parts", "upper_body_parts", "body_part_size"
53 };
54 
55 // List of the parts composing the skin of iCub
56 enum SkinPart {
63 };
65  "unknown",
66  "l_hand", "l_forearm", "l_upper_arm",
67  "r_hand", "r_forearm", "r_upper_arm",
68  "chest",
69  "l_upper_leg", "l_lower_leg", "l_foot",
70  "r_upper_leg", "r_lower_leg", "r_foot",
71  "all_skin_parts", "skin_part_size"
72 };
73 
74 // *** Mapping from SKIN PARTs to BODY PARTs ***
75 // To represent this information we use a vector of struct{SkinPart; BodyPart;}
87 };
88 
89 // association between each skin part and the number of the link where it is mounted
90 struct Skin_2_Link{ SkinPart skin; int linkNum; };
92  {SKIN_PART_UNKNOWN, -1},
93  {SKIN_LEFT_HAND, 6},
94  {SKIN_LEFT_FOREARM, 4},
95  {SKIN_LEFT_UPPER_ARM, 2},
96  {SKIN_RIGHT_HAND, 6},
97  {SKIN_RIGHT_FOREARM, 4},
99  {SKIN_FRONT_TORSO, 2},
100  {SKIN_PART_ALL, -1}
101 };
102 #endif
103 
104 // DEFINE BODY PARTS AND SKIN PARTS OF NAO ROBOT
105 #ifdef NAO_SKIN
106 // List of the parts of the iCub body
107 enum BodyPart {
111 };
112 const std::string BodyPart_s[] = {
113  "unknown_body_part",
114  "head", "torso", "left_arm", "right_arm", "left_leg", "right_leg",
115  "all_body_parts", "body_part_size"
116 };
117 
118 // List of the parts composing the skin of iCub
119 enum SkinPart {
121  SKIN_LEFT_HAND, SKIN_LEFT_ARM,
122  SKIN_RIGHT_HAND, SKIN_RIGHT_ARM,
124 };
125 const std::string SkinPart_s[] = {
126  "unknown_skin_part",
127  "skin_left_hand", "skin_left_arm",
128  "skin_right_hand", "skin_right_arm",
129  "all_skin_parts", "skin_part_size"
130 };
131 
132 // association between each skin part and the corresponding body part
133 struct Skin_2_Body { SkinPart skin; BodyPart body; };
134 const Skin_2_Body SkinPart_2_BodyPart[SKIN_PART_SIZE] = {
137  {SKIN_LEFT_ARM, LEFT_ARM},
139  {SKIN_RIGHT_ARM, RIGHT_ARM},
141 };
142 
143 // association between each skin part and the number of the link where it is mounted
144 struct Skin_2_Link{ SkinPart skin; int linkNum; };
145 const Skin_2_Link SkinPart_2_LinkNum[SKIN_PART_SIZE] = {
146  {SKIN_PART_UNKNOWN, -1},
147  {SKIN_LEFT_HAND, -1},
148  {SKIN_LEFT_ARM, -1},
149  {SKIN_RIGHT_HAND, -1},
150  {SKIN_RIGHT_ARM, -1},
151  {SKIN_PART_ALL, -1}
152 };
153 #endif
154 
155 enum HandPart {
158 };
160  "index", "middle", "ring", "little", "thumb", "palm",
161  "all_hand_parts", "hand_part_size"
162 };
163 
164 static const int ARM_FT_SENSOR_LINK_INDEX = 2; // index of the link containing the F/T sensor in the iCub arms
165 static const int LEG_FT_SENSOR_LINK_INDEX = 1; // index of the link containing the F/T sensor in the iCub legs
166 
167 static const int ARM_DOF = 7;
168 static const int TORSO_DOF = 3;
169 
178 
186 std::vector<SkinPart> getSkinParts(BodyPart b);
187 
195 int getLinkNum(SkinPart s);
196 
204 SkinPart getSkinPartFromString(const std::string skinPartString);
205 
206 
207 
214 yarp::sig::Vector toVector(yarp::sig::Matrix m);
215 
224 yarp::sig::Vector vectorFromBottle(const yarp::os::Bottle b, int in, const int size);
225 
232 void vectorIntoBottle(const yarp::sig::Vector v, yarp::os::Bottle &b);
233 
242 yarp::sig::Matrix matrixFromBottle(const yarp::os::Bottle b, int in, const int r, const int c);
243 
250 void matrixIntoBottle(const yarp::sig::Matrix m, yarp::os::Bottle &b);
251 
259 inline std::list<unsigned int> vectorofIntEqualto(const std::vector<int> vec, const int val)
260 {
261  std::list<unsigned int> res;
262  for (size_t i = 0; i < vec.size(); i++)
263  {
264  if (vec[i]==val)
265  {
266  res.push_back(i);
267  }
268  }
269  return res;
270 };
271 
272 }
273 
274 }//end namespace
275 
276 #endif
277 
278 
iCub::skinDynLib::SKIN_FRONT_TORSO
@ SKIN_FRONT_TORSO
Definition: common.h:60
iCub::skinDynLib::BODY_PART_UNKNOWN
@ BODY_PART_UNKNOWN
Definition: common.h:45
iCub::skinDynLib::SKIN_LEFT_HAND
@ SKIN_LEFT_HAND
Definition: common.h:58
iCub::skinDynLib::HandPart_s
const std::string HandPart_s[]
Definition: common.h:159
iCub::skinDynLib::HAND_PART_SIZE
@ HAND_PART_SIZE
Definition: common.h:157
iCub
This file contains the definition of unique IDs for the body parts and the skin parts of the robot.
Definition: emotionInterface.h:17
iCub::skinDynLib::SkinPart_2_BodyPart
const Skin_2_Body SkinPart_2_BodyPart[SKIN_PART_SIZE]
Definition: common.h:77
iCub::skinDynLib::PALM
@ PALM
Definition: common.h:156
iCub::skinDynLib::RING
@ RING
Definition: common.h:156
iCub::skinDynLib::ARM_FT_SENSOR_LINK_INDEX
static const int ARM_FT_SENSOR_LINK_INDEX
Definition: common.h:164
iCub::skinDynLib::vectorofIntEqualto
std::list< unsigned int > vectorofIntEqualto(const std::vector< int > vec, const int val)
Definition: common.h:259
iCub::skinDynLib::BODY_PART_SIZE
@ BODY_PART_SIZE
Definition: common.h:47
iCub::skinDynLib::NO_VERBOSE
@ NO_VERBOSE
Definition: common.h:38
iCub::skinDynLib::Skin_2_Body::skin
SkinPart skin
Definition: common.h:76
iCub::skinDynLib::HandPart
HandPart
Definition: common.h:155
iCub::skinDynLib::RIGHT_LEG
@ RIGHT_LEG
Definition: common.h:46
iCub::skinDynLib::LEFT_LEG_LOWER
@ LEFT_LEG_LOWER
Definition: common.h:60
iCub::skinDynLib::getSkinPartFromString
SkinPart getSkinPartFromString(const std::string skinPartString)
Definition: common.cpp:42
iCub::skinDynLib::LEG_FT_SENSOR_LINK_INDEX
static const int LEG_FT_SENSOR_LINK_INDEX
Definition: common.h:165
iCub::skinDynLib::VerbosityLevel
VerbosityLevel
Definition: common.h:38
iCub::skinDynLib::LEFT_ARM
@ LEFT_ARM
Definition: common.h:46
iCub::skinDynLib::RIGHT_ARM
@ RIGHT_ARM
Definition: common.h:46
iCub::skinDynLib::SkinPart_2_LinkNum
const Skin_2_Link SkinPart_2_LinkNum[SKIN_PART_SIZE]
Definition: common.h:91
iCub::skinDynLib::RIGHT_LEG_LOWER
@ RIGHT_LEG_LOWER
Definition: common.h:61
iCub::skinDynLib::SKIN_RIGHT_UPPER_ARM
@ SKIN_RIGHT_UPPER_ARM
Definition: common.h:59
iCub::skinDynLib::matrixFromBottle
yarp::sig::Matrix matrixFromBottle(const yarp::os::Bottle b, int in, const int r, const int c)
Retrieves a matrix from a bottle.
Definition: common.cpp:109
iCub::skinDynLib::getLinkNum
int getLinkNum(SkinPart s)
Definition: common.cpp:34
iCub::skinDynLib::BODY_PART_ALL
@ BODY_PART_ALL
Definition: common.h:47
iCub::skinDynLib::Skin_2_Body::body
BodyPart body
Definition: common.h:76
iCub::skinDynLib::toVector
yarp::sig::Vector toVector(yarp::sig::Matrix m)
Definition: common.cpp:77
iCub::skinDynLib::SKIN_PART_ALL
@ SKIN_PART_ALL
Definition: common.h:62
iCub::skinDynLib::UPPER_BODY_PARTS
@ UPPER_BODY_PARTS
Definition: common.h:47
iCub::skinDynLib::ARM_DOF
static const int ARM_DOF
Definition: common.h:167
iCub::skinDynLib::MORE_VERBOSE
@ MORE_VERBOSE
Definition: common.h:38
iCub::skinDynLib::THUMB
@ THUMB
Definition: common.h:156
iCub::skinDynLib::ALL_HAND_PARTS
@ ALL_HAND_PARTS
Definition: common.h:157
iCub::skinDynLib::SKIN_PART_UNKNOWN
@ SKIN_PART_UNKNOWN
Definition: common.h:57
iCub::skinDynLib::LEFT_LEG_UPPER
@ LEFT_LEG_UPPER
Definition: common.h:60
string
string(REPLACE "-rdynamic" "" CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS}") include_directories($
Definition: CMakeLists.txt:9
iCub::skinDynLib::VERBOSE
@ VERBOSE
Definition: common.h:38
iCub::skinDynLib::SKIN_PART_SIZE
@ SKIN_PART_SIZE
Definition: common.h:62
iCub::skinDynLib::SkinPart
SkinPart
Definition: common.h:56
iCub::skinDynLib::RIGHT_FOOT
@ RIGHT_FOOT
Definition: common.h:61
iCub::skinDynLib::LEFT_LEG
@ LEFT_LEG
Definition: common.h:46
iCub::skinDynLib::LOWER_BODY_PARTS
@ LOWER_BODY_PARTS
Definition: common.h:47
iCub::skinDynLib::SkinPart_s
const std::string SkinPart_s[]
Definition: common.h:64
iCub::skinDynLib::LEFT_FOOT
@ LEFT_FOOT
Definition: common.h:60
iCub::skinDynLib::RIGHT_LEG_UPPER
@ RIGHT_LEG_UPPER
Definition: common.h:61
iCub::skinDynLib::BodyPart
BodyPart
Definition: common.h:44
iCub::skinDynLib::INDEX
@ INDEX
Definition: common.h:156
iCub::skinDynLib::SKIN_RIGHT_FOREARM
@ SKIN_RIGHT_FOREARM
Definition: common.h:59
v
static int v
Definition: iCub_Sim.cpp:42
iCub::skinDynLib::TORSO
@ TORSO
Definition: common.h:46
iCub::skinDynLib::SKIN_RIGHT_HAND
@ SKIN_RIGHT_HAND
Definition: common.h:59
iCub::skinDynLib::LITTLE
@ LITTLE
Definition: common.h:156
iCub::skinDynLib::TORSO_DOF
static const int TORSO_DOF
Definition: common.h:168
iCub::skinDynLib::getBodyPart
BodyPart getBodyPart(SkinPart s)
Definition: common.cpp:26
iCub::skinDynLib::BodyPart_s
const std::string BodyPart_s[]
Definition: common.h:49
iCub::skinDynLib::SKIN_LEFT_FOREARM
@ SKIN_LEFT_FOREARM
Definition: common.h:58
iCub::skinDynLib::Skin_2_Body
Definition: common.h:76
iCub::skinDynLib::matrixIntoBottle
void matrixIntoBottle(const yarp::sig::Matrix m, yarp::os::Bottle &b)
Puts a matrix into a bottle, by cycling through its elements and adding them as double.
Definition: common.cpp:126
iCub::skinDynLib::vectorFromBottle
yarp::sig::Vector vectorFromBottle(const yarp::os::Bottle b, int in, const int size)
Definition: common.cpp:89
iCub::skinDynLib::SKIN_LEFT_UPPER_ARM
@ SKIN_LEFT_UPPER_ARM
Definition: common.h:58
iCub::skinDynLib::HEAD
@ HEAD
Definition: common.h:46
iCub::skinDynLib::MIDDLE
@ MIDDLE
Definition: common.h:156
iCub::skinDynLib::getSkinParts
std::vector< SkinPart > getSkinParts(BodyPart b)
Definition: common.cpp:17
iCub::skinDynLib::vectorIntoBottle
void vectorIntoBottle(const yarp::sig::Vector v, yarp::os::Bottle &b)
Puts a Vector into a bottle, by cycling through its elements and adding them as doubles.
Definition: common.cpp:101