Line data Source code
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 :
19 : #ifndef __ROSEE_ACTION_H
20 : #define __ROSEE_ACTION_H
21 :
22 : #include <vector>
23 : #include <string>
24 : #include <map>
25 : #include <yaml-cpp/yaml.h>
26 : #include <memory>
27 : #include <iostream>
28 :
29 : #include <ros_end_effector/Utils.h>
30 :
31 : /**
32 : *
33 : */
34 : namespace ROSEE {
35 :
36 : /**
37 : * @brief The map to describe the position of all actuated joints. The key is the name of the string,
38 : * the value is a vector of joint positions (because in general a joint can have more DOFs
39 : */
40 : typedef std::map <std::string, std::vector <double> > JointPos;
41 :
42 : /** operator overload for JointPos so it is easier to print */
43 : std::ostream& operator << (std::ostream& output, const JointPos jp) ;
44 :
45 : JointPos operator * ( double multiplier, JointPos jp) ;
46 :
47 : JointPos operator * ( JointPos jp, double multiplier ) ;
48 :
49 : JointPos& operator *= ( JointPos& jp, double multiplier ) ;
50 :
51 : JointPos operator + ( JointPos jp1, JointPos jp2) ;
52 :
53 : JointPos& operator += ( JointPos& jp1, ROSEE::JointPos jp2);
54 :
55 :
56 : /**
57 : * @brief The map to describe, how many times a joint is set by the action.
58 : * An \ref ActionPrimitive and an \ref ActionComposed (indipendent) have as values only 0 or 1.
59 : * \ref ActionComposed (not independet) can have values > 1.
60 : * This map is also useful to understand if a joint is used or not by the action (0 == not used) so
61 : * we can control only the necessary joints.
62 : */
63 : typedef std::map <std::string, unsigned int> JointsInvolvedCount;
64 :
65 : std::ostream& operator << (std::ostream& output, const JointsInvolvedCount jic);
66 :
67 :
68 : /**
69 : * @brief The pure virtual class representing an Action. It has members that are in common to all derived class
70 : */
71 2335 : class Action
72 : {
73 :
74 : public:
75 : typedef std::shared_ptr<Action> Ptr;
76 : typedef std::shared_ptr<const Action> ConstPtr;
77 :
78 : /**
79 : * @brief Enum useful to discriminate each action when, for example, we want to parse a file
80 : * @remind if you change this enum, change also the ROSEEControl.msg accordingly
81 : */
82 : enum Type {Primitive, Generic, Composed, Timed, None};
83 :
84 : /* destructor of base must be virtual */
85 18479 : virtual ~Action() {};
86 :
87 : /**
88 : * @brief Get the name of the action
89 : * @return std::string the name of the action
90 : */
91 : std::string getName () const ;
92 :
93 : Type getType() const;
94 :
95 : /**
96 : * @brief Get for \ref fingersInvolved
97 : * @return std::set<std::string> the set containing all the hand's fingers involved in the action
98 : */
99 : std::set <std::string> getFingersInvolved () const ;
100 :
101 : /**
102 : * @brief Get for \ref jointsInvolvedCount
103 : * @return JointsInvolvedCount the map indicating how many times the joint is set by the action
104 : */
105 : JointsInvolvedCount getJointsInvolvedCount () const ;
106 :
107 : /**
108 : * @brief Get the position related to this action. Pure Virtual function: the derived class
109 : * store this info differently so they are in charge of providing the read.
110 : * @return JointsPos the map indicating how the position of the joint
111 : */
112 : //TODO rename getJointsPos
113 : virtual JointPos getJointPos () const = 0;
114 :
115 : /**
116 : * @brief Return all the joint position stored. If the concrete (derived from \ref Action) has only one joint position info,
117 : * this function is equal to \ref getJointPos.
118 : * @return vector containing all the joint pos of the action
119 : */
120 : //TODO rename getAllJointsPos
121 : virtual std::vector < ROSEE::JointPos > getAllJointPos () const = 0;
122 :
123 : /** @brief Overridable functions, if we want to make them more action-specific */
124 : virtual void print () const ;
125 :
126 : /**
127 : * @brief Function to fill the argument passed with info about the action. Pure virtual because each derived
128 : * class has different infos and stored differently.
129 : * check \ref YamlWorker to correctly emit and parse the file
130 : * @param out the yaml-cpp emitter which store infos about the action
131 : * @note this function does not print in a file, but simply fill a YAML::Emitter.
132 : */
133 : virtual void emitYaml ( YAML::Emitter& out ) const = 0;
134 : /**
135 : * @brief function to fill members of the Action with infos taken from yaml files
136 : * @param yamlIt a YAML::const_iterator to the node that is loaded with YAML::LoadFile(dirPath + filename).
137 : * check \ref YamlWorker to correctly parse and emit the file
138 : */
139 : virtual bool fillFromYaml ( YAML::const_iterator yamlIt ) = 0;
140 :
141 : protected:
142 : // Only derived class can create this class
143 : Action();
144 : Action(std::string actionName, Action::Type type);
145 :
146 : std::string name;
147 : Action::Type type;
148 : std::set <std::string> fingersInvolved;
149 : JointsInvolvedCount jointsInvolvedCount;
150 :
151 : };
152 :
153 : /**
154 : * To print the action type enum as the real name (eg primitive) and not as the enum number
155 : * REmember to add here if new type are implemented
156 : */
157 : std::ostream& operator <<(std::ostream& out, const ROSEE::Action::Type type);
158 :
159 : }
160 :
161 : #endif // __ROSEE_ACTION_H
|