se2ez
plan_constraint.cpp
Go to the documentation of this file.
1 /* Author: Zachary Kingston */
2 
3 #include <iostream>
4 
5 #include <ompl/base/Constraint.h>
6 #include <ompl/base/ConstrainedSpaceInformation.h>
7 #include <ompl/base/spaces/constraint/ProjectedStateSpace.h>
8 
9 #include <ompl/geometric/SimpleSetup.h>
10 #include <ompl/geometric/planners/rrt/RRTConnect.h>
11 #include <ompl/geometric/planners/prm/PRM.h>
12 #include <ompl/geometric/planners/est/BiEST.h>
13 
14 #include <thread>
15 #include <chrono>
16 
17 #include <se2ez/core.h>
18 #include <se2ez/plan.h>
19 #include <se2ez/gui.h>
20 #include <se2ez/gui/planpanel.h>
21 
22 using namespace se2ez;
23 
24 int main(int argc, char **argv)
25 {
26  if (argc < 5)
27  {
28  std::cout << "Usage: ./plan_constraint [filename] [start] [goal] [constraint]" << std::endl;
29  return -1;
30  }
31 
32  auto robot = io::loadRobot(std::string(argv[1]));
33  if (!robot)
34  return -1;
35 
36  auto constraints = plan::loadConstraints(robot, std::string(argv[1]));
37  auto constraint = constraints.find(std::string(argv[4]));
38  if (constraint == constraints.end())
39  {
40  SE2EZ_ERROR("Constraint %1% does not exist in %2%!", argv[4], argv[1]);
41  return -1;
42  }
43 
44  plan::EZPlansConstraint planner(robot, constraint->second, plan::PROJECTION);
45  planner.initialize();
46 
47  planner.setPlanner("prm:PRM");
48  planner.setStartGoal(std::string(argv[2]), std::string(argv[3]));
49 
50  ompl::base::PlannerStatus solved = planner.setup->solve(10.0);
51 
52  if (solved)
53  {
54  std::cout << "Found solution!" << std::endl;
55  auto &path = planner.setup->getSolutionPath();
56  path.interpolate();
57  }
58  else
59  {
60  std::cout << "No solution found" << std::endl;
61  return 0;
62  }
63 
64  QApplication a(argc, argv);
65  gui::MainWindow gui;
66 
67  auto panel = new gui::PlanPanel(robot, "Robot1");
68  gui.addPanel(panel);
69  gui.show();
70 
71  panel->setPath(planner.extractPath());
72 
73  return a.exec();
74 }
ompl::geometric::SimpleSetupPtr setup
Definition: helper.h:93
RobotPtr loadRobot(const std::string &filename)
Loads a robot from a YAML file.
Definition: yaml.cpp:303
std::vector< StatePtr > extractPath() const
Definition: helper.cpp:205
The main widget that acts a container for other widgets (canvas, panels). It also delegates the drawi...
Definition: mainwindow.h:34
T endl(T... args)
void addPanel(Panel *panel)
Adds a panel to the main GUI.
Definition: mainwindow.cpp:95
int main(int argc, char **argv)
std::shared_ptr< T > setPlanner(Args &&... args)
Definition: helper.h:45
std::map< std::string, ompl::base::ConstraintPtr > loadConstraints(const RobotPtr &robot, const std::string &filename)
Definition: yaml.cpp:135
Main namespace.
Definition: collision.h:11
void initialize() override
Definition: helper.cpp:240
#define SE2EZ_ERROR(fmt,...)
Definition: log.h:39
bool setStartGoal(const std::string &start, const std::string &goal)
Definition: helper.cpp:118