20 type = Action::Type::Timed;
33 std::vector<ROSEE::JointPos> jpVect;
43 std::vector<ROSEE::JointsInvolvedCount> jcVect;
53 std::vector <std::pair <double,double> > timeVect;
69 std::cerr <<
"[ACTIONTIMED:: " << __func__ <<
"] ERROR: action " << actionName <<
" not present in this composed timed action" << std::endl;
82 std::cerr <<
"[ACTIONTIMED:: " << __func__ <<
"] ERROR: action " << actionName <<
" not present in this composed timed action" << std::endl;
93 return ( it->second );
96 std::cerr <<
"[ACTIONTIMED:: " << __func__ <<
"] ERROR: action " << actionName <<
" not present in this composed timed action" << std::endl;
97 return std::make_pair(-1, -1);
108 std::stringstream output;
110 output <<
"Timed Action '" <<
name <<
"'" << std::endl;
112 output <<
"\tNice TimeLine:" << std::endl <<
"\t\t";
116 output.seekp (-3, output.cur);
119 output <<
"\tJointPos of each actions, in order of execution:\n";
120 for (
auto actionName : actionsNamesOrdered ) {
121 output <<
"\t" << actionName << std::endl;
125 output <<
"\tJointPos final, the sum of all joint pos of each inner action:\n";
128 output <<
"\tFingers involved: [" ;
130 output << it <<
", ";
132 output.seekp (-2, output.cur);
133 output <<
"]" << std::endl;
135 output <<
"\tEach joint influenced by x inner action:" << std::endl;
138 std::cout << output.str();
144 out << YAML::BeginMap << YAML::Key <<
name << YAML::Value << YAML::BeginMap ;
145 std::string timeline;
150 if (! timeline.empty() ) {
151 timeline.pop_back(); timeline.pop_back(); timeline.pop_back();
154 out << YAML::Comment(timeline);
155 out << YAML::Key <<
"Type" << YAML::Value <<
type;
156 out << YAML::Key <<
"FingersInvolved" << YAML::Value << YAML::Flow <<
fingersInvolved;
158 out << YAML::Key <<
"JointsInvolvedCount" << YAML::Value << YAML::BeginMap;
160 out << YAML::Key << jointCount.first;
161 out << YAML::Value << jointCount.second;
165 out << YAML::Key <<
"ActionsJointPosFinal" << YAML::Value << YAML::BeginMap;
167 out << YAML::Key << joint.first;
168 out << YAML::Value << YAML::Flow << joint.second;
172 out << YAML::Key <<
"ActionsNamesOrdered" << YAML::Value << YAML::Flow <<
actionsNamesOrdered;
174 out << YAML::Key <<
"ActionsTimeMargins" << YAML::Value << YAML::BeginMap;
175 for (
const std::string action : actionsNamesOrdered ){
177 out << YAML::Key << action << YAML::Value << YAML::BeginMap;
179 out << YAML::Key <<
"marginBefore" <<
182 out << YAML::Key <<
"marginAfter" <<
188 out << YAML::Key <<
"ActionsJointPos" << YAML::Value << YAML::BeginMap;
189 for (
const std::string action : actionsNamesOrdered ){
191 out << YAML::Key << action << YAML::Value << YAML::BeginMap;
194 out << YAML::Key << joint.first;
195 out << YAML::Value << YAML::Flow << joint.second;
202 out << YAML::Key <<
"ActionsJointCount" << YAML::Value << YAML::BeginMap;
203 for (
const std::string action : actionsNamesOrdered ){
205 out << YAML::Key << action << YAML::Value << YAML::BeginMap;
208 out << YAML::Key << joint.first;
209 out << YAML::Value << YAML::Flow << joint.second;
224 name = yamlIt->first.as<std::string>();
225 type = Action::Type::Timed;
227 for (
auto keyValue = yamlIt->second.begin(); keyValue != yamlIt->second.end(); ++keyValue ) {
229 std::string key = keyValue->first.as<std::string>();
231 if ( key.compare (
"FingersInvolved") == 0 ) {
232 auto tempVect = keyValue->second.as <std::vector <std::string> > ();
235 }
else if ( key.compare (
"Type") == 0 ) {
236 if (ROSEE::Action::Type::Timed != static_cast<ROSEE::Action::Type> ( keyValue->second.as <
unsigned int>() )) {
237 std::cout <<
"[Timed ACTION::" << __func__ <<
"] Error, found type " << keyValue->second.as <
unsigned int>()
238 <<
"instead of Timed type (" << ROSEE::Action::Type::Timed <<
")" << std::endl;
241 type = ROSEE::Action::Type::Timed;
243 }
else if ( key.compare (
"ActionsNamesOrdered") == 0 ) {
246 }
else if ( key.compare (
"JointsInvolvedCount") == 0 ) {
249 }
else if ( key.compare(
"ActionsTimeMargins") == 0 ) {
251 for (
auto tMargins = keyValue->second.begin(); tMargins != keyValue->second.end(); ++tMargins ) {
253 std::string actNAme = tMargins->first.as<std::string>();
254 double before = tMargins->second[
"marginBefore"].as<
double>();
255 double after = tMargins->second[
"marginAfter"].as<
double>();
259 }
else if ( key.compare(
"ActionsJointPos") == 0) {
261 for (
auto jPos = keyValue->second.begin(); jPos != keyValue->second.end(); ++jPos ) {
263 std::string actName = jPos->first.as<std::string>();
268 }
else if ( key.compare(
"ActionsJointCount") == 0) {
270 for (
auto jCount = keyValue->second.begin(); jCount != keyValue->second.end(); ++jCount ) {
272 std::string actName = jCount->first.as<std::string>();
278 }
else if ( key.compare(
"ActionsJointPosFinal") == 0) {
283 std::cerr <<
"[TIMEDACTION::" << __func__ <<
"] Error, not known key " << key << std::endl;
292 unsigned int jointPosIndex,
double percentJointPos, std::string newActionName) {
294 std::string usedName = (newActionName.empty()) ? action->getName() : newActionName;
299 std::cerr <<
"[ACTIONTIMED:: " << __func__ <<
"] ERROR: " << usedName <<
" already present. Failed Insertion" << std::endl;
303 if (marginAfter < 0 || marginBefore < 0) {
304 std::cerr <<
"[ACTIONTIMED:: " << __func__ <<
"] ERROR: Please pass positive time margins" << std::endl;
308 if ( jointPosIndex > action->getAllJointPos().size()-1 ) {
309 std::cerr <<
"[ACTIONTIMED:: " << __func__ <<
"] ERROR: you pass index "<< jointPosIndex <<
310 " but there are only " << action->getAllJointPos().size() <<
" JointPos in the action passed as argument" << std::endl;
314 if (percentJointPos < 0 || percentJointPos > 1) {
315 std::cerr <<
"[ACTIONTIMED:: " << __func__ <<
"] Please insert percentage for jointpos between 0 and 1. Passed: " 316 << percentJointPos << std::endl;
323 std::cerr <<
"[ACTIONTIMED:: " << __func__ <<
"] The action passed as argument has different keys in jointPosmap" 324 <<
" respect to the others inserted in this timed action " << std::endl;
328 ROSEE::JointPos insertingJP = (percentJointPos)*(action->getAllJointPos().at( jointPosIndex )) ;
330 actionsTimeMarginsMap.insert ( std::make_pair( usedName, std::make_pair(marginBefore, marginAfter)));
335 for (
auto it: action->getFingersInvolved() ) {
347 for (
auto jic : action->getJointsInvolvedCount() ) {
350 if (jic.second > 0) {
Type
Enum useful to discriminate each action when, for example, we want to parse a file if you change thi...
ActionTimed()
Default constructor, used when parsing action from yaml file.
bool insertAction(ROSEE::Action::Ptr action, double marginBefore=0.0, double marginAfter=0.0, unsigned int jointPosIndex=0, double percentJointPos=1, std::string newActionName="")
Insert an action as last one in the time line.
std::map< std::string, std::vector< double > > JointPos
The map to describe the position of all actuated joints.
std::vector< ROSEE::JointPos > getAllJointPos() const override
Override function from father Action.
std::map< std::string, unsigned int > JointsInvolvedCount
The map to describe, how many times a joint is set by the action.
std::pair< double, double > getActionMargins(std::string actionName) const
get for time margins
The pure virtual class representing an Action.
ROSEE::JointPos jointPosFinal
Here is contained the wanted final position of the timed action.
bool keys_equal(std::map< keyType, valueType1 > const &lhs, std::map< keyType, valueType2 > const &rhs)
Return false if two maps have different keys.
void emitYaml(YAML::Emitter &out) const override
Emit info in a file with yaml format.
std::map< std::string, ROSEE::JointPos > actionsJointPosMap
bool fillFromYaml(YAML::const_iterator yamlIt) override
Fill the internal data with infos taken from yaml file.
std::map< std::string, std::pair< double, double > > actionsTimeMarginsMap
ROSEE::JointPos getJointPosAction(std::string actionName) const
get for joint positions
std::vector< std::string > getInnerActionsNames() const
getter for action that composed this one
std::vector< ROSEE::JointsInvolvedCount > getAllJointCountAction() const
Get the JointsInvolvedCount maps of all the inner actions, in order.
JointsInvolvedCount jointsInvolvedCount
std::shared_ptr< Action > Ptr
std::vector< std::string > actionsNamesOrdered
This vector is used to take count of the order of the actions inserted.
void print() const override
Print info about this action.
std::map< std::string, ROSEE::JointsInvolvedCount > actionsJointCountMap
ROSEE::JointsInvolvedCount getJointCountAction(std::string actionName) const
get for JointsInvolvedCount of the inner actions
std::set< std::string > fingersInvolved
JointPos getJointPos() const override
Override this function is necessary because it is pure virtual in father class Action.
std::vector< std::pair< double, double > > getAllActionMargins() const
get all the time margins of all inner action