ROSEndEffector
ROS End-Effector package: provides a ROS-based set of standard interfaces to command robotics end-effectors in an agnostic fashion.
Action.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 /******************************** OPERATORS OVERLOAD FOR TYPEDEFS ***********************************/
22 
24 std::ostream& ROSEE::operator << (std::ostream& output, const ROSEE::JointPos jp) {
25  for (const auto &jsEl : jp) {
26  output << "\t\t"<<jsEl.first << " : "; //joint name
27  for(const auto &jValue : jsEl.second){
28  output << jValue << ", "; //joint position (vector because can have multiple dof)
29  }
30  output.seekp (-2, output.cur); //to remove the last comma (and space)
31  output << std::endl;
32  }
33  return output;
34 }
35 
37 
38  return jp *= multiplier;
39 }
40 
42 
43  return jp *= multiplier;
44 }
45 
47 
48  for ( auto &jsEl : jp) {
49  for (int i = 0; i< jsEl.second.size(); i++) {
50  jsEl.second.at(i) *= multiplier;
51  }
52  }
53 
54  return jp;
55 }
56 
58 
59  return jp1 += jp2;
60 }
61 
63 
64  if ( ! ROSEE::Utils::keys_equal(jp1, jp2) ) {
66  }
67 
68  for (auto &jsEl : jp1) {
69  if (jsEl.second.size() != jp2.at(jsEl.first).size() ) {
70  throw "Dofs not same";
71  }
72 
73  for (int i = 0; i < jsEl.second.size(); i++) {
74  jsEl.second.at(i) += jp2.at(jsEl.first).at(i);
75  }
76  }
77 
78  return jp1;
79 }
80 
81 std::ostream& ROSEE::operator << (std::ostream& output, const ROSEE::JointsInvolvedCount jic) {
82  for (const auto &jicEl : jic) {
83  output << "\t"<< jicEl.first << " : " << jicEl.second;
84  output << std::endl;
85  }
86  return output;
87 }
88 
89 std::ostream& ROSEE::operator<<(std::ostream& out, const ROSEE::Action::Type type){
90 
91  const char* s = 0;
92 #define PROCESS_VAL(p) case(p): s = #p; break;
93  switch(type){
94  PROCESS_VAL(ROSEE::Action::Type::Primitive);
95  PROCESS_VAL(ROSEE::Action::Type::Generic);
96  PROCESS_VAL(ROSEE::Action::Type::Composed);
97  PROCESS_VAL(ROSEE::Action::Type::Timed);
98  PROCESS_VAL(ROSEE::Action::Type::None);
99  }
100 #undef PROCESS_VAL
101 
102  return out << s;
103 }
104 
105 /********************************************* CLASS ACTION **************************************/
107 
108 }
109 
110 
112  this->name = name;
113  this->type = type;
114 }
115 
116 std::string ROSEE::Action::getName() const {
117  return name;
118 }
119 
121  return type;
122 }
123 
124 
125 std::set<std::string> ROSEE::Action::getFingersInvolved() const {
126  return fingersInvolved;
127 }
128 
129 
131  return jointsInvolvedCount;
132 }
133 
134 
135 void ROSEE::Action::print () const {
136 
137  std::stringstream output;
138  output << "ActionName: " << name << std::endl;
139 
140  if (fingersInvolved.size() > 0 ){
141  output << "FingersInvolved: [";
142  for (auto fingName : fingersInvolved){
143  output << fingName << ", " ;
144  }
145  output.seekp (-2, output.cur); //to remove the last comma (and space)
146  output << "]" << std::endl;
147 
148  } else {
149  output << "FingersInvolved: <not inserted>" << std::endl; // can happen, for ex for genericAction
150  }
151 
152 
153  output << "JointsInvolvedCount: " << std::endl;;
154  output << jointsInvolvedCount << std::endl;
155 
156  output << "JointPos:" << std::endl;
157  output << getJointPos() << std::endl;
158 
159  output << std::endl;
160 
161  std::cout << output.str();
162 }
std::string getName() const
Get the name of the action.
Definition: Action.cpp:116
Type
Enum useful to discriminate each action when, for example, we want to parse a file if you change thi...
Definition: Action.h:82
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
virtual void print() const
Overridable functions, if we want to make them more action-specific.
Definition: Action.cpp:135
bool keys_equal(std::map< keyType, valueType1 > const &lhs, std::map< keyType, valueType2 > const &rhs)
Return false if two maps have different keys.
Definition: Utils.h:182
JointPos operator+(JointPos jp1, JointPos jp2)
Definition: Action.cpp:57
JointsInvolvedCount getJointsInvolvedCount() const
Get for jointsInvolvedCount.
Definition: Action.cpp:130
std::ostream & operator<<(std::ostream &output, const JointPos jp)
operator overload for JointPos so it is easier to print
Definition: Action.cpp:24
Action::Type type
Definition: Action.h:147
std::set< std::string > getFingersInvolved() const
Get for fingersInvolved.
Definition: Action.cpp:125
JointsInvolvedCount jointsInvolvedCount
Definition: Action.h:149
JointPos & operator*=(JointPos &jp, double multiplier)
Definition: Action.cpp:46
virtual JointPos getJointPos() const =0
Get the position related to this action.
JointPos & operator+=(JointPos &jp1, ROSEE::JointPos jp2)
Definition: Action.cpp:62
#define PROCESS_VAL(p)
std::set< std::string > fingersInvolved
Definition: Action.h:148
JointPos operator*(double multiplier, JointPos jp)
Definition: Action.cpp:36
Type getType() const
Definition: Action.cpp:120