Skip to content

Commit 718ad32

Browse files
committed
cartesian demo: illustrate merging of trajectories
1 parent 8debe68 commit 718ad32

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

demo/src/cartesian.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,12 @@ Task createTask() {
5151
t.stages()->setName("Cartesian Path");
5252

5353
const std::string group = "panda_arm";
54+
const std::string eef = "hand";
5455

55-
// create Cartesian interpolation "planner" to be used in stages
56-
auto cartesian = std::make_shared<solvers::CartesianPath>();
56+
// create Cartesian interpolation "planner" to be used in various stages
57+
auto cartesian_interpolation = std::make_shared<solvers::CartesianPath>();
58+
// create a joint-space interpolation "planner" to be used in various stages
59+
auto joint_interpolation = std::make_shared<solvers::JointInterpolationPlanner>();
5760

5861
// start from a fixed robot state
5962
t.loadRobotModel();
@@ -68,7 +71,7 @@ Task createTask() {
6871
}
6972

7073
{
71-
auto stage = std::make_unique<stages::MoveRelative>("x +0.2", cartesian);
74+
auto stage = std::make_unique<stages::MoveRelative>("x +0.2", cartesian_interpolation);
7275
stage->setGroup(group);
7376
geometry_msgs::Vector3Stamped direction;
7477
direction.header.frame_id = "world";
@@ -78,7 +81,7 @@ Task createTask() {
7881
}
7982

8083
{
81-
auto stage = std::make_unique<stages::MoveRelative>("y -0.3", cartesian);
84+
auto stage = std::make_unique<stages::MoveRelative>("y -0.3", cartesian_interpolation);
8285
stage->setGroup(group);
8386
geometry_msgs::Vector3Stamped direction;
8487
direction.header.frame_id = "world";
@@ -88,7 +91,7 @@ Task createTask() {
8891
}
8992

9093
{ // rotate about TCP
91-
auto stage = std::make_unique<stages::MoveRelative>("rz +45°", cartesian);
94+
auto stage = std::make_unique<stages::MoveRelative>("rz +45°", cartesian_interpolation);
9295
stage->setGroup(group);
9396
geometry_msgs::TwistStamped twist;
9497
twist.header.frame_id = "world";
@@ -98,16 +101,23 @@ Task createTask() {
98101
}
99102

100103
{ // perform a Cartesian motion, defined as a relative offset in joint space
101-
auto stage = std::make_unique<stages::MoveRelative>("joint offset", cartesian);
104+
auto stage = std::make_unique<stages::MoveRelative>("joint offset", cartesian_interpolation);
102105
stage->setGroup(group);
103106
std::map<std::string, double> offsets = { { "panda_joint1", M_PI / 6. }, { "panda_joint3", -M_PI / 6 } };
104107
stage->setDirection(offsets);
105108
t.add(std::move(stage));
106109
}
107110

111+
{ // move gripper into predefined open state
112+
auto stage = std::make_unique<stages::MoveTo>("open gripper", joint_interpolation);
113+
stage->setGroup(eef);
114+
stage->setGoal("open");
115+
t.add(std::move(stage));
116+
}
117+
108118
{ // move from reached state back to the original state, using joint interpolation
109-
auto joint_interpolation = std::make_shared<solvers::JointInterpolationPlanner>();
110-
stages::Connect::GroupPlannerVector planners = { { group, joint_interpolation } };
119+
// specifying two groups (arm and hand) will try to merge both trajectories
120+
stages::Connect::GroupPlannerVector planners = { { group, joint_interpolation }, { eef, joint_interpolation } };
111121
auto connect = std::make_unique<stages::Connect>("connect", planners);
112122
t.add(std::move(connect));
113123
}

0 commit comments

Comments
 (0)