Robowflex  v0.1
Making MoveIt Easy
gui_test.cpp File Reference
#include <chrono>
#include <thread>
#include <robowflex_dart/gui.h>
#include <robowflex_dart/io.h>
#include <robowflex_dart/robot.h>
#include <robowflex_dart/space.h>
#include <robowflex_dart/tsr.h>
#include <robowflex_dart/world.h>

Go to the source code of this file.

Functions

int main (int, char **)
 

Function Documentation

◆ main()

int main ( int  ,
char **   
)

Definition at line 15 of file gui_test.cpp.

16 {
17  bool ik = true;
18 
19  auto world = std::make_shared<darts::World>();
20 
21  auto fetch1 = darts::loadMoveItRobot("fetch1", //
22  "package://fetch_description/robots/fetch.urdf", //
23  "package://fetch_moveit_config/config/fetch.srdf");
24  auto start = fetch1->getSkeleton()->getState();
25 
26  auto scene = std::make_shared<darts::Structure>("object");
27 
28  dart::dynamics::FreeJoint::Properties joint;
29  joint.mName = "box";
30  joint.mT_ParentBodyToJoint.translation() = Eigen::Vector3d(0.5, 0, 0.3);
31  scene->addFreeFrame(joint, darts::makeBox(0.05, 0.05, 0.1));
32 
33  world->addRobot(fetch1);
34  world->addStructure(scene);
35 
36  darts::Window window(world);
37 
38  //
39  // Setup End-Effector IK
40  //
42  ik_spec.setFrame("fetch1", "wrist_roll_link");
43  auto ik_tsr = std::make_shared<darts::TSR>(world, ik_spec);
44  ik_tsr->useGroup("arm_with_torso");
45  ik_tsr->initialize();
46 
48  options_ik.name = "arm_ik";
49  options_ik.size = 0.4;
50  options_ik.thickness = 1;
51  options_ik.pose = fetch1->getFrame("wrist_roll_link")->getWorldTransform();
52 
53  options_ik.callback = [&](const auto &frame) {
54  auto &spec = ik_tsr->getSpecification();
55  spec.setPose(frame->getWorldTransform());
56  ik_tsr->updatePose();
57 
58  if (ik)
59  ik_tsr->solveWorld();
60  };
61 
62  auto ik_ret = window.createInteractiveMarker(options_ik);
63 
64  //
65  // Setup Head-Look IK
66  //
67  darts::TSR::Specification look_spec;
68  look_spec.setFrame("fetch1", "head_camera_link");
69  auto look_tsr = std::make_shared<darts::TSR>(world, look_spec);
70  look_tsr->initialize();
71 
73  options_look.name = "head_look";
74  options_look.pose = fetch1->getFrame("head_camera_link")->getWorldTransform();
75  options_look.pose.translation()[1] += 0.5;
76 
77  options_look.linear[0] = false; // disable linear control
78  options_look.linear[1] = false;
79  options_look.linear[2] = false;
80  options_look.rotation[0] = false; // no roll
81  options_look.planar[0] = false; // disable planar control
82  options_look.planar[1] = false;
83  options_look.planar[2] = false;
84 
85  options_look.callback = [&](const auto &frame) {
86  auto &spec = look_tsr->getSpecification();
87  spec.setPose(frame->getWorldTransform());
88  look_tsr->updatePose();
89 
90  if (ik)
91  look_tsr->solveWorld();
92  };
93 
94  auto look_ret = window.createInteractiveMarker(options_look);
95 
96  // Enable/Disable IK
97  window.getWidget()->addCheckbox("Enable IK", ik);
98 
99  // Pick / Place Button
100  bool picked = false;
101  auto *cube = scene->getFrame("box");
102  window.getWidget()->addButton("Pick/Place", [&] {
103  if (not picked)
104  fetch1->reparentFreeFrame(cube, "wrist_roll_link");
105  else
106  scene->reparentFreeFrame(cube);
107 
108  picked = not picked;
109  });
110 
111  // Setup reset button
112  window.getWidget()->addText("Press button to reset robot state!");
113  window.getWidget()->addButton("Reset", [&] {
114  // do it a few times since the IK tries to update
115  for (std::size_t i = 0; i < 3; ++i)
116  {
117  fetch1->getSkeleton()->setState(start);
118  ik_ret.target->setTransform(fetch1->getFrame("wrist_roll_link")->getWorldTransform());
119  auto tf = fetch1->getFrame("head_camera_link")->getWorldTransform();
120  tf.translation()[1] += 0.5;
121  look_ret.target->setTransform(tf);
122  }
123  });
124 
125  window.run();
126  return 0;
127 }
The specification of a TSR.
Definition: tsr.h:70
void setFrame(const std::string &structure, const std::string &target, const std::string &base=magic::ROOT_FRAME)
Set the base and target frame.
Definition: tsr.cpp:48
Open Scene Graph GUI for DART visualization.
Definition: gui.h:67
RobotPtr loadMoveItRobot(const std::string &name, const std::string &urdf, const std::string &srdf)
Load a robot from a URDF and SRDF (i.e., a MoveIt enabled robot).
std::shared_ptr< dart::dynamics::BoxShape > makeBox(const Eigen::Ref< const Eigen::Vector3d > &v)
Create a box.
Definition: structure.cpp:370
Functions for loading and animating scenes in Blender.
Options for creating an interactive marker.
Definition: gui.h:88
std::string name
Name of marker.
Definition: gui.h:89
bool rotation[3]
Rotation ring controls enabled.
Definition: gui.h:98
Eigen::Isometry3d pose
Relative pose of marker.
Definition: gui.h:90
InteractiveCallback callback
Callback function on motion.
Definition: gui.h:91
double thickness
Thickness of marker arrows.
Definition: gui.h:94
bool linear[3]
Linear position controls enabled.
Definition: gui.h:97
bool planar[3]
Planar translation controls enabled.
Definition: gui.h:99