Robowflex  v0.1
Making MoveIt Easy
robowflex::darts::TSRSolveWidget Class Reference

Class for solving a set of TSRs. More...

#include <gui.h>

+ Inheritance diagram for robowflex::darts::TSRSolveWidget:

Classes

struct  ErrorLines
 Error plots for TSRs. More...
 

Public Member Functions

 TSRSolveWidget (const WorldPtr &world, const std::vector< TSRPtr > &tsrs)
 Constructor. More...
 
 TSRSolveWidget (const TSRSetPtr &tsrs)
 Constructor. More...
 
void initialize (Window *window) override
 Initialization with window context. More...
 
void prerefresh () override
 Called before window refresh. More...
 
void render () override
 Render GUI. More...
 
void solve ()
 Solve for a solution to the current TSR. More...
 

Private Attributes

TSRSetPtr tsrs_
 TSR set. More...
 
GUI Values
const float max_tolerance_ {0.1f}
 Max tolerance value. More...
 
const int max_iteration_ {200}
 Max iteration value. More...
 
const float drag_tolerance_ {0.01f}
 Slider drag for tolerance. More...
 
bool track_tsr_ {false}
 Track the TSR by solving IK. More...
 
bool use_gradient_ {false}
 Use gradient solving instead of built-in. More...
 
bool need_solve_ {false}
 A solve is requested. More...
 
float step_
 GUI gradient step size. More...
 
float limit_
 GUI gradient limit. More...
 
float damping_
 GUI SVD damping. More...
 
float tolerance_
 GUI solver tolerance. More...
 
int maxIter_
 GUI maximum allowed iterations. More...
 
int item_ {0}
 GUI solver. More...
 
GUI Plots
bool last_solve_ {false}
 Result of last TSR solve. More...
 
LinePlotElement solve_time_
 Plot of TSR solve times. More...
 
std::vector< ErrorLineserrors_
 

Detailed Description

Class for solving a set of TSRs.

Definition at line 555 of file gui.h.

Constructor & Destructor Documentation

◆ TSRSolveWidget() [1/2]

TSRSolveWidget::TSRSolveWidget ( const WorldPtr world,
const std::vector< TSRPtr > &  tsrs 
)

Constructor.

Parameters
[in]worldWorld to use.
[in]tsrsSet of TSRs to consider.

Definition at line 765 of file gui.cpp.

766  : TSRSolveWidget(std::make_shared<TSRSet>(world, tsrs, false))
767 {
768 }
TSRSolveWidget(const WorldPtr &world, const std::vector< TSRPtr > &tsrs)
Constructor.
Definition: gui.cpp:765

◆ TSRSolveWidget() [2/2]

TSRSolveWidget::TSRSolveWidget ( const TSRSetPtr tsrs)

Constructor.

Parameters
[in]tsrsSet of TSRs to consider.

Definition at line 770 of file gui.cpp.

770  : tsrs_(tsrs)
771 {
772 }
TSRSetPtr tsrs_
TSR set.
Definition: gui.h:581

Member Function Documentation

◆ initialize()

void TSRSolveWidget::initialize ( Window window)
overridevirtual

Initialization with window context.

Parameters
[in]windowGUI window.

Reimplemented from robowflex::darts::Widget.

Definition at line 903 of file gui.cpp.

904 {
905  // Compute world indices for all TSRs
906  const auto &tsrs = tsrs_->getTSRs();
908  for (const auto &tsr : tsrs)
909  {
911  (tsr->getNumWorldDofs()) ? tsr->getWorldIndices() : tsr->computeWorldIndices();
912 
913  for (const auto &index : wts)
914  wis.emplace(index);
915  }
916 
918  wts.reserve(wis.size());
919  for (const auto &index : wis)
920  wts.emplace_back(index);
921 
922  tsrs_->useWorldIndices(wts);
923  tsrs_->setWorldIndices(wts);
924  tsrs_->computeLimits();
925 
926  tsrs_->initialize();
927 
928  // Setup solve parameters.
929  maxIter_ = tsrs_->getMaxIterations();
930  tolerance_ = tsrs_->getTolerance();
931  step_ = tsrs_->getStep();
932  limit_ = tsrs_->getLimit();
933  damping_ = tsrs_->getDamping();
934 
935  // Setup solve time plots.
936  solve_time_.label = "Solve Time";
937  solve_time_.units = "microsec.";
938  solve_time_.show_min = true;
939  solve_time_.show_max = true;
940  solve_time_.show_avg = true;
941 
942  // Setup error plots.
943  const std::size_t n = tsrs_->numTSRs();
944  errors_.resize(n);
945 
946  for (std::size_t i = 0; i < n; ++i)
947  {
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);
951 
952  errors_[i].xrd.label = "X";
953  errors_[i].xrd.color = Eigen::Vector3d(1, 0, 0);
954  errors_[i].yrd.label = "Y";
955  errors_[i].yrd.color = Eigen::Vector3d(0, 1, 0);
956  errors_[i].zrd.label = "Z";
957  errors_[i].zrd.color = Eigen::Vector3d(0, 0, 1);
958  }
959 }
bool show_avg
Display average value under plot.
Definition: gui.h:333
std::string units
Plot Units.
Definition: gui.h:330
bool show_min
Display minimum value under plot.
Definition: gui.h:331
std::string label
Plot Label.
Definition: gui.h:329
bool show_max
Display maximum value under plot.
Definition: gui.h:332
float step_
GUI gradient step size.
Definition: gui.h:594
float damping_
GUI SVD damping.
Definition: gui.h:596
LinePlotElement solve_time_
Plot of TSR solve times.
Definition: gui.h:607
int maxIter_
GUI maximum allowed iterations.
Definition: gui.h:598
float limit_
GUI gradient limit.
Definition: gui.h:595
std::vector< ErrorLines > errors_
Definition: gui.h:621
float tolerance_
GUI solver tolerance.
Definition: gui.h:597
T emplace(T... args)
T reserve(T... args)
T size(T... args)

