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 Attributes | List of all members
ROSEE::ActionMultiplePinchTight Class Reference

Class to describe the action of "pinching" with more than 2 tips (with 2 tips there is the ActionPinchTight and ActionPinchLoose The number of the finger used is fixed when the object is costructed, and it is stored in the father member nFingersInvolved. More...

#include <ActionMultiplePinchTight.h>

+ Inheritance diagram for ROSEE::ActionMultiplePinchTight:
+ Collaboration diagram for ROSEE::ActionMultiplePinchTight:

Classes

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

Public Types

typedef std::map< std::set< std::string >, ActionMultiplePinchTightMap
 
typedef std::pair< JointPos, double > StateWithDepth
 A pair to "link" the JointPos with the depthSum info to order the StateWithDepth in the actionState set. 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

 ActionMultiplePinchTight ()
 
 ActionMultiplePinchTight (unsigned int maxStoredActionStates)
 
 ActionMultiplePinchTight (std::set< std::string >, JointPos, double depthSum)
 
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::ActionMultiplePinchTight::StateWithDepthgetActionStates () const
 Specific get for the ActionMultiplePinchTight to return the state with the paired depthSum. More...
 
bool insertActionState (JointPos, double depthSum)
 function to insert a single action in the actionStates set of possible action. More...
 
void print () const override
 Overridable functions, if we want to make them more action-specific. 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 Attributes

std::set< StateWithDepth, depthCompactionStates
 For each multiple pinch possible, we want a set of action because we want to store (in general) more possible way to do that action with that X fingers. 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

Class to describe the action of "pinching" with more than 2 tips (with 2 tips there is the ActionPinchTight and ActionPinchLoose The number of the finger used is fixed when the object is costructed, and it is stored in the father member nFingersInvolved.

A pinchMultipleTight is defined by:

Note
When exploring the model to find this action, there are two possibility: we can look for a position where all the X fingertips collide among each other (causing EXACTLY bynomial_coeff(X, 2) collisions pair), or, with a "less strict" condition, a position where not all fingertips must collide between each other (causing AT LEAST X-1 collisions). The default is the "more strict" condition, because it can find "better looking" mulPinches, even if obviously we find less possible way to perform the action. With this, it seems better to order the actionState considering as "best" the position where the tips collide less, i.e. where the depthSum is lower. This is the opposite from the normal tight pinch. This cause anyway a collision, but not a ugly one where the tips compenetrate too much. This thing can change if we invert the sign in the depthComp comparison

Definition at line 48 of file ActionMultiplePinchTight.h.

Member Typedef Documentation

typedef std::map< std::set<std::string>, ActionMultiplePinchTight > ROSEE::ActionMultiplePinchTight::Map

Definition at line 53 of file ActionMultiplePinchTight.h.

A pair to "link" the JointPos with the depthSum info to order the StateWithDepth in the actionState set.

Definition at line 56 of file ActionMultiplePinchTight.h.

Constructor & Destructor Documentation

ROSEE::ActionMultiplePinchTight::ActionMultiplePinchTight ( )

Definition at line 21 of file ActionMultiplePinchTight.cpp.

21  :
22  ActionPinchGeneric ("multiplePinchTight", 3, ActionPrimitive::Type::MultiplePinchTight) { }
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::ActionMultiplePinchTight::ActionMultiplePinchTight ( unsigned int  maxStoredActionStates)

Definition at line 24 of file ActionMultiplePinchTight.cpp.

24  :
25  ActionPinchGeneric ("multiplePinchTight", maxStoredActionStates, ActionPrimitive::Type::MultiplePinchTight) { }
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...
const unsigned int maxStoredActionStates
ROSEE::ActionMultiplePinchTight::ActionMultiplePinchTight ( std::set< std::string >  fingerNamesSet,
JointPos  jp,
double  depthSum 
)

Definition at line 27 of file ActionMultiplePinchTight.cpp.

29  :
30  ActionPinchGeneric ( ("multiplePinchTight_" + std::to_string(fingerNamesSet.size())),
31  fingerNamesSet.size(), 3, ActionPrimitive::Type::MultiplePinchTight ) {
32 
33  //different from insertState, here we are sure the set is empty (we are in costructor)
34  fingersInvolved = fingerNamesSet;
35  actionStates.insert (std::make_pair (jp, depthSum) );
36 }
std::set< StateWithDepth, depthComp > actionStates
For each multiple pinch possible, we want a set of action because we want to store (in general) more ...
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< std::string > fingersInvolved
Definition: Action.h:148

Member Function Documentation

void ROSEE::ActionMultiplePinchTight::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 140 of file ActionMultiplePinchTight.cpp.

140  {
141 
142  out << YAML::Key << YAML::Flow << fingersInvolved;
143 
144  unsigned int nCont = 1;
145  out << YAML::Value << YAML::BeginMap;
146  out << YAML::Key << "PrimitiveType" << YAML::Value << primitiveType;
147  out << YAML::Key << "ActionName" << YAML::Value << name;
148  out << YAML::Key << "JointsInvolvedCount" << YAML::Value << YAML::BeginMap;
149  for (const auto &jointCount : jointsInvolvedCount ) {
150  out << YAML::Key << jointCount.first;
151  out << YAML::Value << jointCount.second;
152  }
153  out << YAML::EndMap;
154 
155  for (const auto & actionState : actionStates) { //.second is the set of ActionState
156 
157  std::string contSeq = "ActionState_" + std::to_string(nCont);
158  out << YAML::Key << contSeq;
159 
160  out << YAML::Value << YAML::BeginMap;
161  //actionState.first, the jointstates map
162  out << YAML::Key << "JointPos" << YAML::Value << YAML::BeginMap;
163  for (const auto &joint : actionState.first) {
164  out << YAML::Key << joint.first;
165  out << YAML::Value << YAML::Flow << joint.second; //vector of double is emitted like Seq
166  }
167  out << YAML::EndMap;
168 
169  //actionState.second, the optional
170  out << YAML::Key << "Optional" << YAML::Value << YAML::BeginMap;
171  out << YAML::Key << "DepthSum" << YAML::Value << actionState.second;
172  out << YAML::EndMap;
173 
174  out << YAML::EndMap;
175  nCont++;
176  }
177  out << YAML::EndMap;
178 
179 }
std::string name
Definition: Action.h:146
std::set< StateWithDepth, depthComp > actionStates
For each multiple pinch possible, we want a set of action because we want to store (in general) more ...
JointsInvolvedCount jointsInvolvedCount
Definition: Action.h:149
std::set< std::string > fingersInvolved
Definition: Action.h:148
bool ROSEE::ActionMultiplePinchTight::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 182 of file ActionMultiplePinchTight.cpp.

182  {
183 
184  std::vector <std::string> fingInvolvedVect = yamlIt->first.as <std::vector < std::string >> ();
185  for (const auto &it : fingInvolvedVect) {
186  fingersInvolved.insert(it);
187  }
188 
189  for ( YAML::const_iterator keyValue = yamlIt->second.begin(); keyValue != yamlIt->second.end(); ++keyValue) {
190 
191  std::string key = keyValue->first.as<std::string>();
192  if (key.compare("JointsInvolvedCount") == 0) {
193  jointsInvolvedCount = keyValue->second.as < JointsInvolvedCount > ();
194 
195  } else if (key.compare ("ActionName") == 0 ) {
196  name = keyValue->second.as <std::string> ();
197 
198  } else if (key.compare ("PrimitiveType") == 0) {
200  keyValue->second.as <unsigned int>() );
201  if (parsedType != primitiveType ) {
202  std::cerr << "[ERROR ActionMultPinch::" << __func__ << " parsed a type " << parsedType <<
203  " but this object has primitive type " << primitiveType << std::endl;
204  return false;
205  }
206 
207  } else if (key.compare(0, 12, "ActionState_") == 0) { //compare 12 caracters from index 0 of key
208 
209  JointPos jointPos;
210  double depthSum;
211  for(YAML::const_iterator asEl = keyValue->second.begin(); asEl != keyValue->second.end(); ++asEl) {
212 
213  //asEl can be the map JointPos or the map Optional
214  if (asEl->first.as<std::string>().compare ("JointPos") == 0 ) {
215  jointPos = asEl->second.as < JointPos >();
216 
217  } else if (asEl->first.as<std::string>().compare ("Optional") == 0 ) {
218  depthSum = asEl->second["DepthSum"].as < double >();
219 
220  } else {
221  //ERRROr, only JointPos and Optional at this level
222  std::cerr << "[ERROR ActionMultPinch::" << __func__ << "not know key "
223  << asEl->first.as<std::string>() <<
224  " found in the yaml file at this level" << std::endl;
225  return false;
226  }
227  }
228  actionStates.insert ( std::make_pair (jointPos, depthSum));
229 
230  } else {
231  std::cerr << "[ERROR ActionMultPinch::" << __func__ << "not know key " << key <<
232  " found in the yaml file" << std::endl;
233  return false;
234  }
235  }
236 
238 
239  return true;
240 }
unsigned int nFingersInvolved
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 ...
std::set< StateWithDepth, depthComp > actionStates
For each multiple pinch possible, we want a set of action because we want to store (in general) more ...
JointsInvolvedCount jointsInvolvedCount
Definition: Action.h:149
std::set< std::string > fingersInvolved
Definition: Action.h:148
std::vector< ROSEE::ActionMultiplePinchTight::StateWithDepth > ROSEE::ActionMultiplePinchTight::getActionStates ( ) const

Specific get for the ActionMultiplePinchTight to return the state with the paired depthSum.

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

Definition at line 65 of file ActionMultiplePinchTight.cpp.

65  {
66 
67  std::vector < ROSEE::ActionMultiplePinchTight::StateWithDepth > retVect;
68  retVect.reserve ( actionStates.size() );
69 
70  for (auto it : actionStates ) {
71  retVect.push_back(it);
72  }
73 
74  return retVect;
75 
76 }
std::set< StateWithDepth, depthComp > actionStates
For each multiple pinch possible, we want a set of action because we want to store (in general) more ...
std::vector< ROSEE::JointPos > ROSEE::ActionMultiplePinchTight::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 52 of file ActionMultiplePinchTight.cpp.

52  {
53 
54  std::vector < JointPos > retVect;
55  retVect.reserve ( actionStates.size() );
56 
57  for (auto it : actionStates ) {
58  retVect.push_back(it.first);
59  }
60 
61  return retVect;
62 }
std::set< StateWithDepth, depthComp > actionStates
For each multiple pinch possible, we want a set of action because we want to store (in general) more ...
ROSEE::JointPos ROSEE::ActionMultiplePinchTight::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 39 of file ActionMultiplePinchTight.cpp.

39  {
40  return (actionStates.begin()->first);
41 }
std::set< StateWithDepth, depthComp > actionStates
For each multiple pinch possible, we want a set of action because we want to store (in general) more ...
ROSEE::JointPos ROSEE::ActionMultiplePinchTight::getJointPos ( unsigned int  index) const

Definition at line 43 of file ActionMultiplePinchTight.cpp.

43  {
44  auto it = actionStates.begin();
45  unsigned int i = 1;
46  while (i < index ) {
47  ++ it;
48  }
49  return (it->first);
50 }
std::set< StateWithDepth, depthComp > actionStates
For each multiple pinch possible, we want a set of action because we want to store (in general) more ...
bool ROSEE::ActionMultiplePinchTight::insertActionState ( ROSEE::JointPos  jp,
double  depthSum 
)

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

If the action is not so good (depthSum) the action is not inserted and the function return false

Parameters
JointPosThe joints position
depthSumthe sum of all depth of collisions pairs
Returns
TRUE if the action is good and is inserted in the set actionStates FALSE if the action given as argument was not good as the others in the set actionStates and the set was already full (maxStoredActionStates)

Definition at line 78 of file ActionMultiplePinchTight.cpp.

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

Overridable functions, if we want to make them more action-specific.

Reimplemented from ROSEE::Action.

Definition at line 108 of file ActionMultiplePinchTight.cpp.

108  {
109 
110  std::stringstream output;
111  output << "ActionName: " << name << std::endl;
112 
113  output << "FingersInvolved: [";
114  for (auto fingName : fingersInvolved){
115  output << fingName << ", " ;
116  }
117  output.seekp (-2, output.cur); //to remove the last comma (and space)
118  output << "]" << std::endl;
119 
120  output << "JointsInvolvedCount: " << std::endl;;
121  output << jointsInvolvedCount << std::endl;
122 
123  unsigned int nActState = 1;
124  for (auto itemSet : actionStates) { //the element in the set
125  output << "Action_State_" << nActState << " :" << std::endl;
126 
127  output << "\t" << "JointStates:" << std::endl;
128  output << itemSet.first;
129  output << "\t" << "DepthSum:" << itemSet.second <<std::endl;
130 
131  nActState++;
132  }
133  output << std::endl;
134 
135  std::cout << output.str();
136 
137 }
std::string name
Definition: Action.h:146
std::set< StateWithDepth, depthComp > actionStates
For each multiple pinch possible, we want a set of action because we want to store (in general) more ...
JointsInvolvedCount jointsInvolvedCount
Definition: Action.h:149
std::set< std::string > fingersInvolved
Definition: Action.h:148

Member Data Documentation

std::set< StateWithDepth, depthComp > ROSEE::ActionMultiplePinchTight::actionStates
private

For each multiple pinch possible, we want a set of action because we want to store (in general) more possible way to do that action with that X fingers.

The pinch among X tips can theoretically be done in infinite ways, so we store the best ways found (ordering them with depthSum of fingertips compenetration)

Definition at line 105 of file ActionMultiplePinchTight.h.


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