48 return (actionStates.begin()->first);
52 auto it = actionStates.begin();
62 std::vector < JointPos > retVect;
63 retVect.reserve ( actionStates.size() );
65 for (
auto it : actionStates ) {
66 retVect.push_back(it.first);
75 std::vector < ROSEE::ActionPinchTight::StateWithContact > retVect;
76 retVect.reserve ( actionStates.size() );
78 for (
auto it : actionStates ) {
79 retVect.push_back(it);
88 auto pairRet = actionStates.insert ( std::make_pair (jp, cont) ) ;
90 if (! pairRet.second ) {
95 if (actionStates.size() > maxStoredActionStates) {
97 auto it = pairRet.first;
99 if ( (++it) == actionStates.end() ){
101 actionStates.erase(pairRet.first);
106 auto lastElem = actionStates.end();
108 actionStates.erase(lastElem);
117 std::stringstream output;
118 output <<
"ActionName: " <<
name << std::endl;
120 output <<
"FingersInvolved: [";
121 for (
auto fingName : fingersInvolved){
122 output << fingName <<
", " ;
124 output.seekp (-2, output.cur);
125 output <<
"]" << std::endl;
127 output <<
"JointsInvolvedCount: " << std::endl;;
128 output << jointsInvolvedCount << std::endl;
130 unsigned int nActState = 1;
131 for (
auto itemSet : actionStates) {
132 output <<
"Action_State_" << nActState <<
" :" << std::endl;
134 output <<
"\t" <<
"JointStates:" << std::endl;
135 output << itemSet.first;
136 output <<
"\t" <<
"MoveitContact:" << std::endl;
137 output <<
"\t\tbody_name_1: " << itemSet.second.body_name_1 << std::endl;
138 output <<
"\t\tbody_name_2: " << itemSet.second.body_name_2 << std::endl;
139 output <<
"\t\tbody_type_1: " << itemSet.second.body_type_1 << std::endl;
140 output <<
"\t\tbody_type_2: " << itemSet.second.body_type_2 << std::endl;
141 output <<
"\t\tdepth: " << itemSet.second.depth << std::endl;
142 output <<
"\t\tnormal: " <<
"["<< itemSet.second.normal.x() <<
", "
143 << itemSet.second.normal.y() <<
", " << itemSet.second.normal.z() <<
"]" << std::endl;
144 output <<
"\t\tpos: " <<
"["<< itemSet.second.pos.x() <<
", "
145 << itemSet.second.pos.y() <<
", " << itemSet.second.pos.z() <<
"]" << std::endl;
151 std::cout << output.str();
158 out << YAML::Key << YAML::Flow << fingersInvolved;
160 unsigned int nCont = 1;
161 out << YAML::Value << YAML::BeginMap;
162 out << YAML::Key <<
"PrimitiveType" << YAML::Value << primitiveType;
163 out << YAML::Key <<
"ActionName" << YAML::Value <<
name;
164 out << YAML::Key <<
"JointsInvolvedCount" << YAML::Value << YAML::BeginMap;
165 for (
const auto &jointCount : jointsInvolvedCount ) {
166 out << YAML::Key << jointCount.first;
167 out << YAML::Value << jointCount.second;
171 for (
const auto & actionState : actionStates) {
173 std::string contSeq =
"ActionState_" + std::to_string(nCont);
174 out << YAML::Key << contSeq;
176 out << YAML::Value << YAML::BeginMap;
178 out << YAML::Key <<
"JointPos" << YAML::Value << YAML::BeginMap;
179 for (
const auto &joint : actionState.first) {
180 out << YAML::Key << joint.first;
181 out << YAML::Value << YAML::Flow << joint.second;
186 out << YAML::Key <<
"Optional" << YAML::Value;
187 emitYamlForContact ( actionState.second, out );
199 std::vector <std::string> fingInvolvedVect = yamlIt->first.as <std::vector < std::string >> ();
200 for (
const auto &it : fingInvolvedVect) {
201 fingersInvolved.insert(it);
204 for ( YAML::const_iterator keyValue = yamlIt->second.begin(); keyValue != yamlIt->second.end(); ++keyValue) {
206 std::string key = keyValue->first.as<std::string>();
207 if (key.compare(
"JointsInvolvedCount") == 0) {
210 }
else if (key.compare (
"ActionName") == 0 ) {
211 name = keyValue->second.as <std::string> ();
213 }
else if (key.compare (
"PrimitiveType") == 0) {
215 keyValue->second.as <
unsigned int>() );
216 if (parsedType != primitiveType ) {
217 std::cerr <<
"[ERROR ActionPinchTight::" << __func__ <<
" parsed a type " << parsedType <<
218 " but this object has primitive type " << primitiveType << std::endl;
222 }
else if (key.compare(0, 12,
"ActionState_") == 0) {
226 for(YAML::const_iterator asEl = keyValue->second.begin(); asEl != keyValue->second.end(); ++asEl) {
229 if (asEl->first.as<std::string>().compare (
"JointPos") == 0 ) {
230 jointPos = asEl->second.as <
JointPos >();
231 }
else if (asEl->first.as<std::string>().compare (
"Optional") == 0 ) {
233 YAML::Node cont = asEl->second[
"MoveItContact"];
234 contact.
body_name_1 = cont[
"body_name_1"].as < std::string >();
235 contact.
body_name_2 = cont[
"body_name_2"].as < std::string >();
236 switch (cont[
"body_type_1"].as < int >())
239 contact.
body_type_1 = collision_detection::BodyType::ROBOT_LINK;
242 contact.
body_type_1 = collision_detection::BodyType::ROBOT_ATTACHED;
245 contact.
body_type_1 = collision_detection::BodyType::WORLD_OBJECT;
248 std::cout <<
"some error, body_type_1" << cont[
"body_type_1"].as <
int >()
249 <<
"unknown" << std::endl;
250 contact.
body_type_1 = collision_detection::BodyType::WORLD_OBJECT;
252 switch (cont[
"body_type_2"].as < int >())
255 contact.
body_type_2 = collision_detection::BodyType::ROBOT_LINK;
258 contact.
body_type_2 = collision_detection::BodyType::ROBOT_ATTACHED;
261 contact.
body_type_2 = collision_detection::BodyType::WORLD_OBJECT;
264 std::cout <<
"some error, body_type_2" << cont[
"body_type_2"].as <
int >()
265 <<
"unknown" << std::endl;
266 contact.
body_type_2 = collision_detection::BodyType::WORLD_OBJECT;
268 contact.
depth = cont[
"depth"].as<
double>();
269 std::vector < double > normVect = cont[
"normal"].as < std::vector <double> >();
270 std::vector < double > posVect = cont[
"pos"].as < std::vector <double> >();
271 contact.
normal = Eigen::Vector3d (normVect.data() );
272 contact.
pos = Eigen::Vector3d (posVect.data() );
276 std::cerr <<
"[ERROR ActionPinchTight::" << __func__ <<
"not know key "
277 << asEl->first.as<std::string>() <<
278 " found in the yaml file at this level" << std::endl;
282 actionStates.insert ( std::make_pair (jointPos, contact));
285 std::cerr <<
"[ERROR ActionPinchTight::" << __func__ <<
"not know key " << key <<
286 " found in the yaml file" << std::endl;
296 out << YAML::BeginMap;
297 out << YAML::Key <<
"MoveItContact" << YAML::Value << YAML::BeginMap;
298 out << YAML::Key <<
"body_name_1";
300 out << YAML::Key <<
"body_name_2";
302 out << YAML::Key <<
"body_type_1";
304 out << YAML::Key <<
"body_type_2";
306 out << YAML::Key <<
"depth";
307 out << YAML::Value << moveitContact.
depth;
308 out << YAML::Key <<
"normal";
309 std::vector < double > normal ( moveitContact.
normal.data(), moveitContact.
normal.data() + moveitContact.
normal.rows());
310 out << YAML::Value << YAML::Flow << normal;
311 out << YAML::Key <<
"pos";
312 std::vector < double > pos ( moveitContact.
pos.data(), moveitContact.
pos.data() + moveitContact.
pos.rows());
313 out << YAML::Value << YAML::Flow << pos;