24 std::string output =
emitYaml ( action );
26 return (pathFolder + action->
getName() +
".yaml");
33 std::string output =
emitYaml ( action );
35 return (pathFolder + action->getName() +
".yaml");
40 const std::map < std::set <std::string> ,
ActionPrimitive* > mapOfActions,
41 const std::string actionName, std::string pathFolder) {
44 std::string output =
emitYaml ( mapOfActions );
46 return (pathFolder + actionName +
".yaml");
53 const std::map < std::set <std::string> ,
ActionPrimitive* > mapOfActions ) {
56 out << YAML::BeginMap;
57 for (
const auto & mapEl : mapOfActions) {
58 mapEl.second->emitYaml(out);
59 out << YAML::Newline << YAML::Newline;
70 out << YAML::Newline << YAML::Newline;
78 action->emitYaml(out);
79 out << YAML::Newline << YAML::Newline;
90 std::ifstream ifile(fileWithPath);
92 std::cout <<
"[ERROR YAMLPARSER:: " << __func__ <<
"]: file " << fileWithPath <<
" not found. " << std::endl;
96 YAML::Node node = YAML::LoadFile(fileWithPath);
98 for(YAML::const_iterator it4Action = node.begin(); it4Action != node.end(); ++it4Action) {
100 switch (actionType) {
101 case ActionPrimitive::Type::PinchTight: {
102 ptr = std::make_shared <ActionPinchTight>();
105 case ActionPrimitive::Type::PinchLoose: {
106 ptr = std::make_shared <ActionPinchLoose> ();
109 case ActionPrimitive::Type::Trig: {
110 ptr = std::make_shared <ActionTrig>(
"trig", ActionPrimitive::Type::Trig);
113 case ActionPrimitive::Type::TipFlex: {
114 ptr = std::make_shared <ActionTrig>(
"tipFlex", ActionPrimitive::Type::TipFlex);
117 case ActionPrimitive::Type::FingFlex: {
118 ptr = std::make_shared <ActionTrig>(
"fingFlex", ActionPrimitive::Type::FingFlex);
121 case ActionPrimitive::Type::SingleJointMultipleTips: {
122 ptr = std::make_shared <ActionSingleJointMultipleTips>();
125 case ActionPrimitive::Type::MultiplePinchTight: {
126 ptr = std::make_shared <ActionMultiplePinchTight> ();
131 std::cout <<
"[ERROR YAMLPARSER]: " << actionType <<
" : type not found" << std::endl;
135 ptr->fillFromYaml ( it4Action );
137 parsedMap.insert ( std::make_pair ( ptr->getKeyElements(), ptr) );
149 std::ifstream ifile(fileWithPath);
151 std::cout <<
"[ERROR YAMLPARSER:: " << __func__ <<
"]: file " << fileWithPath <<
" not found. " << std::endl;
155 YAML::Node node = YAML::LoadFile(fileWithPath);
157 for(YAML::const_iterator it4Action = node.begin(); it4Action != node.end(); ++it4Action) {
159 std::string actionName;
163 for ( YAML::const_iterator actionState = it4Action->second.begin(); actionState != it4Action->second.end(); ++actionState) {
165 if (actionState->first.as<std::string>().compare(
"PrimitiveType") == 0) {
174 case ActionPrimitive::Type::PinchTight: {
175 ptr = std::make_shared <ActionPinchTight>();
178 case ActionPrimitive::Type::PinchLoose: {
179 ptr = std::make_shared <ActionPinchLoose> ();
182 case ActionPrimitive::Type::Trig: {
183 ptr = std::make_shared <ActionTrig>(
"trig", ActionPrimitive::Type::Trig);
186 case ActionPrimitive::Type::TipFlex: {
187 ptr = std::make_shared <ActionTrig>(
"tipFlex", ActionPrimitive::Type::TipFlex);
190 case ActionPrimitive::Type::FingFlex: {
191 ptr = std::make_shared <ActionTrig>(
"fingFlex", ActionPrimitive::Type::FingFlex);
194 case ActionPrimitive::Type::SingleJointMultipleTips: {
195 ptr = std::make_shared <ActionSingleJointMultipleTips>();
198 case ActionPrimitive::Type::MultiplePinchTight: {
199 ptr = std::make_shared <ActionMultiplePinchTight> ();
204 std::cout <<
"[ERROR YAMLPARSER]: " << type <<
" : type not found" << std::endl;
208 ptr->fillFromYaml ( it4Action );
210 parsedMap.insert ( std::make_pair ( ptr->getKeyElements(), ptr) );
223 std::ifstream ifile(fileWithPath);
225 std::cout <<
"[ERROR YAMLPARSER:: " << __func__ <<
"]: file " << fileWithPath <<
" not found. " << std::endl;
229 YAML::Node node = YAML::LoadFile(fileWithPath);
230 YAML::const_iterator yamlIt = node.begin();
243 std::ifstream ifile(fileWithPath);
245 std::cout <<
"[ERROR YAMLPARSER:: " << __func__ <<
"]: file " << fileWithPath <<
" not found. " << std::endl;
249 YAML::Node node = YAML::LoadFile(fileWithPath);
251 YAML::const_iterator it4Action = node.begin();
256 for ( YAML::const_iterator el = it4Action->second.begin(); el != it4Action->second.end(); ++el) {
258 if (el->first.as<std::string>().compare(
"Type") == 0) {
265 case Action::Type::Primitive : {
266 std::cout <<
"[ERROR YAMLPARSER:: " << __func__ <<
"]: file " << fileWithPath <<
" contains a primitive action, " 267 <<
" please use parseYamlPrimitive to parse it " << std::endl;
271 case Action::Type::Generic : {
272 ptrAction = std::make_shared <ActionGeneric> ();
275 case Action::Type::Composed : {
276 ptrAction = std::make_shared <ActionComposed> ();
279 case Action::Type::Timed : {
280 std::cout <<
"[ERROR YAMLPARSER:: " << __func__ <<
"]: file " << fileWithPath <<
" contains a timed action, " 281 <<
" please use parseYamlTimed to parse it " << std::endl;
286 std::cout <<
"[ERROR YAMLPARSER:: " << __func__ <<
"]: file " << fileWithPath <<
" contains an action of not know type " 287 << type << std::endl;
292 ptrAction->fillFromYaml(it4Action);
302 std::shared_ptr < ROSEE::ActionTimed > ptrAction;
305 std::ifstream ifile(fileWithPath);
307 std::cout <<
"[ERROR YAMLPARSER:: " << __func__ <<
"]: file " << fileWithPath <<
" not found. " << std::endl;
311 YAML::Node node = YAML::LoadFile(fileWithPath);
312 YAML::const_iterator yamlIt = node.begin();
313 ptrAction = std::make_shared <ActionTimed> ();
315 ptrAction->fillFromYaml ( yamlIt );
Type
Enum useful to discriminate each action when, for example, we want to parse a file if you change thi...
Virtual class, Base of all the primitive actions. It has some implemented functions that a derived cl...
std::map< std::set< std::string >, ROSEE::ActionPrimitive::Ptr > parseYamlPrimitive(std::string fileWithPath)
Parse a yaml file and return the map with all the actions present in the file. For the moment...
std::shared_ptr< ROSEE::ActionTimed > parseYamlTimed(std::string fileWithPath)
Parse a timed Action.
ROSEE::ActionGeneric::Ptr parseYamlGeneric(std::string fileWithPath)
The pure virtual class representing an Action. It has members that are in common to all derived class...
A ActionComposed, which is formed by one or more Primitives (or even other composed). It is useful for example to create an action that grasp only with bending the tips (e.g. to take a dish from above) If the ActionComposed has the boolean value independent to true, it means that include indipendent sub-actions, so, each joint is used by at maximum by ONLY ONE of the sub-action inside. In this case the jointsInvolvedCount will contain only 0 or 1 values. If the ActionComposed is not independent, each joint position is calculated as the mean of all the joint position of the contained sub-actions that uses that joint. So each mean can include different primitives, so we used the jointsInvolvedCount vector to store the number of sub action that use each joint.
static bool create_directory(std::string pathDirectory)
std::shared_ptr< ActionGeneric > Ptr
std::shared_ptr< ActionPrimitive > Ptr
virtual void emitYaml(YAML::Emitter &out) const =0
Function to fill the argument passed with info about the action. Pure virtual because each derived cl...
static void out2file(std::string pathFile, std::string output)
Type
Enum useful to discriminate each primitive action when, for example, we want to parse a file if you ...
std::string emitYaml(const std::map< std::set< std::string >, ActionPrimitive * >)
support functions for createYamlFile
YamlWorker()
Costructor default.
virtual bool fillFromYaml(YAML::const_iterator yamlIt) override
Fill the internal data with infos taken from yaml file.
ROSEE::ActionComposed parseYamlComposed(std::string fileWithPath)
Parse a composed Action.
std::string getName() const
Get the name of the action.
std::string createYamlFile(const std::map< std::set< std::string >, ActionPrimitive * > mapOfActions, const std::string actionName, std::string pathFolder)
Create/overwrite yaml file and emit info on it about each ActionPrimitive inside the given mapOfActio...