ROSEndEffector
ROS End-Effector package: provides a ROS-based set of standard interfaces to command robotics end-effectors in an agnostic fashion.
ActionPrimitive.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 // std::ostream& operator<<(std::ostream& out, const ROSEE::ActionPrimitive::Type type){
22 // const char* s = 0;
23 // #define PROCESS_VAL(p) case(p): s = #p; break;
24 // switch(type){
25 // PROCESS_VAL(ROSEE::ActionPrimitive::Type::PinchTight);
26 // PROCESS_VAL(ROSEE::ActionPrimitive::Type::PinchLoose);
27 // PROCESS_VAL(ROSEE::ActionPrimitive::Type::MultiplePinchTight);
28 // PROCESS_VAL(ROSEE::ActionPrimitive::Type::Trig);
29 // PROCESS_VAL(ROSEE::ActionPrimitive::Type::TipFlex);
30 // PROCESS_VAL(ROSEE::ActionPrimitive::Type::FingFlex);
31 // PROCESS_VAL(ROSEE::ActionPrimitive::Type::SingleJointMultipleTips);
32 // PROCESS_VAL(ROSEE::ActionPrimitive::Type::None);
33 // }
34 // #undef PROCESS_VAL
35 //
36 // return out << s;
37 // }
38 
39 ROSEE::ActionPrimitive::ActionPrimitive(std::string name, unsigned int maxStoredActionStates, ActionPrimitive::Type primitiveType) :
40  Action(name, Action::Type::Primitive), maxStoredActionStates(maxStoredActionStates), primitiveType(primitiveType) {};
41 
43  std::string name, unsigned int nFingersInvolved, unsigned int maxStoredActionStates,
45  Action(name, Action::Type::Primitive), nFingersInvolved(nFingersInvolved), maxStoredActionStates(maxStoredActionStates),
46  primitiveType(primitiveType) {}
47 
48 
50  return primitiveType;
51 }
52 
54  return maxStoredActionStates;
55 }
56 
58  return nFingersInvolved;
59 }
60 
62  this->jointsInvolvedCount = jointsInvolvedCount;
63 }
64 
65 
66 
67 void ROSEE::ActionPrimitive::emitYaml ( YAML::Emitter& out ) const {
68 
69  // key: set of string (eg two tip names)
70  out << YAML::Key << YAML::Flow << fingersInvolved;
71 
72  unsigned int nCont = 1;
73  out << YAML::Value << YAML::BeginMap;
74  out << YAML::Key << "PrimitiveType" << YAML::Value << primitiveType;
75  out << YAML::Key << "ActionName" << YAML::Value << name;
76  out << YAML::Key << "JointsInvolvedCount" << YAML::Value << YAML::BeginMap;
77  for (const auto &jointCount : jointsInvolvedCount ) {
78  out << YAML::Key << jointCount.first;
79  out << YAML::Value << jointCount.second;
80  }
81  out << YAML::EndMap;
82 
83 
84  for (const auto & jointPos : getAllJointPos()) {
85 
86  std::string contSeq = "ActionState_" + std::to_string(nCont);
87  out << YAML::Key << contSeq;
88 
89  out << YAML::Value << YAML::BeginMap;
90  //actionState.first, the jointstates map
91  out << YAML::Key << "JointPos" << YAML::Value << YAML::BeginMap;
92  for (const auto &joint : jointPos) {
93  out << YAML::Key << joint.first;
94  out << YAML::Value << YAML::Flow << joint.second; //vector of double is emitted like Seq
95  }
96  out << YAML::EndMap;
97 
98  out << YAML::EndMap;
99  nCont++;
100  }
101  out << YAML::EndMap;
102 }
103 
104 
105 
unsigned int nFingersInvolved
std::string name
Definition: Action.h:146
unsigned int getMaxStoredActionStates() const
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
void setJointsInvolvedCount(ROSEE::JointsInvolvedCount jointsInvolvedCount)
The pure virtual class representing an Action.
Definition: Action.h:71
ActionPrimitive(std::string name, unsigned int maxStoredActionStates, Type type)
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
const unsigned int maxStoredActionStates
virtual void emitYaml(YAML::Emitter &) const override
Function to fill the argument passed with info about the action.
unsigned int getnFingersInvolved() const
virtual std::vector< ROSEE::JointPos > getAllJointPos() const =0
Return all the joint position stored.
std::set< std::string > fingersInvolved
Definition: Action.h:148
Type getPrimitiveType() const