ROSEndEffector
ROS End-Effector package: provides a ROS-based set of standard interfaces to command robotics end-effectors in an agnostic fashion.
Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
ROSEE::ActionPinchTight Class Reference

The action of pinch with two tips. More...

#include <ActionPinchTight.h>

+ Inheritance diagram for ROSEE::ActionPinchTight:
+ Collaboration diagram for ROSEE::ActionPinchTight:

Classes

struct  depthComp
 struct to put in order the actionStates. More...
 

Public Types

typedef std::map< std::pair< std::string, std::string >, ActionPinchTightMap
 
typedef std::pair< JointPos, collision_detection::Contact > StateWithContact
 A pair to "link" the JointPos with infos about the collision among the two tips. More...
 
- Public Types inherited from ROSEE::ActionPrimitive
enum  Type {
  PinchTight,
  PinchLoose,
  MultiplePinchTight,
  Trig,
  TipFlex,
  FingFlex,
  SingleJointMultipleTips,
  None
}
 Enum useful to discriminate each primitive action when, for example, we want to parse a file if you change this enum, change also the ROSEEControl.msg accordingly. More...
 
typedef std::shared_ptr< ActionPrimitivePtr
 
typedef std::shared_ptr< const ActionPrimitiveConstPtr
 
- Public Types inherited from ROSEE::Action
enum  Type {
  Primitive,
  Generic,
  Composed,
  Timed,
  None
}
 Enum useful to discriminate each action when, for example, we want to parse a file if you change this enum, change also the ROSEEControl.msg accordingly. More...
 
typedef std::shared_ptr< ActionPtr
 
typedef std::shared_ptr< const ActionConstPtr
 

Public Member Functions

 ActionPinchTight ()
 
 ActionPinchTight (unsigned int maxStoredActionStates)
 
 ActionPinchTight (std::pair< std::string, std::string >, JointPos, collision_detection::Contact)
 
 ActionPinchTight (std::string finger1, std::string finger2, JointPos, collision_detection::Contact)
 
JointPos getJointPos () const override
 Get the position related to this action. More...
 
JointPos getJointPos (unsigned int index) const
 
std::vector< ROSEE::JointPosgetAllJointPos () const override
 Return all the joint position stored. More...
 
std::vector< ROSEE::ActionPinchTight::StateWithContactgetActionStates () const
 Specific get for the ActionPinchTight to return the state with contact info. More...
 
bool insertActionState (JointPos, collision_detection::Contact)
 function to insert a single action in the actionStates set of possible action. More...
 
void print () const override
 For the pinch, we override these function to print, emit and parse the optional info Contact, which is specific of the pinch. More...
 
void emitYaml (YAML::Emitter &) const override
 Function to fill the argument passed with info about the action. More...
 
bool fillFromYaml (YAML::const_iterator yamlIt) override
 function to fill members of the Action with infos taken from yaml files More...
 
- Public Member Functions inherited from ROSEE::ActionPinchGeneric
 ActionPinchGeneric (std::string name, ActionPrimitive::Type type)
 KNOW the distance at a certain percentage? so se volgio prendere un oggetto largo 3 cm il programma sa quale รจ la percentage per avere una distanza di 3cm More...
 
 ActionPinchGeneric (std::string name, unsigned int maxStoredActionStates, ActionPrimitive::Type type)
 
 ActionPinchGeneric (std::string name, unsigned int nFingerInvolved, unsigned int maxStoredActionStates, ActionPrimitive::Type type)
 
std::set< std::string > getKeyElements () const override
 Necessary method to know the key used by the maps which store all the Actions of one type. More...
 
- Public Member Functions inherited from ROSEE::ActionPrimitive
virtual ~ActionPrimitive ()
 
Type getPrimitiveType () const
 
unsigned int getMaxStoredActionStates () const
 
unsigned int getnFingersInvolved () const
 
void setJointsInvolvedCount (ROSEE::JointsInvolvedCount jointsInvolvedCount)
 
- Public Member Functions inherited from ROSEE::Action
virtual ~Action ()
 
std::string getName () const
 Get the name of the action. More...
 
Type getType () const
 
std::set< std::string > getFingersInvolved () const
 Get for fingersInvolved. More...
 
