ROSEndEffector
ROS End-Effector package: provides a ROS-based set of standard interfaces to command robotics end-effectors in an agnostic fashion.
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ROSEE::ActionGeneric Class Reference

Class to handle a generic, simple action. More...

#include <ActionGeneric.h>

+ Inheritance diagram for ROSEE::ActionGeneric:
+ Collaboration diagram for ROSEE::ActionGeneric:

Public Types

typedef std::shared_ptr< ActionGenericPtr
 
typedef std::shared_ptr< const ActionGenericConstPtr
 
- Public Types inherited from ROSEE::Action
enum  Type {
  Primitive,
  Generic,
  Composed,
  Timed,
  None
}
 Enum useful to discriminate each action when, for example, we want to parse a file if you change this enum, change also the ROSEEControl.msg accordingly. More...
 
typedef std::shared_ptr< ActionPtr
 
typedef std::shared_ptr< const ActionConstPtr
 

Public Member Functions

 ActionGeneric ()
 default costructor. More...
 
 ActionGeneric (std::string actionName, ROSEE::JointPos jointPos)
 Simpliest costructor, need only essential infos. More...
 
 ActionGeneric (std::string actionName, ROSEE::JointPos jointPos, JointsInvolvedCount jic)
 Another costructor. More...
 
 ActionGeneric (std::string actionName, ROSEE::JointPos jointPos, JointsInvolvedCount jic, std::set< std::string > fingersInvolved)
 
JointPos getJointPos () const override
 Get the joint position related to this action, overriden from Action. More...
 
std::vector< ROSEE::JointPosgetAllJointPos () const override
 Get the joint position related to this action, overriden from Action Necessary to not make this class abstact, even if for a composed action we store only a single JointPos, so this function return a single element vector. More...
 
virtual void emitYaml (YAML::Emitter &out) const override
 Function to fill the argument passed with info about the action. More...
 
virtual bool fillFromYaml (YAML::const_iterator yamlIt) override
 function to fill members of the Action with infos taken from yaml files More...
 
- Public Member Functions inherited from ROSEE::Action
virtual ~Action ()
 
std::string getName () const
 Get the name of the action. More...
 
Type getType () const
 
std::set< std::string > getFingersInvolved () const
 Get for fingersInvolved. More...
 
JointsInvolvedCount getJointsInvolvedCount () const
 Get for jointsInvolvedCount. More...
 
virtual void print () const
 Overridable functions, if we want to make them more action-specific. More...
 

Protected Member Functions

 ActionGeneric (std::string actionName)
 this costructor is only for derived class More...
 
- Protected Member Functions inherited from ROSEE::Action
 Action ()
 
 Action (std::string actionName, Action::Type type)
 

Protected Attributes

JointPos jointPos
 
- Protected Attributes inherited from ROSEE::Action
std::string name
 
Action::Type type
 
std::set< std::string > fingersInvolved
 
JointsInvolvedCount jointsInvolvedCount
 

Detailed Description

Class to handle a generic, simple action.

Differently from other class, this is easily creable manually, for ex giving a name and a JointPos map to the costructor. It contains essential infos about the action, and override the necessary pure virtual functions of base class Action

Definition at line 32 of file ActionGeneric.h.

Member Typedef Documentation

typedef std::shared_ptr<const ActionGeneric> ROSEE::ActionGeneric::ConstPtr

Definition at line 36 of file ActionGeneric.h.

typedef std::shared_ptr<ActionGeneric> ROSEE::ActionGeneric::Ptr

Definition at line 35 of file ActionGeneric.h.

Constructor & Destructor Documentation

ROSEE::ActionGeneric::ActionGeneric ( )

default costructor.

It is used when parsing a file with YamlWorker,

Warning
If you use this costructor, then you must fill internal structures with fillFromYaml (or using YamlWorker support class), it is the only way to set the internal infos (e.g. there is not a setName( name ) function ). If you have not a Yaml file to parse, use other costructors.

Definition at line 20 of file ActionGeneric.cpp.

20 {}
ROSEE::ActionGeneric::ActionGeneric ( std::string  actionName,
ROSEE::JointPos  jointPos 
)

Simpliest costructor, need only essential infos.

Note
This costructor create jointsInvolvedCount map. To do this, it considers a "not set" joint (count == 0) a joint which pos is 0. If you do not want this, pass also your JointsInvolvedCount map to the costructor

