24 type = Action::Type::Composed;
30 type = Action::Type::Composed;
36 type = Action::Type::Composed;
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;
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;
92 for (
auto joint : actionJP ){
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;
116 for (
auto joint : actionJP ) {
117 if ( actionJIC.at( joint.first ) == 0 ) {
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)) /
131 jointPos.at(joint.first).at(dof) = mean;
138 for (
auto it: action->getFingersInvolved() ) {
153 for (
auto jic : action->getJointsInvolvedCount() ){
154 if ( jic.second > 1 ) {
163 for (
auto jic : action->getJointsInvolvedCount() ){
178 std::stringstream output;
180 output <<
"Composed Action '" <<
name;
181 independent ? output <<
"' (independent):" : output <<
"' (not independent):" ;
184 output <<
"Composed by " <<
nInnerActions <<
" inner action: [" ;
186 output << it <<
", ";
188 output.seekp (-2, output.cur);
189 output <<
"]" << std::endl;
191 output <<
"Fingers involved: [" ;
193 output << it <<
", ";
195 output.seekp (-2, output.cur);
196 output <<
"]" << std::endl;
198 output <<
"Each joint influenced by x inner action:" << std::endl;
201 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;
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 ) {
245 }
else if ( key.compare (
"NInnerActions") == 0 ) {
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 ) {
259 }
else if ( key.compare (
"FingersInvolved") == 0 ) {
260 auto tempVect = keyValue->second.as <std::vector <std::string> > ();
263 }
else if ( key.compare (
"JointsInvolvedCount") == 0 ) {
266 }
else if ( key.compare (
"JointPos") == 0 ) {
270 std::cout <<
"[COMPOSED ACTION PARSER] Error, not known key " << key << std::endl;
std::vector< std::string > innerActionsNames
std::map< std::string, std::vector< double > > JointPos
The map to describe the position of all actuated joints.
std::map< std::string, unsigned int > JointsInvolvedCount
The map to describe, how many times a joint is set by the action.
bool empty()
Check if the action composed is empty.
bool keys_equal(std::map< keyType, valueType1 > const &lhs, std::map< keyType, valueType2 > const &rhs)
Return false if two maps have different keys.
unsigned int nInnerActions
virtual void print() const override
Print info about this action (name, jointpos, inner actions names, and other)
Class to handle a generic, simple action.
std::vector< std::string > getInnerActionsNames() const
bool checkIndependency(ROSEE::Action::Ptr action)
unsigned int numberOfInnerActions() const
bool isIndependent() const
virtual bool sumAction(ROSEE::Action::Ptr action, double jointPosScaleFactor=1.0, unsigned int jointPosIndex=0)
Function to add another action to this one.
JointsInvolvedCount jointsInvolvedCount
std::shared_ptr< Action > Ptr
virtual bool fillFromYaml(YAML::const_iterator yamlIt) override
Fill the internal data with infos taken from yaml file.
virtual void emitYaml(YAML::Emitter &out) const override
Emit info in a file with yaml format.
std::set< std::string > fingersInvolved