JointsInvolvedCount getJointsInvolvedCount () const
 Get for jointsInvolvedCount. More...
 

Private Member Functions

bool emitYamlForContact (collision_detection::Contact, YAML::Emitter &) const
 private function to be called by the emitYaml More...
 

Private Attributes

std::set< StateWithContact, depthCompactionStates
 For each pair, we want a set of action because we want to store (in general) more possible way to do that action. More...
 

Additional Inherited Members

- Protected Member Functions inherited from ROSEE::ActionPrimitive
 ActionPrimitive (std::string name, unsigned int maxStoredActionStates, Type type)
 
 ActionPrimitive (std::string name, unsigned int nFingersInvolved, unsigned int maxStoredActionStates, Type type)
 Protected costructor: object creable only by derived classes. More...
 
- Protected Member Functions inherited from ROSEE::Action
 Action ()
 
 Action (std::string actionName, Action::Type type)
 
- Protected Attributes inherited from ROSEE::ActionPrimitive
unsigned int nFingersInvolved
 
const unsigned int maxStoredActionStates
 
const Type primitiveType
 
- Protected Attributes inherited from ROSEE::Action
std::string name
 
Action::Type type
 
std::set< std::string > fingersInvolved
 
JointsInvolvedCount jointsInvolvedCount
 

Detailed Description

The action of pinch with two tips.

The two tips must collide for some hand configuration to mark this configuration as a pinchTight. All the non involved fingers are set in the default state. A pinchTight is defined by:

Definition at line 40 of file ActionPinchTight.h.

Member Typedef Documentation

typedef std::map< std::pair<std::string, std::string>, ActionPinchTight > ROSEE::ActionPinchTight::Map

Definition at line 45 of file ActionPinchTight.h.

typedef std::pair<JointPos, collision_detection::Contact> ROSEE::ActionPinchTight::StateWithContact

A pair to "link" the JointPos with infos about the collision among the two tips.

Definition at line 49 of file ActionPinchTight.h.

Constructor & Destructor Documentation

ROSEE::ActionPinchTight::ActionPinchTight ( )

Definition at line 21 of file ActionPinchTight.cpp.

21  :
22  ActionPinchGeneric ("pinchTight", 2, 3, ActionPrimitive::Type::PinchTight) { }
ActionPinchGeneric(std::string name, ActionPrimitive::Type type)
KNOW the distance at a certain percentage? so se volgio prendere un oggetto largo 3 cm il programma s...
ROSEE::ActionPinchTight::ActionPinchTight ( unsigned int  maxStoredActionStates)

Definition at line 24 of file ActionPinchTight.cpp.

24  :
25  ActionPinchGeneric ("pinchTight", 2, jointStateSetMaxSize, ActionPrimitive::Type::PinchTight) { }
ActionPinchGeneric(std::string name, ActionPrimitive::Type type)
KNOW the distance at a certain percentage? so se volgio prendere un oggetto largo 3 cm il programma s...
ROSEE::ActionPinchTight::ActionPinchTight ( std::pair< std::string, std::string >  fingerNamesPair,
JointPos  jp,
collision_detection::Contact  cont 
)

Definition at line 27 of file ActionPinchTight.cpp.

28  :
29  ActionPinchGeneric ("pinchTight", 2, 3, ActionPrimitive::Type::PinchTight ) {
30 
31  //different from insertState, here we are sure the set is empty (we are in costructor)
32  fingersInvolved.insert(fingerNamesPair.first);
33  fingersInvolved.insert(fingerNamesPair.second);
34  actionStates.insert (std::make_pair (jp, cont) );
35 }
ActionPinchGeneric(std::string name, ActionPrimitive::Type type)
KNOW the distance at a certain percentage? so se volgio prendere un oggetto largo 3 cm il programma s...
std::set< StateWithContact, depthComp > actionStates
For each pair, we want a set of action because we want to store (in general) more possible way to do ...
std::set< std::string > fingersInvolved
Definition: Action.h:148
ROSEE::ActionPinchTight::ActionPinchTight ( std::string  finger1,
std::string  finger2,
JointPos  jp,
collision_detection::Contact  cont 
)

Definition at line 37 of file ActionPinchTight.cpp.

