18 #include "ui_planpanel.h" 20 using namespace se2ez;
24 :
Panel(name, parent), ui_(new
Ui::
PlanPanel), robot_(robot), constraints_(constraints)
39 ui_->constraints->addItem(
"<none>");
40 for (
const auto &constraint : constraints)
41 ui_->constraints->addItem(QString(constraint.first.c_str()));
44 for (
const auto &name :
planner_->getPlanners())
45 ui_->planners->addItem(QString(name.
c_str()));
48 for (
const auto &name :
robot_->getFrameNames())
50 const auto &data =
robot_->getFrameDataConst(name);
52 ui_->ees->addItem(QString(name.
c_str()));
56 ui_->pathSlider->setEnabled(
false);
58 anim_.setTargetObject(
ui_->pathSlider);
59 anim_.setPropertyName(
"value");
62 connect(
ui_->plan, SIGNAL(clicked()),
this, SLOT(
plan()));
63 connect(
ui_->pathSlider, SIGNAL(valueChanged(
int)),
this, SLOT(
setState(
int)));
65 connect(
ui_->animTime, SIGNAL(valueChanged(
double)),
this, SLOT(
animateTime()));
66 connect(
ui_->planners, SIGNAL(currentTextChanged(
const QString &)),
this,
69 connect(
ui_->sweptCount, SIGNAL(valueChanged(
int)),
this, SLOT(
updateState()));
70 connect(
ui_->draw, SIGNAL(toggled(
bool)),
this, SLOT(
updateState()));
71 connect(
ui_->constraints, SIGNAL(currentTextChanged(
const QString &)),
this,
74 connect(
ui_->ees, SIGNAL(currentTextChanged(
const QString &)),
this, SLOT(
setEE(
const QString &)));
75 connect(
ui_->gorn, SIGNAL(toggled(
bool)),
this, SLOT(
updateState()));
76 connect(
ui_->gstate, SIGNAL(toggled(
bool)),
this, SLOT(
updateState()));
77 connect(
ui_->gedge, SIGNAL(toggled(
bool)),
this, SLOT(
updateState()));
80 ui_->ees->setCurrentIndex(
ui_->ees->count() - 1);
83 int index =
ui_->planners->findText(
"rrt:RRTConnect", Qt::MatchExactly);
85 ui_->planners->setCurrentIndex(index);
102 ee_ = text.toStdString();
113 if (
ui_->constraints->currentIndex() != 0)
115 const auto &constraint = text.toStdString();
122 planner_->initialize();
123 planner_->createPlanners();
134 while (
ui_->parameters->count())
136 QLayoutItem *child =
ui_->parameters->takeAt(0);
137 delete child->widget();
143 const auto &planner = text.toStdString();
147 if (planner ==
"prm:PRM")
151 for (
const auto &entry :
set_.getParams())
153 const auto &
name = entry.first;
156 if (formatted_name.
size() > 28)
158 formatted_name.
resize(25);
159 formatted_name +=
"...";
162 auto ¶m = entry.second;
163 const auto &range = param->getRangeSuggestion();
167 if (maybeBool.size() == 2)
169 auto box =
new QCheckBox();
170 connect(box, &QCheckBox::stateChanged, [&,
name](
int state) {
171 std::string value = (state == Qt::Unchecked) ?
"0" :
"1";
175 box->setCheckState(boost::lexical_cast<bool>(param->getValue()) ? Qt::Checked : Qt::Unchecked);
176 ui_->parameters->addRow(QString(formatted_name.
c_str()), box);
181 const auto &vt = param->getValue();
183 range.find_first_of(
".") != std::string::npos || vt.find_first_of(
".") != std::string::npos;
191 double min = 0, max = 1, step = 0.1;
192 if (numbers.size() == 3)
194 min = boost::lexical_cast<
double>(numbers[0]);
195 step = boost::lexical_cast<
double>(numbers[1]);
196 max = boost::lexical_cast<
double>(numbers[2]);
198 else if (numbers.size() == 2)
200 min = boost::lexical_cast<
double>(numbers[0]);
201 max = boost::lexical_cast<
double>(numbers[1]);
204 auto box =
new QDoubleSpinBox();
205 box->setMaximum(max);
206 box->setMinimum(min);
207 box->setSingleStep(step);
209 connect(box,
static_cast<void (QDoubleSpinBox::*)(
double)
>(&QDoubleSpinBox::valueChanged),
210 [&,
name](
double value) {
221 box->setValue(boost::lexical_cast<double>(param->getValue()));
222 ui_->parameters->addRow(QString(formatted_name.
c_str()), box);
225 else if (not numbers.empty())
227 int min = 0, max = 100, step = 1;
228 if (numbers.size() == 3)
230 min = boost::lexical_cast<
int>(numbers[0]);
231 step = boost::lexical_cast<
int>(numbers[1]);
232 max = boost::lexical_cast<
int>(numbers[2]);
234 else if (numbers.size() == 2)
236 min = boost::lexical_cast<
int>(numbers[0]);
237 max = boost::lexical_cast<
int>(numbers[1]);
240 auto box =
new QSpinBox();
241 box->setMaximum(max);
242 box->setMinimum(min);
243 box->setSingleStep(step);
245 connect(box,
static_cast<void (QSpinBox::*)(
int)
>(&QSpinBox::valueChanged),
246 [&,
name](
int value) {
257 box->setValue(boost::lexical_cast<int>(param->getValue()));
258 ui_->parameters->addRow(QString(formatted_name.
c_str()), box);
263 auto line =
new QLineEdit(QString(param->getValue().c_str()));
264 ui_->parameters->addWidget(line);
265 connect(line, &QLineEdit::textChanged, [&,
name](
const QString &newValue) {
266 const auto value = newValue.toStdString();
270 ui_->parameters->addRow(QString(formatted_name.
c_str()), line);
275 ui_->parameters->itemAt(
ui_->parameters->rowCount() - 1, QFormLayout::LabelRole)->widget();
277 ui_->parameters->itemAt(
ui_->parameters->rowCount() - 1, QFormLayout::FieldRole)->widget();
278 label->setToolTip(QString(
name.c_str()));
279 widget->setToolTip(QString(
name.c_str()));
285 if (state == Qt::Checked)
299 if (
ui_->animateBox->isChecked())
314 anim_.setDuration(
ui_->animTime->value() * 1000);
315 anim_.setLoopCount(-1);
317 anim_.setStartValue(
ui_->pathSlider->minimum());
319 anim_.setEndValue(
ui_->pathSlider->maximum() + 1);
336 for (
unsigned int i = 0; i <
path_.size() - 1; ++i)
341 ui_->pathSlider->setMaximum(
path_.size() - 1);
342 ui_->pathSlider->setEnabled(
true);
362 if (
ui_->constraints->currentIndex() == 0)
364 auto pd = std::make_shared<ompl::base::PlannerData>(
planner_->info);
365 planner_->setup->getPlannerData(*pd);
366 pd->decoupleFromPlanner();
376 auto state = std::make_shared<State>(
robot_);
381 auto entry =
panels->find(name);
387 robot_->getNamedState(name, state);
405 ui_->setbox->setEnabled(
false);
406 ui_->planbox->setEnabled(
false);
407 ui_->scrollArea->setEnabled(
false);
414 if (
ui_->clear->isChecked())
419 planner_->setup->getProblemDefinition());
420 auto *pdef =
const_cast<ompl::base::ProblemDefinition *
>(cptr.get());
423 pdef->clearSolutionPaths();
425 planner_->setup->getPlanner()->clearQuery();
428 planner_->info->setStateValidityCheckingResolution(
ui_->valid->value());
434 ompl::base::PlannerStatus solved =
planner_->setup->solve(
ui_->time->value());
436 ui_->approx->isChecked() ? solved : solved == ompl::base::PlannerStatus::EXACT_SOLUTION;
440 if (
ui_->simplify->isChecked())
441 planner_->setup->simplifySolution();
443 if (
ui_->interpolate->isChecked())
445 auto &path =
planner_->setup->getSolutionPath();
472 ui_->gstatel->setText(
"0");
473 ui_->gedgel->setText(
"0");
477 ui_->setbox->setEnabled(
true);
478 ui_->planbox->setEnabled(
true);
479 ui_->scrollArea->setEnabled(
true);
488 bool path =
ui_->draw->isChecked();
489 if (path &&
path_.size())
492 bool swept =
ui_->swept->isChecked();
493 unsigned int count =
ui_->sweptCount->value();
497 for (
unsigned int i = 0; i <
path_.size() - 1; i += count)
510 bool edges =
ui_->gedge->isChecked();
511 bool states =
ui_->gstate->isChecked();
512 bool orn =
ui_->gorn->isChecked();
513 if (
pd_ && (edges || states || orn))
518 painter.resetTransform();
520 for (
unsigned int i = 0; i <
pd_->numVertices(); ++i)
522 const auto &vert =
pd_->getVertex(i);
523 const auto &state =
planner_->getStateConst(vert.getState());
525 QColor color(0, 255, 164);
526 if (vert.getTag() == 2)
527 color = QColor(0, 164, 255);
534 auto pose = iso.translation();
537 canvas->
toScreen(pose[0], pose[1], x, y);
540 painter.fillRect(x - 3, y - 3, 6, 6, color);
544 Eigen::Vector2d rot{0.15, 0};
548 canvas->
toScreen(rot[0], rot[1], xa, ya);
550 painter.drawLine(x, y, xa, ya);
556 unsigned int m =
pd_->getEdges(i, edge);
558 for (
unsigned int j = 0; j < m; ++j)
560 const auto &next =
planner_->getStateConst(
pd_->getVertex(edge[j]).getState());
563 auto npose = next->getPose(
robot_,
ee_).translation();
566 canvas->
toScreen(npose[0], npose[1], xa, ya);
568 painter.drawLine(x, y, xa, ya);
577 if (
ui_->constraints->currentIndex() != 0)
579 const auto &text =
ui_->constraints->currentText();
584 painter.resetTransform();
585 QPen pen(QColor(255, 164, 0));
591 Eigen::Vector2d a, b;
592 line->getEndpoints(a, b,
pstate_);
595 canvas->
toScreen(a[0], a[1], ax, ay);
596 canvas->
toScreen(b[0], b[1], bx, by);
598 painter.drawLine(ax, ay, bx, by);
599 painter.drawText(bx + 3, by, text);
609 canvas->
toScreen(a[0], a[1], ax, ay);
610 painter.drawEllipse(ax, ay, 5, 5);
611 painter.drawText(ax + 7, ay, text);
620 Eigen::Vector2d p, r;
624 canvas->
toScreen(p[0], p[1], px, py);
626 canvas->
toScreen(r[0], r[1], rx, ry);
632 painter.translate(px, py);
635 painter.drawEllipse(-rx, -ry, 2*rx, 2*ry);
638 painter.drawText(px + 7, py, text);
650 for (
const auto &
name :
robot_->getNamedStates())
660 for (
const auto &panel : *
panels)
668 if (jpanel->getSignature().compare(
robot_->getSignature()) == 0)
680 ui_->startComboBox->clear();
681 ui_->goalComboBox->clear();
686 ui_->startComboBox->addItem(QString(
name.c_str()));
687 ui_->goalComboBox->addItem(QString(
name.c_str()));
690 int count =
ui_->startComboBox->count();
691 ui_->startComboBox->insertSeparator(count);
692 ui_->goalComboBox->insertSeparator(count);
697 ui_->startComboBox->addItem(QString(
name.c_str()));
698 ui_->goalComboBox->addItem(QString(
name.c_str()));
701 count =
ui_->startComboBox->count();
704 ui_->startComboBox->setCurrentIndex(count - 2);
705 ui_->goalComboBox->setCurrentIndex(count - 1);
std::vector< StatePtr > path_
plan::EZPlansPtr planner_
A shared pointer wrapper for se2ez::State.
PlanPanel(RobotPtr robot, std::string name, std::map< std::string, ompl::base::ConstraintPtr > constraints={}, QWidget *parent=0)
std::set< std::string > jnames_
void setEE(const QString &text)
std::set< std::string > panelnames_
void drawGeometry(QPainter &painter, RobotPtr robot, StatePtr state, GeometryDrawerPtr drawer=nullptr)
ompl::base::PlannerDataPtr pd_
void getPoint(Eigen::Ref< Eigen::VectorXd > a, const StatePtr &state) const
void update(boost::posix_time::ptime last, boost::posix_time::ptime current) override
ompl::base::PlannerDataPtr getPlannerData()
std::map< std::string, ompl::base::ConstraintPtr > constraints_
ompl::base::ParamSet set_
#define SE2EZ_WARN(fmt,...)
StatePtr getState(const QString &s)
T static_pointer_cast(T... args)
void getState(StatePtr state)
void toScreen(double xin, double yin, int &xout, int &yout)
std::vector< std::string > tokenize(const std::string &string, const std::string &separators)
Separates a string into tokens, based upon separators.
void setPath(const std::vector< StatePtr > path)
MainWindow::PanelMapPtr panels
void draw(QPainter &painter, RenderArea *canvas) override
void plannerChanged(const QString &text)
A shared pointer wrapper for se2ez::Robot.
std::string format(const std::string &fmt, Args &&... args)
void setConstraints(const QString &text)
The canvas widget. It contains all the drawing functions as well as all the general settings for draw...
#define SE2EZ_ERROR(fmt,...)
const std::vector< StatePtr > & getPath() const
void getCircle(Eigen::Ref< Eigen::VectorXd > p, Eigen::Ref< Eigen::VectorXd > r, double &v, const StatePtr &state) const
std::set< std::string > snames_