se2ez
motionbuilder.cpp
Go to the documentation of this file.
1 /* Author: Constantinos Chamzas */
2 
3 #include <iostream>
4 
5 #include <se2ez/core/log.h>
6 #include <se2ez/core/math.h>
7 #include <se2ez/core/frame.h>
8 #include <se2ez/core/state.h>
10 #include <se2ez/core/scene.h>
11 #include <se2ez/core/robot.h>
12 #include <se2ez/core/ik.h>
13 
15 
16 using namespace se2ez;
17 
18 ///
19 /// MotionBuilder
20 ///
21 
23  const std::vector<std::string> &frames)
24  : robot_(robot), cm_(std::make_shared<Box2DCollisionManager>(robot)), ee_(ee)
25 {
26  ik_ = std::make_shared<CollisionAwareChainIK>(robot_, ee, 100);
27  for (const auto &fname : frames)
28  ees_.emplace(fname);
29 }
30 
31 MotionBuilder::MotionBuilder(const RobotPtr &robot, const std::string &ee, const std::string &prefix)
32  : MotionBuilder(robot, ee, [&]() {
34 
35  for (const auto &fname : robot->getFrameNames())
36  {
37  if (fname.find(prefix) != std::string::npos)
38  frames.emplace_back(fname);
39  }
40  return frames;
41  }())
42 
43 {
44 }
45 
47 {
48  goals_.clear();
49  switch (type)
50  {
51  case FRAME:
52  genFrameGoals();
53  break;
54  case NAMED:
55  genNamedGoals();
56  break;
57  case ALL:
58  genAllGoals();
59  }
60 
61  return goals_;
62 }
63 
65 {
66  queries_.clear();
67  genGoals(type);
68 
69  for (auto it1 = goals_.begin(); it1 != goals_.end(); ++it1)
70  for (auto it2 = std::next(it1); it2 != goals_.end(); ++it2)
71  queries_.emplace(it1->second, it2->second);
72 
73  if (!queries_.size())
74  SE2EZ_WARN("Queries list is empty");
75 
76  return queries_;
77 }
79 {
80  for (const auto &ee : ees_)
81  {
82  const auto &eepose = robot_->getFrame(ee);
83  auto goal = std::make_shared<State>(robot_);
84 
85  if (ik_->solve(goal, eepose->getTip()))
86  goals_.emplace(eepose->getName(), goal);
87  else
88  SE2EZ_WARN("IK solution for: %s with EE:%s was not found. \n. Did you Choose the correct EE?",
89  eepose->getName(), ee_);
90  }
91 }
92 
94 {
95  for (auto pair : robot_->getNamedStatesMap())
96  if (!cm_->collide(pair.second))
97  goals_.emplace(pair.first, pair.second);
98  else
99  SE2EZ_WARN("Named state: %s is in collision", pair.second);
100 }
101 
103 {
104  genFrameGoals();
105  genNamedGoals();
106 }
107 
void genAllGoals()
Generates both Frame and Named Goals.
std::set< std::string > ees_
eeposes to place the end effector
Definition: motionbuilder.h:99
const std::map< std::string, StatePtr > & genGoals(QueryType type)
generates the goals
genGoals() returns only states found with IK
Definition: motionbuilder.h:41
std::set< std::pair< StatePtr, StatePtr > > queries_
valid motion planning queries (Start,Goal)
Definition: motionbuilder.h:98
A collisions manager that uses Box2D as the underlying collision checking engine. ...
Definition: collision.h:41
CollisionAwareChainIKPtr ik_
the ik_solver
const std::string ee_
end effector used by the ik_solver
const std::set< std::pair< StatePtr, StatePtr > > & getQueries(QueryType type=ALL)
Gets the motion planning queries as (Start, Goal) pairs.
T next(T... args)
CollisionManagerPtr cm_
the collision manager to be used by the ik_solver
#define SE2EZ_WARN(fmt,...)
Definition: log.h:41
QueryType
Type of the requested goal generation query.
Definition: motionbuilder.h:38
void genNamedGoals()
Generates goals from the named states.
Given a robot it generates queries (IK solutions for a specific set of frames)
Definition: motionbuilder.h:31
genGoals() returns both of the above
Definition: motionbuilder.h:42
std::map< std::string, StatePtr > goals_
Valid goals.
Definition: motionbuilder.h:97
A shared pointer wrapper for se2ez::Robot.
MotionBuilder(const RobotPtr &robot, const std::string &ee, const std::vector< std::string > &frames)
Constructor. Will generate queries for these samples.
genGoals() returns only Named
Definition: motionbuilder.h:40
T emplace(T... args)
Main namespace.
Definition: collision.h:11
void genFrameGoals()
Generates goals by finding IK solutions of the ee on the given frames.
RobotPtr robot_
underlying robot to find configurations for
T emplace_back(T... args)