38  :
39  ActionPinchGeneric ("pinchTight", 2, 3, ActionPrimitive::Type::PinchTight ) {
40 
41  //different from insertState, here we are sure the set is empty (we are in costructor)
42  fingersInvolved.insert(finger1);
43  fingersInvolved.insert(finger2);
44  actionStates.insert (std::make_pair (jp, cont) );
45 }
ActionPinchGeneric(std::string name, ActionPrimitive::Type type)
KNOW the distance at a certain percentage? so se volgio prendere un oggetto largo 3 cm il programma s...
std::set< StateWithContact, depthComp > actionStates
For each pair, we want a set of action because we want to store (in general) more possible way to do ...
std::set< std::string > fingersInvolved
Definition: Action.h:148

Member Function Documentation

void ROSEE::ActionPinchTight::emitYaml ( YAML::Emitter &  out) const
overridevirtual

Function to fill the argument passed with info about the action.

Pure virtual because each derived class has different infos and stored differently. check YamlWorker to correctly emit and parse the file

Parameters
outthe yaml-cpp emitter which store infos about the action
Note
this function does not print in a file, but simply fill a YAML::Emitter.

Reimplemented from ROSEE::ActionPrimitive.

Definition at line 156 of file ActionPinchTight.cpp.

156  {
157 
158  out << YAML::Key << YAML::Flow << fingersInvolved;
159 
160  unsigned int nCont = 1;
161  out << YAML::Value << YAML::BeginMap;
162  out << YAML::Key << "PrimitiveType" << YAML::Value << primitiveType;
163  out << YAML::Key << "ActionName" << YAML::Value << name;
164  out << YAML::Key << "JointsInvolvedCount" << YAML::Value << YAML::BeginMap;
165  for (const auto &jointCount : jointsInvolvedCount ) {
166  out << YAML::Key << jointCount.first;
167  out << YAML::Value << jointCount.second;
168  }
169  out << YAML::EndMap;
170 
171  for (const auto & actionState : actionStates) { //.second is the set of ActionState
172 
173  std::string contSeq = "ActionState_" + std::to_string(nCont);
174  out << YAML::Key << contSeq;
175 
176  out << YAML::Value << YAML::BeginMap;
177  //actionState.first, the jointstates map
178  out << YAML::Key << "JointPos" << YAML::Value << YAML::BeginMap;
179  for (const auto &joint : actionState.first) {
180  out << YAML::Key << joint.first;
181  out << YAML::Value << YAML::Flow << joint.second; //vector of double is emitted like Seq
182  }
183  out << YAML::EndMap;
184 
185  //actionState.second, the optional
186  out << YAML::Key << "Optional" << YAML::Value;
187  emitYamlForContact ( actionState.second, out );
188 
189  out << YAML::EndMap;
190  nCont++;
191  }
192  out << YAML::EndMap;
193 
194 }
std::string name
Definition: Action.h:146
JointsInvolvedCount jointsInvolvedCount
Definition: Action.h:149
bool emitYamlForContact(collision_detection::Contact, YAML::Emitter &) const
private function to be called by the emitYaml
std::set< StateWithContact, depthComp > actionStates
For each pair, we want a set of action because we want to store (in general) more possible way to do ...
std::set< std::string > fingersInvolved
Definition: Action.h:148
bool ROSEE::ActionPinchTight::emitYamlForContact ( collision_detection::Contact  moveitContact,
YAML::Emitter &  out 
) const
private

private function to be called by the emitYaml

Definition at line 294 of file ActionPinchTight.cpp.

294  {
295 
296  out << YAML::BeginMap;
297  out << YAML::Key << "MoveItContact" << YAML::Value << YAML::BeginMap;
298  out << YAML::Key << "body_name_1";
299  out << YAML::Value << moveitContact.body_name_1;
300  out << YAML::Key << "body_name_2";
301  out << YAML::Value << moveitContact.body_name_2;
302  out << YAML::Key << "body_type_1";
303  out << YAML::Value << moveitContact.body_type_1;
304  out << YAML::Key << "body_type_2";
305  out << YAML::Value << moveitContact.body_type_2;
306  out << YAML::Key << "depth";
307  out << YAML::Value << moveitContact.depth;
308  out << YAML::Key << "normal";
309  std::vector < double > normal ( moveitContact.normal.data(), moveitContact.normal.data() + moveitContact.normal.rows());
310  out << YAML::Value << YAML::Flow << normal;
311  out << YAML::Key << "pos";
312  std::vector < double > pos ( moveitContact.pos.data(), moveitContact.pos.data() + moveitContact.pos.rows());
313  out << YAML::Value << YAML::Flow << pos;
314  out << YAML::EndMap;
315  out << YAML::EndMap;
316 
317  return true;
318 }
bool ROSEE::ActionPinchTight::fillFromYaml ( YAML::const_iterator  yamlIt)
overridevirtual