◆ prerefresh()

void TSRSolveWidget::prerefresh ( )
overridevirtual

Called before window refresh.

Reimplemented from robowflex::darts::Widget.

Definition at line 961 of file gui.cpp.

962 {
963  if (track_tsr_ or need_solve_)
964  solve();
965 
966  need_solve_ = false;
967 
968  const auto &tsrs = tsrs_->getTSRs();
969  for (std::size_t i = 0; i < tsrs.size(); ++i)
970  {
971  Eigen::VectorXd e = Eigen::VectorXd::Zero(6);
972  tsrs[i]->getErrorWorldRaw(e);
973 
974  errors_[i].xrd.addPoint(e[0]);
975  errors_[i].yrd.addPoint(e[1]);
976  errors_[i].zrd.addPoint(e[2]);
977  errors_[i].xpd.addPoint(e[3]);
978  errors_[i].ypd.addPoint(e[4]);
979  errors_[i].zpd.addPoint(e[5]);
980  }
981 }
bool need_solve_
A solve is requested.
Definition: gui.h:592
void solve()
Solve for a solution to the current TSR.
Definition: gui.cpp:883
bool track_tsr_
Track the TSR by solving IK.
Definition: gui.h:590

◆ render()

void TSRSolveWidget::render ( )
override

Render GUI.

Definition at line 774 of file gui.cpp.

775 {
776  // Draw main window.
777  ImGui::SetNextWindowBgAlpha(0.5f);
778  std::string title = "TSR Solver";
779  if (!ImGui::Begin(title.c_str(), nullptr, ImGuiWindowFlags_HorizontalScrollbar))
780  {
781  ImGui::End();
782  return;
783  }
784 
785  // Draw TSR solve interface.
786  if (ImGui::TreeNodeEx("Solving", ImGuiTreeNodeFlags_DefaultOpen))
787  {
788  ImGui::Checkbox("Track TSR", &track_tsr_);
789  ImGui::SameLine();
790  ImGui::Checkbox("Use Gradient?", &use_gradient_);
791 
792  ImGui::Columns(2);
793  if (ImGui::SliderInt("Max Iter.", &maxIter_, 1, max_iteration_))
794  {
795  tsrs_->setMaxIterations(maxIter_);
796  tsrs_->updateSolver();
797  }
798  if (ImGui::SliderFloat("Step", &step_, 0.001f, 1.f))
799  tsrs_->setStep(step_);
800 
801  if (ImGui::SliderFloat("Limit", &limit_, 0.001f, 1.f))
802  tsrs_->setLimit(limit_);
803 
804  ImGui::NextColumn();
805  if (ImGui::SliderFloat("Tol.", &tolerance_, 1e-5f, max_tolerance_, "< %.5f", 3.f))
806  {
807  tsrs_->setMaxIterations(tolerance_);
808  tsrs_->updateSolver();
809  }
810 
811  const char *items[] = {"dSVD", "SVD", "QR"};
812  if (ImGui::Combo("combo", &item_, items, IM_ARRAYSIZE(items)))
813  {
814  if (item_ == 0)
815  {
816  tsrs_->useSVD();
817  tsrs_->useDamping(true);
818  }
819  else if (item_ == 1)
820  {
821  tsrs_->useSVD();
822  tsrs_->useDamping(false);
823  }
824  else
825  tsrs_->useQR();
826  }
827 
828  if (ImGui::SliderFloat("Damp.", &damping_, 1e-8f, 1e-3f, "< %.8f", 10.f))
829  tsrs_->setDamping(damping_);
830 
831  ImGui::Columns(1);
832 
833  if (ImGui::Button("Solve TSR"))
834  need_solve_ = true;
835 
836  ImGui::SameLine();
837 
838  if (last_solve_)
839  ImGui::TextColored((ImVec4)ImColor(0.0f, 1.0f, 0.0f), "Success!");
840  else
841  ImGui::TextColored((ImVec4)ImColor(1.0f, 0.0f, 0.0f), "Failure!");
842 
844 
845  ImGui::TreePop();
846  }
847 
848  ImGui::Separator();
849  ImGui::Spacing();
850 
851  // Draw distance tracking information.
852 
853  const auto &tsrs = tsrs_->getTSRs();
854  for (std::size_t i = 0; i < tsrs.size(); ++i)
855  {
856  const auto &tsr = tsrs[i];
857  const auto &spec = tsr->getSpecification();
858 
859  const std::string title = "B:" + spec.base.frame + ":" + spec.base.structure + //
860  " > T:" + spec.target.frame + ":" + spec.target.structure;
861 
862  if (ImGui::TreeNodeEx(title.c_str(), ImGuiTreeNodeFlags_DefaultOpen))
863  {
864  ImGui::Columns(2);
865  ImGui::Text("Pos. Error");
866  errors_[i].xpd.render();
867  errors_[i].ypd.render();
868  errors_[i].zpd.render();
869  ImGui::NextColumn();
870 
871  ImGui::Text("Rot. Error");
872  errors_[i].xrd.render();
873  errors_[i].yrd.render();
874  errors_[i].zrd.render();
875 
876  ImGui::Columns(1);
877 
878  ImGui::TreePop();
879  }
880  }
881 }
T c_str(T... args)
void render() const override
Render method. Renders IMGUI contents.
Definition: gui.cpp:339
bool use_gradient_
Use gradient solving instead of built-in.
Definition: gui.h:591
const float max_tolerance_
Max tolerance value.
Definition: gui.h:586
int item_
GUI solver.
Definition: gui.h:599
const int max_iteration_
Max iteration value.
Definition: gui.h:587
bool last_solve_
Result of last TSR solve.
Definition: gui.h:606