Definition at line 24 of file ActionGeneric.cpp.

24  : Action(actionName, Action::Type::Generic) {
25 
26  //HACK TODO now consider the position 0 as not used joint
27  for (auto jp : jointPos) {
28  bool zeros = std::all_of(jp.second.begin(), jp.second.end(), [](double i) { return i==0.0; });
29  if (zeros) {
30  jointsInvolvedCount.insert (std::make_pair (jp.first, 0) );
31  } else {
32  jointsInvolvedCount.insert (std::make_pair (jp.first, 1) );
33 
34  }
35  }
36 
37  this->jointPos = jointPos;
38 
39 }
JointsInvolvedCount jointsInvolvedCount
Definition: Action.h:149
ROSEE::ActionGeneric::ActionGeneric ( std::string  actionName,
ROSEE::JointPos  jointPos,
JointsInvolvedCount  jic 
)

Another costructor.

Parameters
actionNamethe name of this action
jointPosmap containing position of ALL joints of your robot
jicmap of counters of times of joints involved (e.g. joint not used –> 0 ; joint used for the action –> 1)
Exceptions
Besure that keys of jointPos and jic are the same, otherwise exception is throw

Definition at line 41 of file ActionGeneric.cpp.

41  :
42  Action(actionName, Action::Type::Generic) {
43 
44  if (jic.empty()) {
45  //HACK TODO now consider the position 0 as not used joint
46  for (auto jp : jointPos) {
47  bool zeros = std::all_of(jp.second.begin(), jp.second.end(), [](double i) { return i==0.0; });
48  if (zeros) {
49  jointsInvolvedCount.insert (std::make_pair (jp.first, 0) );
50  } else {
51  jointsInvolvedCount.insert (std::make_pair (jp.first, 1) );
52 
53  }
54  }
55 
56  } else {
57  if ( ! ROSEE::Utils::keys_equal(jointPos, jic) ) {
59  }
60  this->jointsInvolvedCount = jic;
61  }
62 
63  this->jointPos = jointPos;
64 
65 }
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
JointsInvolvedCount jointsInvolvedCount
Definition: Action.h:149
ROSEE::ActionGeneric::ActionGeneric ( std::string  actionName,
ROSEE::JointPos  jointPos,
JointsInvolvedCount  jic,
std::set< std::string >  fingersInvolved 
)

Definition at line 68 of file ActionGeneric.cpp.

69  : Action(actionName, Action::Type::Generic) {
70 
71  if (jic.empty()) {
72  //HACK TODO now consider the position 0 as not used joint
73  for (auto jp : jointPos) {
74  bool zeros = std::all_of(jp.second.begin(), jp.second.end(), [](double i) { return i==0.0; });
75  if (zeros) {
76  jointsInvolvedCount.insert (std::make_pair (jp.first, 0) );
77  } else {
78  jointsInvolvedCount.insert (std::make_pair (jp.first, 1) );
79 
80  }
81  }
82 
83  } else {
84 
85  if ( ! ROSEE::Utils::keys_equal(jointPos, jic) ) {
87  }
88 
89  this->jointsInvolvedCount = jic;
90  }
91 
92  this->jointPos = jointPos;
93 
94  this->fingersInvolved = fingersInvolved;
95 }
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
JointsInvolvedCount jointsInvolvedCount
Definition: Action.h:149
std::set< std::string > fingersInvolved
Definition: Action.h:148
ROSEE::ActionGeneric::ActionGeneric ( std::string  actionName)
protected

this costructor is only for derived class

Definition at line 22 of file ActionGeneric.cpp.

22 : Action (actionName, Action::Type::Generic) {}

Member Function Documentation

void ROSEE::ActionGeneric::emitYaml ( YAML::Emitter &  out) const
overridevirtual

Function to fill the argument passed with info about the action.

Pure virtual because each derived class has different infos and stored differently. check YamlWorker to correctly emit and parse the file

Parameters
outthe yaml-cpp emitter which store infos about the action
Note
this function does not print in a file, but simply fill a YAML::Emitter.

Implements ROSEE::Action.

Reimplemented in ROSEE::ActionComposed.

Definition at line 107 of file ActionGeneric.cpp.