function to fill members of the Action with infos taken from yaml files

Parameters
yamlIta YAML::const_iterator to the node that is loaded with YAML::LoadFile(dirPath + filename). check YamlWorker to correctly parse and emit the file

Implements ROSEE::Action.

Definition at line 197 of file ActionPinchTight.cpp.

197  {
198 
199  std::vector <std::string> fingInvolvedVect = yamlIt->first.as <std::vector < std::string >> ();
200  for (const auto &it : fingInvolvedVect) {
201  fingersInvolved.insert(it);
202  }
203 
204  for ( YAML::const_iterator keyValue = yamlIt->second.begin(); keyValue != yamlIt->second.end(); ++keyValue) {
205 
206  std::string key = keyValue->first.as<std::string>();
207  if (key.compare("JointsInvolvedCount") == 0) {
208  jointsInvolvedCount = keyValue->second.as < JointsInvolvedCount > ();
209 
210  } else if (key.compare ("ActionName") == 0 ) {
211  name = keyValue->second.as <std::string> ();
212 
213  } else if (key.compare ("PrimitiveType") == 0) {
215  keyValue->second.as <unsigned int>() );
216  if (parsedType != primitiveType ) {
217  std::cerr << "[ERROR ActionPinchTight::" << __func__ << " parsed a type " << parsedType <<
218  " but this object has primitive type " << primitiveType << std::endl;
219  return false;
220  }
221 
222  } else if (key.compare(0, 12, "ActionState_") == 0) { //compare 12 caracters from index 0 of key
223 
224  JointPos jointPos;
225  collision_detection::Contact contact;
226  for(YAML::const_iterator asEl = keyValue->second.begin(); asEl != keyValue->second.end(); ++asEl) {
227 
228  //asEl can be the map JointPos or the map Optional
229  if (asEl->first.as<std::string>().compare ("JointPos") == 0 ) {
230  jointPos = asEl->second.as < JointPos >();
231  } else if (asEl->first.as<std::string>().compare ("Optional") == 0 ) {
232 
233  YAML::Node cont = asEl->second["MoveItContact"];
234  contact.body_name_1 = cont["body_name_1"].as < std::string >();
235  contact.body_name_2 = cont["body_name_2"].as < std::string >();
236  switch (cont["body_type_1"].as < int >())
237  {
238  case 0:
239  contact.body_type_1 = collision_detection::BodyType::ROBOT_LINK;
240  break;
241  case 1:
242  contact.body_type_1 = collision_detection::BodyType::ROBOT_ATTACHED;
243  break;
244  case 2:
245  contact.body_type_1 = collision_detection::BodyType::WORLD_OBJECT;
246  break;
247  default:
248  std::cout << "some error, body_type_1" << cont["body_type_1"].as < int >()
249  << "unknown" << std::endl;
250  contact.body_type_1 = collision_detection::BodyType::WORLD_OBJECT;
251  }
252  switch (cont["body_type_2"].as < int >())
253  {
254  case 0:
255  contact.body_type_2 = collision_detection::BodyType::ROBOT_LINK;
256  break;
257  case 1:
258  contact.body_type_2 = collision_detection::BodyType::ROBOT_ATTACHED;
259  break;
260  case 2:
261  contact.body_type_2 = collision_detection::BodyType::WORLD_OBJECT;
262  break;
263  default:
264  std::cout << "some error, body_type_2" << cont["body_type_2"].as < int >()
265  << "unknown" << std::endl;
266  contact.body_type_2 = collision_detection::BodyType::WORLD_OBJECT;
267  }
268  contact.depth = cont["depth"].as<double>();
269  std::vector < double > normVect = cont["normal"].as < std::vector <double> >();
270  std::vector < double > posVect = cont["pos"].as < std::vector <double> >();
271  contact.normal = Eigen::Vector3d (normVect.data() );
272  contact.pos = Eigen::Vector3d (posVect.data() );
273 
274  } else {
275  //ERRROr, only joinstates and optional at this level
276  std::cerr << "[ERROR ActionPinchTight::" << __func__ << "not know key "
277  << asEl->first.as<std::string>() <<
278  " found in the yaml file at this level" << std::endl;
279  return false;
280  }
281  }
282  actionStates.insert ( std::make_pair (jointPos, contact));
283 
284  } else {
285  std::cerr << "[ERROR ActionPinchTight::" << __func__ << "not know key " << key <<
286  " found in the yaml file" << std::endl;
287  return false;
288  }
289  }
290 
291  return true;
292 }
std::string name
Definition: Action.h:146
std::map< std::string, std::vector< double > > JointPos
The map to describe the position of all actuated joints.
Definition: Action.h:40
std::map< std::string, unsigned int > JointsInvolvedCount
The map to describe, how many times a joint is set by the action.
Definition: Action.h:63
Type
Enum useful to discriminate each primitive action when, for example, we want to parse a file if you ...
JointsInvolvedCount jointsInvolvedCount
Definition: Action.h:149
std::set< StateWithContact, depthComp > actionStates
For each pair, we want a set of action because we want to store (in general) more possible way to do ...
std::set< std::string > fingersInvolved
Definition: Action.h:148
std::vector< ROSEE::ActionPinchTight::StateWithContact > ROSEE::ActionPinchTight::getActionStates ( ) const

Specific get for the ActionPinchTight to return the state with contact info.

Returns
The vector (of size maxStoredActionStates) containing all the StateWithContact objects

Definition at line 73 of file ActionPinchTight.cpp.

73  {
74 
75  std::vector < ROSEE::ActionPinchTight::StateWithContact > retVect;
76  retVect.reserve ( actionStates.size() );
77 
78  for (auto it : actionStates ) {
79  retVect.push_back(it);
80  }
81 
82  return retVect;
83 
84 }
std::set< StateWithContact, depthComp > actionStates
For each pair, we want a set of action because we want to store (in general) more possible way to do ...
std::vector< ROSEE::JointPos > ROSEE::ActionPinchTight::getAllJointPos ( ) const
overridevirtual

Return all the joint position stored.

If the concrete (derived from Action) has only one joint position info, this function is equal to getJointPos.

Returns
vector containing all the joint pos of the action

Implements ROSEE::Action.

Definition at line 60 of file ActionPinchTight.cpp.

60  {
61 
62  std::vector < JointPos > retVect;
63  retVect.reserve ( actionStates.size() );
64 
65  for (auto it : actionStates ) {
66  retVect.push_back(it.first);
67  }
68 
69  return retVect;
70 }
std::set< StateWithContact, depthComp > actionStates
For each pair, we want a set of action because we want to store (in general) more possible way to do ...
ROSEE::JointPos ROSEE::ActionPinchTight::getJointPos ( ) const
overridevirtual

Get the position related to this action.

Pure Virtual function: the derived class store this info differently so they are in charge of providing the read.

Returns
JointsPos the map indicating how the position of the joint

Implements ROSEE::Action.

Definition at line 47 of file ActionPinchTight.cpp.

47  {
48  return (actionStates.begin()->first);
49 }
std::set< StateWithContact, depthComp > actionStates
For each pair, we want a set of action because we want to store (in general) more possible way to do ...
ROSEE::JointPos ROSEE::ActionPinchTight::getJointPos ( unsigned int  index) const

Definition at line 51 of file ActionPinchTight.cpp.

51  {
52  auto it = actionStates.begin();
53  unsigned int i = 1;
54  while (i < index ) {
55  ++ it;
56  }
57  return (it->first);
58 }
std::set< StateWithContact, depthComp > actionStates
For each pair, we want a set of action because we want to store (in general) more possible way to do ...
bool ROSEE::ActionPinchTight::insertActionState ( ROSEE::JointPos  jp,
collision_detection::Contact  cont 
)