◆ solve()

void TSRSolveWidget::solve ( )

Solve for a solution to the current TSR.

Definition at line 883 of file gui.cpp.

884 {
885  auto start = std::chrono::steady_clock::now();
886 
887  if (use_gradient_)
888  {
889  Eigen::VectorXd world(tsrs_->getWorldIndices().size());
890  tsrs_->getPositionsWorldState(world);
891 
892  last_solve_ = tsrs_->solveGradientWorldState(world);
893  }
894  else
895  last_solve_ = tsrs_->solveWorld();
896 
898 
899  auto time = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
900  solve_time_.addPoint(time);
901 }
void addPoint(float x)
Add a point to the plot data.
Definition: gui.cpp:323
T end(T... args)
T time(T... args)

Member Data Documentation

◆ damping_

float robowflex::darts::TSRSolveWidget::damping_
private

GUI SVD damping.

Definition at line 596 of file gui.h.

◆ drag_tolerance_

const float robowflex::darts::TSRSolveWidget::drag_tolerance_ {0.01f}
private

Slider drag for tolerance.

Definition at line 588 of file gui.h.

◆ errors_

std::vector<ErrorLines> robowflex::darts::TSRSolveWidget::errors_
private

Definition at line 621 of file gui.h.

◆ item_

int robowflex::darts::TSRSolveWidget::item_ {0}
private

GUI solver.

Definition at line 599 of file gui.h.

◆ last_solve_

bool robowflex::darts::TSRSolveWidget::last_solve_ {false}
private

Result of last TSR solve.

Definition at line 606 of file gui.h.

◆ limit_

float robowflex::darts::TSRSolveWidget::limit_
private

GUI gradient limit.

Definition at line 595 of file gui.h.

◆ max_iteration_

const int robowflex::darts::TSRSolveWidget::max_iteration_ {200}
private

Max iteration value.

Definition at line 587 of file gui.h.

◆ max_tolerance_

const float robowflex::darts::TSRSolveWidget::max_tolerance_ {0.1f}
private

Max tolerance value.

Definition at line 586 of file gui.h.

◆ maxIter_

int robowflex::darts::TSRSolveWidget::maxIter_
private

GUI maximum allowed iterations.

Definition at line 598 of file gui.h.

◆ need_solve_

bool robowflex::darts::TSRSolveWidget::need_solve_ {false}
private

A solve is requested.

Definition at line 592 of file gui.h.

◆ solve_time_

LinePlotElement robowflex::darts::TSRSolveWidget::solve_time_
private

Plot of TSR solve times.

Definition at line 607 of file gui.h.

◆ step_

float robowflex::darts::TSRSolveWidget::step_
private

GUI gradient step size.

Definition at line 594 of file gui.h.

◆ tolerance_

float robowflex::darts::TSRSolveWidget::tolerance_
private

GUI solver tolerance.

Definition at line 597 of file gui.h.

◆ track_tsr_

bool robowflex::darts::TSRSolveWidget::track_tsr_ {false}
private

Track the TSR by solving IK.

Definition at line 590 of file gui.h.

◆ tsrs_

TSRSetPtr robowflex::darts::TSRSolveWidget::tsrs_
private

TSR set.

Definition at line 581 of file gui.h.

◆ use_gradient_

bool robowflex::darts::TSRSolveWidget::use_gradient_ {false}
private

Use gradient solving instead of built-in.

Definition at line 591 of file gui.h.


The documentation for this class was generated from the following files: