28 JointPos jp, collision_detection::Contact cont) :
38 JointPos jp, collision_detection::Contact cont) :
62 std::vector < JointPos > retVect;
66 retVect.push_back(it.first);
75 std::vector < ROSEE::ActionPinchTight::StateWithContact > retVect;
79 retVect.push_back(it);
88 auto pairRet =
actionStates.insert ( std::make_pair (jp, cont) ) ;
90 if (! pairRet.second ) {
97 auto it = pairRet.first;
117 std::stringstream output;
118 output <<
"ActionName: " <<
name << std::endl;
120 output <<
"FingersInvolved: [";
122 output << fingName <<
", " ;
124 output.seekp (-2, output.cur);
125 output <<
"]" << std::endl;
127 output <<
"JointsInvolvedCount: " << std::endl;;
130 unsigned int nActState = 1;
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();
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;
166 out << YAML::Key << jointCount.first;
167 out << YAML::Value << jointCount.second;
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;
199 std::vector <std::string> fingInvolvedVect = yamlIt->first.as <std::vector < std::string >> ();
200 for (
const auto &it : fingInvolvedVect) {
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>() );
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) {
225 collision_detection::Contact contact;
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";
299 out << YAML::Value << moveitContact.body_name_1;
300 out << YAML::Key <<
"body_name_2";
301 out << YAML::Value << moveitContact.body_name_2;
302 out << YAML::Key <<
"body_type_1";
303 out << YAML::Value << moveitContact.body_type_1;
304 out << YAML::Key <<
"body_type_2";
305 out << YAML::Value << moveitContact.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;
Type
Enum useful to discriminate each action when, for example, we want to parse a file if you change thi...
Virtual class, Base of all the primitive actions.
std::vector< ROSEE::ActionPinchTight::StateWithContact > getActionStates() const
Specific get for the ActionPinchTight to return the state with contact info.
void emitYaml(YAML::Emitter &) const override
Function to fill the argument passed with info about the action.
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.
A base virtual class for the PinchTight and PinchLoose classes.
void print() const override
For the pinch, we override these function to print, emit and parse the optional info Contact...
Type
Enum useful to discriminate each primitive action when, for example, we want to parse a file if you ...
std::vector< ROSEE::JointPos > getAllJointPos() const override
Return all the joint position stored.
JointsInvolvedCount jointsInvolvedCount
bool emitYamlForContact(collision_detection::Contact, YAML::Emitter &) const
private function to be called by the emitYaml
bool fillFromYaml(YAML::const_iterator yamlIt) override
function to fill members of the Action with infos taken from yaml files
const unsigned int maxStoredActionStates
std::set< StateWithContact, depthComp > actionStates
For each pair, we want a set of action because we want to store (in general) more possible way to do ...
JointPos getJointPos() const override
Get the position related to this action.
std::set< std::string > fingersInvolved
bool insertActionState(JointPos, collision_detection::Contact)
function to insert a single action in the actionStates set of possible action.