ROSEndEffector
ROS End-Effector package: provides a ROS-based set of standard interfaces to command robotics end-effectors in an agnostic fashion.
ActionTrig.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 IIT-HHCM
3  * Author: Davide Torielli
4  * email: davide.torielli@iit.it
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
20 
21 ROSEE::ActionTrig::ActionTrig (std::string actionName, ActionPrimitive::Type actionType) :
22  ActionPrimitive ( actionName, 1, 1, actionType ) { }
23 
24 ROSEE::ActionTrig::ActionTrig (std::string actionName, ActionPrimitive::Type actionType, std::string tip, JointPos jp) :
25  ActionPrimitive ( actionName, 1, 1, actionType ) {
26 
27  fingersInvolved.insert(tip);
28  jointPos = jp;
29 }
30 
32  return *( fingersInvolved.begin() );
33 }
34 
36  return jointPos;
37 }
38 
39 std::set<std::string> ROSEE::ActionTrig::getKeyElements() const {
40  return fingersInvolved;
41 }
42 
44  this->jointPos = jointPos;
45 }
46 
47 std::vector < ROSEE::JointPos > ROSEE::ActionTrig::getAllJointPos() const{
48 
49  std::vector < JointPos > retVect {jointPos};
50  return retVect;
51 }
52 
53 
54 void ROSEE::ActionTrig::setFingerInvolved (std::string fingName ) {
55  fingersInvolved.clear();
56  fingersInvolved.insert(fingName);
57 }
58 
59 bool ROSEE::ActionTrig::fillFromYaml ( YAML::const_iterator yamlIt ) {
60 
61 
62  std::vector <std::string> fingInvolvedVect = yamlIt->first.as <std::vector < std::string >> ();
63  for (const auto &it : fingInvolvedVect) {
64  fingersInvolved.insert(it);
65  }
66 
67  for ( YAML::const_iterator element = yamlIt->second.begin(); element != yamlIt->second.end(); ++element) {
68 
69  std::string key = element->first.as<std::string>();
70  if ( key.compare ("ActionName") == 0 ){
71  name = element->second.as < std::string > ();
72 
73  } else if (key.compare("JointsInvolvedCount") == 0) {
74  jointsInvolvedCount = element->second.as < JointsInvolvedCount > ();
75 
76  } else if (key.compare ("PrimitiveType") == 0) {
78  element->second.as <unsigned int>() );
79  if (parsedType != primitiveType ) {
80  std::cerr << "[ERROR ActionTrig::" << __func__ << " parsed a type " << parsedType <<
81  " but this object has primitive type " << primitiveType << std::endl;
82  return false;
83  }
84 
85  } else if (key.compare(0, 12, "ActionState_") == 0) { //compare 12 caracters from index 0 of key
86  for(YAML::const_iterator asEl = element->second.begin(); asEl != element->second.end(); ++asEl) {
87  //asEl can be the map JointStates or the map Optional
88 
89  if (asEl->first.as<std::string>().compare ("JointPos") == 0 ) {
90  jointPos = asEl->second.as < JointPos >() ;
91 
92  } else {
93  //ERRROr, only JointPos at this level (optional is not for trig)
94  std::cerr << "[ERROR ActionTrig::" << __func__ << " not know key "
95  << asEl->first.as<std::string>() <<
96  " found in the yaml file at this level" << std::endl;
97  return false;
98  }
99  }
100 
101  } else {
102  std::cerr << "[ERROR ActionTrig::" << __func__ << "not know key " << key <<
103  " found in the yaml file" << std::endl;
104  }
105  }
106  return true;
107 }
void setJointPos(JointPos)
Definition: ActionTrig.cpp:43
Virtual class, Base of all the primitive actions.
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
JointPos jointPos
Definition: ActionTrig.h:107
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...
Definition: ActionTrig.cpp:39
Type
Enum useful to discriminate each primitive action when, for example, we want to parse a file if you ...
bool fillFromYaml(YAML::const_iterator yamlIt) override
function to fill members of the Action with infos taken from yaml files
Definition: ActionTrig.cpp:59
JointsInvolvedCount jointsInvolvedCount
Definition: Action.h:149
ActionTrig(std::string actionName, ActionPrimitive::Type)
Definition: ActionTrig.cpp:21
std::string getFingerInvolved() const
Specific method of trig to simply return a string instead of the full vector fingersInvolved that in ...
Definition: ActionTrig.cpp:31
void setFingerInvolved(std::string)
Definition: ActionTrig.cpp:54
std::vector< JointPos > getAllJointPos() const override
Overriden get from the pure virtual function of the base class ActionPrimitive The signature must be ...
Definition: ActionTrig.cpp:47
JointPos getJointPos() const override
Overriden get from the pure virtual function of the base class Action.
Definition: ActionTrig.cpp:35
std::set< std::string > fingersInvolved
Definition: Action.h:148