-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathfetch_bimanual.cpp
More file actions
151 lines (121 loc) · 4.63 KB
/
fetch_bimanual.cpp
File metadata and controls
151 lines (121 loc) · 4.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/* Author: Zachary Kingston */
#include <chrono>
#include <thread>
#include <robowflex_library/log.h>
#include <robowflex_dart/gui.h>
#include <robowflex_dart/io.h>
#include <robowflex_dart/planning.h>
#include <robowflex_dart/robot.h>
#include <robowflex_dart/space.h>
#include <robowflex_dart/tsr.h>
#include <robowflex_dart/world.h>
#include <ompl/geometric/SimpleSetup.h>
#include <ompl/geometric/planners/rrt/RRTConnect.h>
using namespace robowflex;
int main(int /*argc*/, char ** /*argv*/)
{
//
// Load and setup the fetch
//
auto world = std::make_shared<darts::World>();
auto fetch1 = darts::loadMoveItRobot("fetch1", //
"package://fetch_description/robots/fetch.urdf", //
"package://fetch_moveit_config/config/fetch.srdf");
auto fetch2 = fetch1->cloneRobot("fetch2");
fetch2->setDof(4, 1);
world->addRobot(fetch1);
world->addRobot(fetch2);
darts::Window window(world);
//
// Initial goal - touch fingertips
//
const auto &touch = [&]
{
darts::PlanBuilder builder(world);
builder.addGroup("fetch1", "arm_with_torso");
builder.addGroup("fetch2", "arm_with_torso");
builder.setStartConfiguration({
0.05, 1.32, 1.40, -0.2, 1.72, 0.0, 1.66, 0.0, //
0.05, 1.32, 1.40, -0.2, 1.72, 0.0, 1.66, 0.0, //
});
builder.initialize();
darts::TSR::Specification goal1_spec;
goal1_spec.setFrame("fetch1", "wrist_roll_link", "base_link");
goal1_spec.setPose(0.4, 0.3, 0.92, //
// 0.5, -0.5, 0.5, 0.5);
0.707, 0, 0, 0.707);
darts::TSR::Specification goal2_spec;
goal2_spec.setFrame("fetch2", "wrist_roll_link", "base_link");
goal2_spec.setPose(0.4, -0.3, 0.92, //
0.707, 0, 0, -0.707);
auto goal1_tsr = std::make_shared<darts::TSR>(world, goal1_spec);
auto goal2_tsr = std::make_shared<darts::TSR>(world, goal2_spec);
auto goal = builder.getGoalTSR({goal1_tsr, goal2_tsr});
builder.setGoal(goal);
auto rrt = std::make_shared<ompl::geometric::RRTConnect>(builder.info, true);
rrt->setRange(1.);
builder.ss->setPlanner(rrt);
builder.setup();
goal->startSampling();
ompl::base::PlannerStatus solved = builder.ss->solve(30.0);
goal->stopSampling();
if (solved)
{
RBX_INFO("Found solution!");
window.animatePath(builder, builder.getSolutionPath());
}
else
RBX_WARN("No solution found");
return solved;
};
const auto &dance = [&]
{
darts::PlanBuilder builder(world);
builder.addGroup("fetch1", "arm_with_torso");
builder.addGroup("fetch2", "arm_with_torso");
builder.setStartConfigurationFromWorld();
darts::TSR::Specification constraint_spec;
constraint_spec.setTarget("fetch2", "wrist_roll_link");
constraint_spec.setBase("fetch1", "wrist_roll_link");
constraint_spec.setPoseFromWorld(world);
auto constraint_tsr = std::make_shared<darts::TSR>(world, constraint_spec);
builder.addConstraint(constraint_tsr);
// builder.options.constraints.delta = 0.1;
builder.initialize();
darts::TSR::Specification goal_spec;
goal_spec.setFrame("fetch1", "wrist_roll_link", "base_link");
goal_spec.setPose(0.6, 0.3, 0.42, //
0.707, 0, 0, 0.707);
auto goal_tsr = std::make_shared<darts::TSR>(world, goal_spec);
auto goal = builder.getGoalTSR(goal_tsr);
builder.setGoal(goal);
auto rrt = std::make_shared<ompl::geometric::RRTConnect>(builder.info, true);
rrt->setRange(100.);
builder.ss->setPlanner(rrt);
builder.setup();
goal->startSampling();
ompl::base::PlannerStatus solved = builder.ss->solve(30.0);
goal->stopSampling();
if (solved)
{
RBX_INFO("Found solution!");
window.animatePath(builder, builder.getSolutionPath());
}
else
RBX_WARN("No solution found");
return solved;
};
window.run(
[&]()
{
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
while (true)
{
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
auto solved = touch();
if (solved)
dance();
}
});
return 0;
}