107  {
108 
109  out << YAML::BeginMap << YAML::Key << name << YAML::Value << YAML::BeginMap ;
110  out << YAML::Key << "Type" << YAML::Value << type;
111  out << YAML::Key << "FingersInvolved" << YAML::Value << YAML::Flow << fingersInvolved;
112  out << YAML::Key << "JointsInvolvedCount" << YAML::Value << YAML::BeginMap;
113  for (const auto &jointCount : jointsInvolvedCount ) {
114  out << YAML::Key << jointCount.first;
115  out << YAML::Value << jointCount.second;
116  }
117  out << YAML::EndMap;
118 
119  out << YAML::Key << "JointPos" << YAML::Value << YAML::BeginMap;
120  for (const auto &joint : jointPos) {
121  out << YAML::Key << joint.first;
122  out << YAML::Value << YAML::Flow << joint.second; //vector of double is emitted like Seq
123  }
124  out << YAML::EndMap;
125  out << YAML::EndMap;
126  out << YAML::EndMap;
127 }
std::string name
Definition: Action.h:146
Action::Type type
Definition: Action.h:147
JointsInvolvedCount jointsInvolvedCount
Definition: Action.h:149
std::set< std::string > fingersInvolved
Definition: Action.h:148
bool ROSEE::ActionGeneric::fillFromYaml ( YAML::const_iterator  yamlIt)
overridevirtual

function to fill members of the Action with infos taken from yaml files

Parameters
yamlIta YAML::const_iterator to the node that is loaded with YAML::LoadFile(dirPath + filename). check YamlWorker to correctly parse and emit the file

Implements ROSEE::Action.

Reimplemented in ROSEE::ActionComposed.

Definition at line 130 of file ActionGeneric.cpp.

130  {
131 
132  name = yamlIt->first.as<std::string>();
133  type = ROSEE::Action::Type::Generic;
134 
135  for (auto keyValue = yamlIt->second.begin(); keyValue != yamlIt->second.end(); ++keyValue ) {
136 
137  std::string key = keyValue->first.as<std::string>();
138 
139  if ( key.compare ("FingersInvolved") == 0 ) {
140  // if <not_inserted> tempVect is a empty vector
141  auto tempVect = keyValue->second.as <std::vector <std::string> > ();
142  fingersInvolved.insert ( tempVect.begin(), tempVect.end() );
143 
144  } else if ( key.compare ("Type") == 0 ) {
145  if (ROSEE::Action::Type::Generic != static_cast<ROSEE::Action::Type> ( keyValue->second.as <unsigned int>() )) {
146  std::cout << "[GENERIC ACTION::" << __func__ << "] Error, found type " << keyValue->second.as <unsigned int>()
147  << "instead of generic type (" << ROSEE::Action::Type::Generic << ")" << std::endl;
148  return false;
149  }
150  type = ROSEE::Action::Type::Generic;
151 
152  } else if ( key.compare ("JointsInvolvedCount") == 0 ) {
153  jointsInvolvedCount = keyValue->second.as < JointsInvolvedCount >();
154 
155  } else if ( key.compare ("JointPos") == 0 ) {
156  jointPos = keyValue->second.as < JointPos >();
157 
158  } else {
159  std::cout << "[GENERIC ACTION::" << __func__ << "] Error, not known key " << key << std::endl;
160  return false;
161  }
162  }
163 
166  }
167 
168  return true;
169 }
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
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
Action::Type type
Definition: Action.h:147
JointsInvolvedCount jointsInvolvedCount
Definition: Action.h:149
std::set< std::string > fingersInvolved
Definition: Action.h:148
std::vector< ROSEE::JointPos > ROSEE::ActionGeneric::getAllJointPos ( ) const
overridevirtual

Get the joint position related to this action, overriden from Action Necessary to not make this class abstact, even if for a composed action we store only a single JointPos, so this function return a single element vector.

Returns
JointsPos the map indicating the position of the joints

Implements ROSEE::Action.

Definition at line 101 of file ActionGeneric.cpp.

101  {
102  std::vector < JointPos> vect;
103  vect.push_back ( jointPos ) ;
104  return vect;
105 }
ROSEE::JointPos ROSEE::ActionGeneric::getJointPos ( ) const
overridevirtual

Get the joint position related to this action, overriden from Action.

Returns
JointsPos the map indicating the position of the joints

Implements ROSEE::Action.

Definition at line 97 of file ActionGeneric.cpp.

97  {
98  return jointPos;
99 }

Member Data Documentation

JointPos ROSEE::ActionGeneric::jointPos
protected

Definition at line 94 of file ActionGeneric.h.


The documentation for this class was generated from the following files: