ROSEndEffector
ROS End-Effector package: provides a ROS-based set of standard interfaces to command robotics end-effectors in an agnostic fashion.
ActionSingleJointMultipleTips.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2020 <copyright holder> <email>
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 
18 
20  ActionPrimitive ( "singleJointMultipleTips", 1, ROSEE::ActionPrimitive::Type::SingleJointMultipleTips ) {}
21 
22 ROSEE::ActionSingleJointMultipleTips::ActionSingleJointMultipleTips(std::string actionName, unsigned int nFingers ) :
23  ActionPrimitive ( actionName, nFingers, 1, ROSEE::ActionPrimitive::Type::SingleJointMultipleTips ) {}
24 
25 ROSEE::ActionSingleJointMultipleTips::ActionSingleJointMultipleTips (std::string actionName, std::vector<std::string> fingers, std::string jointName,
26  JointPos jpFurther, JointPos jpNearer) :
27  ActionPrimitive ( actionName, fingers.size(), 1, ROSEE::ActionPrimitive::Type::SingleJointMultipleTips ) {
28 
29  this->jointInvolved = jointName;
30  fingersInvolved.insert (fingers.begin(), fingers.end());
31 
32  this->jointPosFurther = jpFurther;
33  this->jointPosNearer = jpNearer;
34 
35  // still need to do this, that can be done in costructor because we know that only one joint will be used, per definition of this action
36  for (auto it : jpFurther ) {
37  jointsInvolvedCount.insert (std::make_pair (it.first, 0) );
38  }
39  jointsInvolvedCount.at (jointName) = 1;
40 
41 }
42 
43 std::vector<ROSEE::JointPos> ROSEE::ActionSingleJointMultipleTips::getAllJointPos() const {
44 
45  std::vector<JointPos> vect;
46  vect.push_back (jointPosFurther);
47  vect.push_back (jointPosNearer);
48  return vect;
49 }
50 
52  return jointPosFurther;
53 }
54 
56  return jointPosFurther;
57 }
58 
60  return jointPosNearer;
61 }
62 
64  return jointInvolved;
65 }
66 
68  std::set <std::string> set;
69  set.insert(jointInvolved);
70  return set;
71 }
72 
74 
75  std::stringstream output;
76  output << "ActionName: " << name << std::endl;
77 
78  output << "FingersInvolved: [";
79  for (auto fingName : fingersInvolved){
80  output << fingName << ", " ;
81  }
82  output.seekp (-2, output.cur); //to remove the last comma (and space)
83  output << "]" << std::endl;
84 
85  output << "Joint which moves the tips: " << jointInvolved << std::endl;
86 
87  output << "JointPos Further from 0:" << std::endl;
88  output << jointPosFurther;
89 
90  output << "JointPos Nearer to 0:" << std::endl;
91  output << jointPosNearer;
92 
93  output << std::endl;
94 
95  std::cout << output.str();
96 
97 }
98 
99 void ROSEE::ActionSingleJointMultipleTips::emitYaml(YAML::Emitter& out) const {
100 
101  out << YAML::Key << jointInvolved;
102  out << YAML::Value << YAML::BeginMap;
103 
104  out << YAML::Key << "PrimitiveType" << YAML::Value << primitiveType;
105  out << YAML::Key << "ActionName" << YAML::Value << name;
106  out << YAML::Key << "FingersInvolved" << YAML::Value << YAML::Flow << fingersInvolved;
107 
108  out << YAML::Key << "JointPosFurther" << YAML::Value << YAML::BeginMap;
109  for (const auto &joint : jointPosFurther) {
110  out << YAML::Key << joint.first;
111  out << YAML::Value << YAML::Flow << joint.second; //vector of double is emitted like Seq
112  }
113  out << YAML::EndMap;
114 
115  out << YAML::Key << "JointPosNearer" << YAML::Value << YAML::BeginMap;
116  for (const auto &joint : jointPosNearer) {
117  out << YAML::Key << joint.first;
118  out << YAML::Value << YAML::Flow << joint.second; //vector of double is emitted like Seq
119  }
120  out << YAML::EndMap;
121 
122  out << YAML::EndMap;
123 
124 }
125 
126 
127 
128 bool ROSEE::ActionSingleJointMultipleTips::fillFromYaml(YAML::const_iterator yamlIt) {
129 
130  jointInvolved = yamlIt->first.as < std::string > ();
131 
132  for ( YAML::const_iterator keyValue = yamlIt->second.begin(); keyValue != yamlIt->second.end(); ++keyValue) {
133  std::string key = keyValue->first.as<std::string>();
134 
135  if ( key.compare ("ActionName") == 0 ){
136  name = keyValue->second.as < std::string > ();
137 
138  } else if (key.compare("FingersInvolved") == 0) {
139  std::vector <std::string> fingInvolvedVect = keyValue->second.as <std::vector < std::string >> ();
140  for (const auto &it : fingInvolvedVect) {
141  fingersInvolved.insert(it);
142  }
143 
144  } else if (key.compare ("JointPosNearer") == 0) {
145  jointPosNearer = keyValue->second.as <JointPos>();
146 
147  } else if (key.compare ("JointPosFurther") == 0) {
148  jointPosFurther = keyValue->second.as <JointPos>();
149 
150  } else if (key.compare ("PrimitiveType") == 0) {
152  keyValue->second.as <unsigned int>() );
153  if (parsedType != primitiveType ) {
154  std::cerr << "[ERROR ActionSingleJointMultipleTips::" << __func__ << " parsed a type " << parsedType <<
155  " but this object has primitive type " << primitiveType << std::endl;
156  return false;
157  }
158 
159  } else {
160  std::cerr << "[ERROR ActionSingleJointMultipleTips::" << __func__ << "not know key " << key <<
161  " found in the yaml file" << std::endl;
162  return false;
163  }
164  }
165 
166  // we have also to fill this structure, that is not present on yaml file because redundant
167  for (auto it : jointPosFurther ) {
168  jointsInvolvedCount.insert (std::make_pair (it.first, 0) );
169  }
171 
173 
174  return true;
175 
176 }
177 
178 
179 
180 
unsigned int nFingersInvolved
Type
Enum useful to discriminate each action when, for example, we want to parse a file if you change thi...
Definition: Action.h:82
Virtual class, Base of all the primitive actions.
std::string name
Definition: Action.h:146
void print() const override
Overridable functions, if we want to make them more action-specific.
std::map< std::string, std::vector< double > > JointPos
The map to describe the position of all actuated joints.
Definition: Action.h:40
bool fillFromYaml(YAML::const_iterator yamlIt) override
function to fill members of the Action with infos taken from yaml files
Type
Enum useful to discriminate each primitive action when, for example, we want to parse a file if you ...
void emitYaml(YAML::Emitter &out) const override
Function to fill the argument passed with info about the action.
JointsInvolvedCount jointsInvolvedCount
Definition: Action.h:149
std::vector< JointPos > getAllJointPos() const override
Overriden get from the pure virtual function of the base class Action The signature must be equal...
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...
std::set< std::string > fingersInvolved
Definition: Action.h:148
JointPos getJointPos() const override
Overriden get from the pure virtual function of the base class Action.