function to insert a single action in the actionStates set of possible action.

If the action is not so good (based on depth now) the action is not inserted and the function return false

Parameters
JointPosThe joints position
collision_detection::Contactthe contact associated with the action
Returns
TRUE if the action is good and is inserted in the set actionStates FALSE if the action given as param was not good as the others in the set actionStates and the set was already full (maxStoredActionStates)

Definition at line 86 of file ActionPinchTight.cpp.

86  {
87 
88  auto pairRet = actionStates.insert ( std::make_pair (jp, cont) ) ;
89 
90  if (! pairRet.second ) {
91  //TODO print error no insertion because depth is equal... very improbable
92  return false;
93  }
94 
95  if (actionStates.size() > maxStoredActionStates) {
96  //max capacity reached, we have to delete the last one
97  auto it = pairRet.first;
98 
99  if ( (++it) == actionStates.end() ){
100  // the new inserted is the last one and has to be erased
101  actionStates.erase(pairRet.first);
102  return false;
103  }
104 
105  // the new inserted is not the last one that has to be erased
106  auto lastElem = actionStates.end();
107  --lastElem;
108  actionStates.erase(lastElem);
109  }
110 
111  return true;
112 }
const unsigned int maxStoredActionStates
std::set< StateWithContact, depthComp > actionStates
For each pair, we want a set of action because we want to store (in general) more possible way to do ...
void ROSEE::ActionPinchTight::print ( ) const
overridevirtual

For the pinch, we override these function to print, emit and parse the optional info Contact, which is specific of the pinch.

Reimplemented from ROSEE::Action.

Definition at line 115 of file ActionPinchTight.cpp.

115  {
116 
117  std::stringstream output;
118  output << "ActionName: " << name << std::endl;
119 
120  output << "FingersInvolved: [";
121  for (auto fingName : fingersInvolved){
122  output << fingName << ", " ;
123  }
124  output.seekp (-2, output.cur); //to remove the last comma (and space)
125  output << "]" << std::endl;
126 
127  output << "JointsInvolvedCount: " << std::endl;;
128  output << jointsInvolvedCount << std::endl;
129 
130  unsigned int nActState = 1;
131  for (auto itemSet : actionStates) { //the element in the set
132  output << "Action_State_" << nActState << " :" << std::endl;
133 
134  output << "\t" << "JointStates:" << std::endl;
135  output << itemSet.first;
136  output << "\t" << "MoveitContact:" << std::endl;
137  output << "\t\tbody_name_1: " << itemSet.second.body_name_1 << std::endl;
138  output << "\t\tbody_name_2: " << itemSet.second.body_name_2 << std::endl;
139  output << "\t\tbody_type_1: " << itemSet.second.body_type_1 << std::endl;
140  output << "\t\tbody_type_2: " << itemSet.second.body_type_2 << std::endl;
141  output << "\t\tdepth: " << itemSet.second.depth << std::endl;
142  output << "\t\tnormal: " << "["<< itemSet.second.normal.x() << ", "
143  << itemSet.second.normal.y() << ", " << itemSet.second.normal.z() << "]" << std::endl;
144  output << "\t\tpos: " << "["<< itemSet.second.pos.x() << ", "
145  << itemSet.second.pos.y() << ", " << itemSet.second.pos.z() << "]" << std::endl;
146 
147  nActState++;
148  }
149  output << std::endl;
150 
151  std::cout << output.str();
152 
153 }
std::string name
Definition: Action.h:146
JointsInvolvedCount jointsInvolvedCount
Definition: Action.h:149
std::set< StateWithContact, depthComp > actionStates
For each pair, we want a set of action because we want to store (in general) more possible way to do ...
std::set< std::string > fingersInvolved
Definition: Action.h:148

Member Data Documentation

std::set< StateWithContact, depthComp > ROSEE::ActionPinchTight::actionStates
private

For each pair, we want a set of action because we want to store (in general) more possible way to do that action.

The pinch among two tips can theoretically be done in infinite ways, we store the best ways found (ordering them by the depth of fingertips compenetration)

Definition at line 109 of file ActionPinchTight.h.


The documentation for this class was generated from the following files: