24 type = Action::Type::Composed;
30 type = Action::Type::Composed;
36 type = Action::Type::Composed;
48 return innerActionsNames;
52 return (nInnerActions == 0);
59 if ( ! checkIndependency(action) ) {
63 if ( jointPosIndex > action->getAllJointPos().size()-1 ) {
64 std::cerr <<
"[ACTIONCOMPOSED:: " << __func__ <<
"] The given jointPosindex " << jointPosIndex
65 <<
" exceed the number " << action->getAllJointPos().size() <<
" of jointpos of passed action" << std::endl;
69 if ( nInnerActions > 0 &&
71 std::cerr <<
"[ACTIONCOMPOSED:: " << __func__ <<
"] The action passed as argument has different keys in jointPosmap"
72 <<
" respect to the others inserted in this composed action " << std::endl;
76 if (jointPosScaleFactor < 0) {
77 std::cerr <<
"[ACTIONCOMPOSED:: " << __func__ <<
"] You can not scale the joint position of the action to be inserted by a "
78 <<
"value less than 0; jointPosScaleFactor passed is: " << jointPosScaleFactor << std::endl;
82 if (jointPosScaleFactor > 1) {
83 std::wcerr <<
"[ACTIONCOMPOSED:: " << __func__ <<
"] WARNING, You are scaling with a value greater than 1 "
84 <<
" this could cause to command position over the joint limits; jointPosScaleFactor passed is: " << jointPosScaleFactor << std::endl;
87 JointPos actionJP = action->getAllJointPos().at(jointPosIndex) * jointPosScaleFactor;
90 if (nInnerActions == 0) {
92 for (
auto joint : actionJP ){
93 jointsInvolvedCount.insert ( std::make_pair (joint.first, actionJIC.at(joint.first) ) );
94 jointPos.insert ( std::make_pair (joint.first, joint.second) );
102 for (
auto joint : actionJP ){
104 if ( actionJIC.at (joint.first ) > 0 ) {
106 jointPos.at(joint.first) = joint.second;
107 jointsInvolvedCount.at(joint.first) += actionJIC.at (joint.first );
116 for (
auto joint : actionJP ) {
117 if ( actionJIC.at( joint.first ) == 0 ) {
122 jointsInvolvedCount.at(joint.first) += actionJIC.at (joint.first );
125 for (
unsigned int dof = 0; dof < joint.second.size(); dof++ ) {
127 double mean = jointPos.at( joint.first ).at(dof) +
128 ( (joint.second.at(dof) - jointPos.at(joint.first).at(dof)) /
129 jointsInvolvedCount.at(joint.first) );
131 jointPos.at(joint.first).at(dof) = mean;
137 innerActionsNames.push_back ( action->getName() );
138 for (
auto it: action->getFingersInvolved() ) {
139 fingersInvolved.insert ( it );
151 }
else if (nInnerActions == 0 ) {
153 for (
auto jic : action->getJointsInvolvedCount() ){
154 if ( jic.second > 1 ) {
163 for (
auto jic : action->getJointsInvolvedCount() ){
164 if ( jic.second + jointsInvolvedCount.at(jic.first) > 1 ) {
178 std::stringstream output;
180 output <<
"Composed Action '" <<
name;
181 independent ? output <<
"' (independent):" : output <<
"' (not independent):" ;
184 output <<
"Composed by " << nInnerActions <<
" inner action: [" ;
185 for (
auto it : innerActionsNames) {
186 output << it <<
", ";
188 output.seekp (-2, output.cur);
189 output <<
"]" << std::endl;
191 output <<
"Fingers involved: [" ;
192 for (
auto it : fingersInvolved) {
193 output << it <<
", ";
195 output.seekp (-2, output.cur);
196 output <<
"]" << std::endl;
198 output <<
"Each joint influenced by x inner action:" << std::endl;
199 output << jointsInvolvedCount;
201 output <<
"JointPos:" << std::endl;
202 output << jointPos << std::endl;
204 std::cout << output.str();
210 out << YAML::BeginMap << YAML::Key <<
name << YAML::Value << YAML::BeginMap ;
211 out << YAML::Key <<
"Type" << YAML::Value << type;
212 out << YAML::Key <<
"Independent" << YAML::Value << independent;
213 out << YAML::Key <<
"NInnerActions" << YAML::Value << nInnerActions;
214 out << YAML::Key <<
"InnerActionsNames" << YAML::Value << YAML::Flow << innerActionsNames;
215 out << YAML::Key <<
"FingersInvolved" << YAML::Value << YAML::Flow << fingersInvolved;
216 out << YAML::Key <<
"JointsInvolvedCount" << YAML::Value << YAML::BeginMap;
217 for (
const auto &jointCount : jointsInvolvedCount ) {
218 out << YAML::Key << jointCount.first;
219 out << YAML::Value << jointCount.second;
223 out << YAML::Key <<
"JointPos" << YAML::Value << YAML::BeginMap;
224 for (
const auto &joint : jointPos) {
225 out << YAML::Key << joint.first;
226 out << YAML::Value << YAML::Flow << joint.second;
236 name = yamlIt->first.as<std::string>();
238 for (
auto keyValue = yamlIt->second.begin(); keyValue != yamlIt->second.end(); ++keyValue ) {
240 std::string key = keyValue->first.as<std::string>();
242 if ( key.compare (
"Independent") == 0 ) {
243 independent = keyValue->second.as<
bool>();
245 }
else if ( key.compare (
"NInnerActions") == 0 ) {
246 nInnerActions = keyValue->second.as <
unsigned int>();
248 }
else if ( key.compare (
"Type") == 0 ) {
249 if (ROSEE::Action::Type::Composed !=
static_cast<ROSEE::Action::Type> ( keyValue->second.as <
unsigned int>() )) {
250 std::cout <<
"[COMPOSED ACTION::" << __func__ <<
"] Error, found type " << keyValue->second.as <
unsigned int>()
251 <<
"instead of Composed type (" << ROSEE::Action::Type::Composed <<
")" << std::endl;
254 type = ROSEE::Action::Type::Composed;
256 }
else if ( key.compare (
"InnerActionsNames") == 0 ) {
257 innerActionsNames = keyValue->second.as <std::vector <std::string> >();
259 }
else if ( key.compare (
"FingersInvolved") == 0 ) {
260 auto tempVect = keyValue->second.as <std::vector <std::string> > ();
261 fingersInvolved.insert ( tempVect.begin(), tempVect.end() );
263 }
else if ( key.compare (
"JointsInvolvedCount") == 0 ) {
266 }
else if ( key.compare (
"JointPos") == 0 ) {
267 jointPos = keyValue->second.as <
JointPos >();
270 std::cout <<
"[COMPOSED ACTION PARSER] Error, not known key " << key << std::endl;