3 #include <condition_variable>
6 #include <boost/uuid/uuid.hpp>
7 #include <boost/uuid/uuid_generators.hpp>
8 #include <boost/uuid/uuid_io.hpp>
19 boost::uuids::random_generator gen;
20 boost::uuids::uuid u = gen();
21 return boost::lexical_cast<std::string>(u);
29 : dart::gui::osg::ImGuiViewer(::osg::Vec4(1.0, 1.0, 1.0, 1.0)), world_(world)
36 osgViewer::Viewer::updateTraversal();
67 disableLinearControls();
68 disableRotationControls();
69 disablePlanarControls();
77 : dart::gui::osg::WorldNode(world->getSim()),
world_(world),
viewer_(world)
81 viewer_.setUpViewInWindow(0, 0, 1080, 720);
82 auto *cm =
viewer_.getCameraManipulator();
84 ::osg::Vec3(5.00, 5.00, 2.00),
85 ::osg::Vec3(0.00, 0.00, 0.00),
86 ::osg::Vec3(-0.24, -0.25, 0.94));
87 viewer_.setCameraManipulator(cm);
88 viewer_.setVerticalFieldOfView(15);
90 widget_ = std::make_shared<WindowWidget>();
109 widget->initialize(
const_cast<Window *
>(
this));
110 viewer_.getImGuiHandler()->addWidget(widget);
116 r.
target = std::make_shared<dart::gui::osg::InteractiveFrame>(
122 auto *lt = r.
target->getTool(dart::gui::osg::InteractiveTool::Type::LINEAR, i);
123 lt->setEnabled(options.
linear[i]);
124 auto *rt = r.
target->getTool(dart::gui::osg::InteractiveTool::Type::ANGULAR, i);
125 rt->setEnabled(options.
rotation[i]);
126 auto *pt = r.
target->getTool(dart::gui::osg::InteractiveTool::Type::PLANAR, i);
127 pt->setEnabled(options.
planar[i]);
134 r.
signal = r.
target->onTransformUpdated.connect([
callback](
const dart::dynamics::Entity *entity) {
137 const auto *cast =
dynamic_cast<const dart::gui::osg::InteractiveFrame *
>(entity);
149 auto *dnd =
viewer_.enableDragAndDrop(node,
true,
true);
152 r.
signal = node->onTransformUpdated.connect([dnd,
callback](
const dart::dynamics::Entity *entity) {
154 callback(
dynamic_cast<const dart::dynamics::BodyNode *
>(entity));
173 auto thread = std::make_shared<std::thread>([&] {
178 while ((times == 0) ?
true : i--)
180 space->setWorldState(
world_, path.getState(0));
185 space->setWorldState(
world_, path.getState(j));
202 cv.
wait(lk, [&] {
return not active; });
209 ompl::geometric::PathGeometric extract(builder.
rinfo);
210 for (
std::size_t i = 0; i < path.getStateCount(); ++i)
283 const auto &button = ImGui::Button(
text.
c_str());
341 ImGui::PushID(
id.c_str());
342 ImGui::PushStyleColor(ImGuiCol_PlotLines,
345 char overlay[64] =
"N/A";
351 ImGui::PopStyleColor(1);
371 ImGui::SetNextWindowBgAlpha(0.5f);
372 if (!ImGui::Begin(
"Robowflex DART",
nullptr,
373 ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_HorizontalScrollbar))
385 addElement(std::make_shared<TextElement>(text));
395 addElement(std::make_shared<CheckboxElement>(text,
boolean));
412 : name_(name), original_(spec), spec_(spec)
418 auto world = window->
world_;
422 frame_opt.
name =
"TSREditWidget-" +
name_ +
"-frame";
430 offset_ = std::make_shared<dart::dynamics::SimpleFrame>(dart::dynamics::Frame::World(),
431 "TSREditWidget-" +
name_ +
"-offset");
432 world->getSim()->addSimpleFrame(
offset_);
436 ll_opt.
name =
"TSREditWidget-" +
name_ +
"-ll";
451 uu_opt.
name =
"TSREditWidget-" +
name_ +
"-uu";
466 std::make_shared<dart::dynamics::SimpleFrame>(
offset_.get(),
"TSREditWidget-" +
name_ +
"-shape");
467 world->getSim()->addSimpleFrame(
shape_);
472 rbounds_[i] = std::make_shared<dart::dynamics::SimpleFrame>(
475 Eigen::Isometry3d tf = Eigen::Isometry3d::Identity();
481 rbounds_[i]->setRelativeTransform(tf);
482 world->getSim()->addSimpleFrame(
rbounds_[i]);
486 tsr_ = std::make_shared<darts::TSR>(world,
spec_);
507 tsr_->updateBounds();
508 tsr_->updateSolver();
561 const auto &tf =
frame->getRelativeTransform();
574 Eigen::Vector3d t =
frame->getRelativeTransform().translation();
575 Eigen::Vector3d diff =
591 Eigen::Vector3d t =
frame->getRelativeTransform().translation();
592 Eigen::Vector3d diff =
637 auto *va =
shape_->getVisualAspect(
true);
639 va->setShadowed(
false);
650 auto *va =
rbounds_[i]->getVisualAspect(
true);
651 va->setShadowed(
false);
668 ImGui::SetNextWindowBgAlpha(0.5f);
670 if (!ImGui::Begin(title.
c_str(),
nullptr, ImGuiWindowFlags_HorizontalScrollbar))
677 if (ImGui::TreeNodeEx(
"Frame", ImGuiTreeNodeFlags_DefaultOpen))
682 if (ImGui::Button(
"Reset Position"))
690 if (ImGui::Button(
"Reset Rotation"))
703 if (ImGui::TreeNodeEx(
"Bounds", ImGuiTreeNodeFlags_DefaultOpen))
708 ImGui::Text(
"Position Bounds");
717 ImGui::Text(
"Rotation Bounds");
725 if (ImGui::Button(
"Reset Bounds"))
736 if (ImGui::Button(
"Print TSR"))
777 ImGui::SetNextWindowBgAlpha(0.5f);
779 if (!ImGui::Begin(title.
c_str(),
nullptr, ImGuiWindowFlags_HorizontalScrollbar))
786 if (ImGui::TreeNodeEx(
"Solving", ImGuiTreeNodeFlags_DefaultOpen))
796 tsrs_->updateSolver();
798 if (ImGui::SliderFloat(
"Step", &
step_, 0.001f, 1.f))
801 if (ImGui::SliderFloat(
"Limit", &
limit_, 0.001f, 1.f))
808 tsrs_->updateSolver();
811 const char *items[] = {
"dSVD",
"SVD",
"QR"};
812 if (ImGui::Combo(
"combo", &
item_, items, IM_ARRAYSIZE(items)))
817 tsrs_->useDamping(
true);
822 tsrs_->useDamping(
false);
828 if (ImGui::SliderFloat(
"Damp.", &
damping_, 1e-8f, 1e-3f,
"< %.8f", 10.f))
833 if (ImGui::Button(
"Solve TSR"))
839 ImGui::TextColored((ImVec4)ImColor(0.0f, 1.0f, 0.0f),
"Success!");
841 ImGui::TextColored((ImVec4)ImColor(1.0f, 0.0f, 0.0f),
"Failure!");
853 const auto &tsrs =
tsrs_->getTSRs();
856 const auto &tsr = tsrs[i];
857 const auto &spec = tsr->getSpecification();
859 const std::string title =
"B:" + spec.base.frame +
":" + spec.base.structure +
860 " > T:" + spec.target.frame +
":" + spec.target.structure;
862 if (ImGui::TreeNodeEx(title.
c_str(), ImGuiTreeNodeFlags_DefaultOpen))
865 ImGui::Text(
"Pos. Error");
871 ImGui::Text(
"Rot. Error");
889 Eigen::VectorXd world(
tsrs_->getWorldIndices().size());
890 tsrs_->getPositionsWorldState(world);
899 auto time = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
906 const auto &tsrs =
tsrs_->getTSRs();
908 for (
const auto &tsr : tsrs)
911 (tsr->getNumWorldDofs()) ? tsr->getWorldIndices() : tsr->computeWorldIndices();
913 for (
const auto &index : wts)
919 for (
const auto &index : wis)
922 tsrs_->useWorldIndices(wts);
923 tsrs_->setWorldIndices(wts);
924 tsrs_->computeLimits();
948 errors_[i].xpd.color = Eigen::Vector3d(1, 0, 0);
949 errors_[i].ypd.color = Eigen::Vector3d(0, 1, 0);
950 errors_[i].zpd.color = Eigen::Vector3d(0, 0, 1);
953 errors_[i].xrd.color = Eigen::Vector3d(1, 0, 0);
955 errors_[i].yrd.color = Eigen::Vector3d(0, 1, 0);
957 errors_[i].zrd.color = Eigen::Vector3d(0, 0, 1);
968 const auto &tsrs =
tsrs_->getTSRs();
971 Eigen::VectorXd e = Eigen::VectorXd::Zero(6);
972 tsrs[i]->getErrorWorldRaw(e);
CheckboxElement(const std::string &text, bool &boolean)
Constructor.
const std::string text
Display text.
void render() const override
Render method. Renders IMGUI contents.
A shared pointer wrapper for robowflex::darts::WindowWidget::Element.
float minimum() const
Compute the minimum over the data.
bool show_avg
Display average value under plot.
std::vector< float > elements
All data points.
std::string units
Plot Units.
Eigen::Vector3d color
Color of plot.
std::size_t index
Index in data.
float latest
Last input data point.
float average() const
Compute the average over the data.
float maximum() const
Compute the maximum over the data.
void render() const override
Render method. Renders IMGUI contents.
bool show_min
Display minimum value under plot.
void addPoint(float x)
Add a point to the plot data.
std::size_t total_elements
Total elements inserted in data.
std::size_t max_size
Maximum size of plot data.
std::string label
Plot Label.
bool show_max
Display maximum value under plot.
A helper class to setup common OMPL structures for planning.
StateSpacePtr rspace
Underlying Robot State Space.
ompl::base::SpaceInformationPtr rinfo
Underlying Space Information.
RenderElement(const RenderCallback &callback)
Constructor.
const RenderCallback callback
Callback.
void render() const override
Render method. Renders IMGUI contents.
A shared pointer wrapper for robowflex::darts::StateSpace.
A shared pointer wrapper for robowflex::darts::TSR.
A shared pointer wrapper for robowflex::darts::TSRSet.
Manager for a set of TSR constraints. Attempts to reduce redundancy and combines errors and Jacobians...
The specification of a TSR.
Eigen::Vector3d lower
Lower position tolerance.
std::string structure
Structure target frame is in.
void setZRotTolerance(double bound)
Set the Z orientation tolerance to (-bound, bound).
void setRotation(const Eigen::Quaterniond &orientation)
Set the rotation of the TSR.
std::string frame
Name of target frame.
void setYPosTolerance(double bound)
Set the Y position tolerance to (-bound, bound).
Eigen::Quaterniond getRotation() const
Get the current desired orientation.
RobotPose pose
Pose of TSR.
void print(std::ostream &out) const
Print out this TSR information.
void setYRotTolerance(double bound)
Set the Y orientation tolerance to (-bound, bound).
Eigen::Vector3d getEulerRotation() const
Get the current desired orientation.
struct robowflex::darts::TSR::Specification::@5 position
Position tolerances.
struct robowflex::darts::TSR::Specification::@6 orientation
Orientation tolerances.
ROBOWFLEX_EIGEN Eigen::Vector3d upper
Upper position tolerance.
void setXPosTolerance(double bound)
Setting Position Tolerances.
void setZPosTolerance(double bound)
Set the Z position tolerance to (-bound, bound).
void setXRotTolerance(double bound)
Setting Orientation Tolerances.
Eigen::Vector3d getPosition() const
Getters and Informative Methods.
void setPosition(const Eigen::Ref< const Eigen::Vector3d > &position)
Setting TSR Pose.
struct robowflex::darts::TSR::Specification::@4 base
Base frame.
TextElement(const std::string &text)
Constructor.
void render() const override
Render method. Renders IMGUI contents.
const std::string text
Text to display.
Viewer(const WorldPtr &world)
Constructor.
void updateTraversal() override
Open Scene Graph GUI for DART visualization.
WindowWidgetPtr widget_
IMGUI widget.
WorldPtr getWorld()
Get world used for visualization.
WindowWidgetPtr getWidget()
Get the IMGUI configurable widget.
Window(const WorldPtr &world)
Constructor.
void run(std::function< void()> thread={})
Run the GUI. Blocks.
void animatePath(const StateSpacePtr &space, const ompl::geometric::PathGeometric &path, std::size_t times=1, double fps=60, bool block=true)
Animate a motion plan using the world.
std::shared_ptr< std::thread > animation_
Animation thread.
std::vector< WidgetPtr > widgets_
Other widgets;.
::osg::ref_ptr< Window > node_
OSG Node.
void addWidget(const WidgetPtr &widget)
Add a new IMGUI widget.
WorldPtr world_
World to visualize.
InteractiveReturn createInteractiveMarker(const InteractiveOptions &options)
Create a new interactive marker in the GUI.
void customPreRefresh() override
const WorldPtr & getWorldConst() const
Get world used for visualization.
void customPostRefresh() override
DnDReturn enableNodeDragNDrop(dart::dynamics::BodyNode *node, const DnDCallback &callback={})
Enable drag 'n drop functionality on a body node being visualized. With DnD, the body node will autom...
A shared pointer wrapper for robowflex::darts::World.
T emplace_back(T... args)
static const double half_pi
static const std::string ROOT_FRAME
DART-based robot modeling and planning.
std::shared_ptr< dart::dynamics::MeshShape > makeArcsegment(double low, double high, double inner_radius, double outer_radius, std::size_t resolution=32)
Create a circle's arcsector from one angle to another, with a specified radius.
std::string generateUUID()
Generate a unique identifier.
std::shared_ptr< dart::dynamics::BoxShape > makeBox(const Eigen::Ref< const Eigen::Vector3d > &v)
Create a box.
Return from creating a movable frame.
dart::gui::osg::BodyNodeDnD * dnd
Drag 'n Drop object.
dart::common::Connection signal
Connection from motion to callback.
Options for creating an interactive marker.
void disableControls()
Disables all controls.
std::string name
Name of marker.
bool rotation[3]
Rotation ring controls enabled.
void disableRotationControls()
Disables all rotation controls.
bool obstructable
Is this frame obstructable?
void disableLinearControls()
Disables all linear controls.
Eigen::Isometry3d pose
Relative pose of marker.
InteractiveCallback callback
Callback function on motion.
double size
Size of marker.
double thickness
Thickness of marker arrows.
bool linear[3]
Linear position controls enabled.
bool planar[3]
Planar translation controls enabled.
void disablePlanarControls()
Disables all planar controls.
dart::dynamics::Frame * parent
Parent frame.
Return from creating an interactive marker.
dart::gui::osg::InteractiveFrameDnD * dnd
Drag 'n Drop object.
dart::common::Connection signal
Connection from motion to callback.
dart::gui::osg::InteractiveFramePtr target
Interactive Frame generated.
void callback(movegroup::MoveGroupHelper::Action &action)