Skip to content

Commit 499fcfb

Browse files
committed
cleanup / renaming
* Rename pruneInterface() -> resolveInterface() * Rename accepted (interface) -> expected * Improve exception strings
1 parent aa732d8 commit 499fcfb

File tree

11 files changed

+251
-47
lines changed

11 files changed

+251
-47
lines changed

core/include/moveit/task_constructor/container_p.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class ContainerBasePrivate : public StagePrivate
106106
void validateConnectivity() const override;
107107

108108
// Containers derive their required interface from their children
109-
// UNKNOWN until pruneInterface was called
109+
// UNKNOWN until resolveInterface was called
110110
InterfaceFlags requiredInterface() const override { return required_interface_; }
111111

112112
// forward these methods to the public interface for containers
@@ -139,7 +139,7 @@ class ContainerBasePrivate : public StagePrivate
139139
auto& internalToExternalMap() { return internal_to_external_; }
140140
const auto& internalToExternalMap() const { return internal_to_external_; }
141141

142-
// set in pruneInterface()
142+
// set in resolveInterface()
143143
InterfaceFlags required_interface_;
144144

145145
private:
@@ -170,7 +170,7 @@ class SerialContainerPrivate : public ContainerBasePrivate
170170
SerialContainerPrivate(SerialContainer* me, const std::string& name);
171171

172172
// called by parent asking for pruning of this' interface
173-
void pruneInterface(InterfaceFlags accepted) override;
173+
void resolveInterface(InterfaceFlags expected) override;
174174
// validate connectivity of chain
175175
void validateConnectivity() const override;
176176

@@ -215,7 +215,7 @@ class ParallelContainerBasePrivate : public ContainerBasePrivate
215215
ParallelContainerBasePrivate(ParallelContainerBase* me, const std::string& name);
216216

217217
// called by parent asking for pruning of this' interface
218-
void pruneInterface(InterfaceFlags accepted) override;
218+
void resolveInterface(InterfaceFlags expected) override;
219219

220220
void validateConnectivity() const override;
221221

@@ -251,7 +251,7 @@ class MergerPrivate : public ParallelContainerBasePrivate
251251
typedef std::function<void(SubTrajectory&&)> Spawner;
252252
MergerPrivate(Merger* me, const std::string& name);
253253

254-
void pruneInterface(InterfaceFlags accepted) override;
254+
void resolveInterface(InterfaceFlags expected) override;
255255

256256
void onNewPropagateSolution(const SolutionBase& s);
257257
void onNewGeneratorSolution(const SolutionBase& s);

core/include/moveit/task_constructor/stage_p.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,11 @@ class StagePrivate
7171
/// actually configured interface of this stage (only valid after init())
7272
InterfaceFlags interfaceFlags() const;
7373

74-
/** Interface required by this stage
75-
*
76-
* If the interface is unknown (because it is auto-detected from context), return UNKNOWN */
74+
/// Retrieve interface required by this stage, UNKNOWN if auto-detected from context
7775
virtual InterfaceFlags requiredInterface() const = 0;
7876

79-
/** Prune interface to comply with the given propagation direction
80-
*
81-
* PropagatingEitherWay uses this in restrictDirection() */
82-
virtual void pruneInterface(InterfaceFlags /* accepted */) {}
77+
/// Resolve interface/propagation direction to comply with the given external interface
78+
virtual void resolveInterface(InterfaceFlags /* expected */) {}
8379

8480
/// validate connectivity of children (after init() was done)
8581
virtual void validateConnectivity() const;
@@ -220,8 +216,8 @@ class PropagatingEitherWayPrivate : public ComputeBasePrivate
220216
InterfaceFlags requiredInterface() const override;
221217
// initialize pull interfaces for given propagation directions
222218
void initInterface(PropagatingEitherWay::Direction dir);
223-
// prune interface to the given propagation direction
224-
void pruneInterface(InterfaceFlags accepted) override;
219+
// resolve interface to the given propagation direction
220+
void resolveInterface(InterfaceFlags expected) override;
225221

226222
bool canCompute() const override;
227223
void compute() override;

core/src/container.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -422,23 +422,23 @@ void SerialContainerPrivate::validateInterface(const StagePrivate& child, Interf
422422
}
423423

424424
// called by parent asking for pruning of this' interface
425-
void SerialContainerPrivate::pruneInterface(InterfaceFlags accepted) {
425+
void SerialContainerPrivate::resolveInterface(InterfaceFlags expected) {
426426
// we need to have some children to do the actual work
427427
if (children().empty())
428428
throw InitStageException(*me(), "no children");
429429

430-
if (!(accepted & START_IF_MASK))
430+
if (!(expected & START_IF_MASK))
431431
throw InitStageException(*me(), "unknown start interface");
432432

433433
Stage& first = *children().front();
434434
Stage& last = *children().back();
435435

436436
// FIRST child
437-
first.pimpl()->pruneInterface(accepted & START_IF_MASK);
437+
first.pimpl()->resolveInterface(expected & START_IF_MASK);
438438
// connect first child's (start) push interface
439439
setChildsPushBackwardInterface(first.pimpl());
440440
// validate that first child's and this container's start interfaces match
441-
validateInterface<START_IF_MASK>(*first.pimpl(), accepted);
441+
validateInterface<START_IF_MASK>(*first.pimpl(), expected);
442442
// connect first child's (start) pull interface
443443
if (const InterfacePtr& target = first.pimpl()->starts())
444444
starts_.reset(new Interface(
@@ -448,14 +448,14 @@ void SerialContainerPrivate::pruneInterface(InterfaceFlags accepted) {
448448
for (auto it = ++children().begin(), previous_it = children().begin(); it != children().end(); ++it, ++previous_it) {
449449
StagePrivate* child_impl = (**it).pimpl();
450450
StagePrivate* previous_impl = (**previous_it).pimpl();
451-
child_impl->pruneInterface(invert(previous_impl->requiredInterface()) & START_IF_MASK);
451+
child_impl->resolveInterface(invert(previous_impl->requiredInterface()) & START_IF_MASK);
452452
connect(*previous_impl, *child_impl);
453453
}
454454

455455
// connect last child's (end) push interface
456456
setChildsPushForwardInterface(last.pimpl());
457457
// validate that last child's and this container's end interfaces match
458-
validateInterface<END_IF_MASK>(*last.pimpl(), accepted);
458+
validateInterface<END_IF_MASK>(*last.pimpl(), expected);
459459
// connect last child's (end) pull interface
460460
if (const InterfacePtr& target = last.pimpl()->ends())
461461
ends_.reset(new Interface(
@@ -552,7 +552,7 @@ void WrappedSolution::fillMessage(moveit_task_constructor_msgs::Solution& soluti
552552
ParallelContainerBasePrivate::ParallelContainerBasePrivate(ParallelContainerBase* me, const std::string& name)
553553
: ContainerBasePrivate(me, name) {}
554554

555-
void ParallelContainerBasePrivate::pruneInterface(InterfaceFlags accepted) {
555+
void ParallelContainerBasePrivate::resolveInterface(InterfaceFlags expected) {
556556
// we need to have some children to do the actual work
557557
if (children().empty())
558558
throw InitStageException(*me(), "no children");
@@ -563,8 +563,8 @@ void ParallelContainerBasePrivate::pruneInterface(InterfaceFlags accepted) {
563563
for (const Stage::pointer& child : children()) {
564564
try {
565565
auto child_impl = child->pimpl();
566-
child_impl->pruneInterface(accepted);
567-
validateInterfaces(*child_impl, accepted, first);
566+
child_impl->resolveInterface(expected);
567+
validateInterfaces(*child_impl, expected, first);
568568
// initialize push connections of children according to their demands
569569
setChildsPushForwardInterface(child_impl);
570570
setChildsPushBackwardInterface(child_impl);
@@ -579,16 +579,16 @@ void ParallelContainerBasePrivate::pruneInterface(InterfaceFlags accepted) {
579579
throw exceptions;
580580

581581
// States received by the container need to be copied to all children's pull interfaces.
582-
if (accepted & READS_START)
582+
if (expected & READS_START)
583583
starts().reset(new Interface([this](Interface::iterator external, bool updated) {
584584
this->onNewExternalState(Interface::FORWARD, external, updated);
585585
}));
586-
if (accepted & READS_END)
586+
if (expected & READS_END)
587587
ends().reset(new Interface([this](Interface::iterator external, bool updated) {
588588
this->onNewExternalState(Interface::BACKWARD, external, updated);
589589
}));
590590

591-
required_interface_ = accepted;
591+
required_interface_ = expected;
592592
}
593593

594594
void ParallelContainerBasePrivate::validateInterfaces(const StagePrivate& child, InterfaceFlags& external,
@@ -746,8 +746,8 @@ void Fallbacks::onNewSolution(const SolutionBase& s) {
746746

747747
MergerPrivate::MergerPrivate(Merger* me, const std::string& name) : ParallelContainerBasePrivate(me, name) {}
748748

749-
void MergerPrivate::pruneInterface(InterfaceFlags accepted) {
750-
ContainerBasePrivate::pruneInterface(accepted);
749+
void MergerPrivate::resolveInterface(InterfaceFlags expected) {
750+
ContainerBasePrivate::resolveInterface(expected);
751751
switch (interfaceFlags()) {
752752
case PROPAGATE_FORWARDS:
753753
case PROPAGATE_BACKWARDS:

core/src/stage.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void StagePrivate::validateConnectivity() const {
117117
InterfaceFlags required = requiredInterface();
118118
InterfaceFlags actual = interfaceFlags();
119119
if ((required & actual) != required) {
120-
boost::format desc("interface %1% %2% does not satisfy required interface %3% %4%");
120+
boost::format desc("actual interface %1% %2% does not match required interface %3% %4%");
121121
desc % flowSymbol<START_IF_MASK>(actual) % flowSymbol<END_IF_MASK>(actual);
122122
desc % flowSymbol<START_IF_MASK>(required) % flowSymbol<END_IF_MASK>(required);
123123
throw InitStageException(*me(), desc.str());
@@ -420,24 +420,24 @@ void PropagatingEitherWayPrivate::initInterface(PropagatingEitherWay::Direction
420420
}
421421
}
422422

423-
void PropagatingEitherWayPrivate::pruneInterface(InterfaceFlags accepted) {
424-
if (accepted == UNKNOWN)
423+
void PropagatingEitherWayPrivate::resolveInterface(InterfaceFlags expected) {
424+
if (expected == UNKNOWN)
425425
throw InitStageException(*me(), "cannot initialize to unknown interface");
426426

427427
auto dir = PropagatingEitherWay::AUTO;
428-
if ((accepted & START_IF_MASK) == READS_START || (accepted & END_IF_MASK) == WRITES_NEXT_START)
428+
if ((expected & START_IF_MASK) == READS_START || (expected & END_IF_MASK) == WRITES_NEXT_START)
429429
dir = PropagatingEitherWay::FORWARD;
430-
else if ((accepted & START_IF_MASK) == WRITES_PREV_END || (accepted & END_IF_MASK) == READS_END)
430+
else if ((expected & START_IF_MASK) == WRITES_PREV_END || (expected & END_IF_MASK) == READS_END)
431431
dir = PropagatingEitherWay::BACKWARD;
432432
else {
433-
boost::format desc("propagator cannot handle external interface %1% %2%");
434-
desc % flowSymbol<START_IF_MASK>(accepted) % flowSymbol<END_IF_MASK>(accepted);
433+
boost::format desc("propagator cannot satisfy expected interface %1% %2%");
434+
desc % flowSymbol<START_IF_MASK>(expected) % flowSymbol<END_IF_MASK>(expected);
435435
throw InitStageException(*me(), desc.str());
436436
}
437437
if (configured_dir_ != PropagatingEitherWay::AUTO && dir != configured_dir_) {
438-
boost::format desc("configured interface (%1% %2%) does not match external one (%3% %4%)");
438+
boost::format desc("configured interface (%1% %2%) does not match expected one (%3% %4%)");
439439
desc % flowSymbol<START_IF_MASK>(required_interface_) % flowSymbol<END_IF_MASK>(required_interface_);
440-
desc % flowSymbol<START_IF_MASK>(accepted) % flowSymbol<END_IF_MASK>(accepted);
440+
desc % flowSymbol<START_IF_MASK>(expected) % flowSymbol<END_IF_MASK>(expected);
441441
throw InitStageException(*me(), desc.str());
442442
}
443443
initInterface(dir);

core/src/task.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ void Task::init() {
261261
// and *afterwards* initialize all children recursively
262262
stages()->init(impl->robot_model_);
263263
// task expects its wrapped child to push to both ends, this triggers interface resolution
264-
stages()->pimpl()->pruneInterface(InterfaceFlags({ GENERATE }));
264+
stages()->pimpl()->resolveInterface(InterfaceFlags({ GENERATE }));
265265

266266
// provide introspection instance to all stages
267267
impl->setIntrospection(impl->introspection_.get());

core/test/test_container.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,19 +200,19 @@ class InitTest : public ::testing::Test
200200
append(container, types);
201201
try {
202202
container.init(robot_model);
203-
// prune interfaces based on provided external interface (start, end)
204-
InterfaceFlags accepted;
203+
// resolve interfaces based on provided external interface (start, end)
204+
InterfaceFlags expected;
205205
if (start)
206-
accepted |= WRITES_PREV_END;
206+
expected |= WRITES_PREV_END;
207207
else
208-
accepted |= READS_START;
208+
expected |= READS_START;
209209

210210
if (end)
211-
accepted |= WRITES_NEXT_START;
211+
expected |= WRITES_NEXT_START;
212212
else
213-
accepted |= READS_END;
213+
expected |= READS_END;
214214

215-
container.pimpl()->pruneInterface(accepted);
215+
container.pimpl()->resolveInterface(expected);
216216
container.pimpl()->validateConnectivity();
217217
if (!expect_failure)
218218
return; // as expected
@@ -456,9 +456,9 @@ TEST_F(SerialTest, interface_detection) {
456456
EXPECT_EQ(container.pimpl()->interfaceFlags(), InterfaceFlags(CONNECT));
457457

458458
// derive propagation direction from outer interface
459-
EXPECT_INIT_SUCCESS(false, true, ANY); // should be pruned to FW
459+
EXPECT_INIT_SUCCESS(false, true, ANY); // should be resolved to FW
460460
EXPECT_EQ(container.pimpl()->interfaceFlags(), InterfaceFlags(PROPAGATE_FORWARDS));
461-
EXPECT_INIT_SUCCESS(true, false, ANY); // should be pruned to BW
461+
EXPECT_INIT_SUCCESS(true, false, ANY); // should be resolved to BW
462462
EXPECT_EQ(container.pimpl()->interfaceFlags(), InterfaceFlags(PROPAGATE_BACKWARDS));
463463

464464
EXPECT_INIT_SUCCESS(false, true, ANY, ANY); // -> ->

demo/scripts/grasp.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#! /usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
from std_msgs.msg import Header
5+
from geometry_msgs.msg import TwistStamped, Twist, Vector3Stamped, Vector3, PoseStamped, Pose, Point, Quaternion
6+
from moveit.task_constructor import core, stages
7+
import moveit_commander
8+
import rospy
9+
import numpy
10+
11+
from moveit.python_tools import roscpp_init
12+
roscpp_init("mtc_tutorial")
13+
rospy.init_node('mtc_tutorial_py', anonymous=False)
14+
15+
def create_object():
16+
scene = moveit_commander.PlanningSceneInterface(synchronous=True)
17+
scene.remove_world_object();
18+
pose = PoseStamped()
19+
pose.header.frame_id = "world"
20+
pose.pose.position.x = 0.5
21+
pose.pose.position.y = numpy.random.uniform(-0.1, 0.1)
22+
pose.pose.position.z = 0.16
23+
pose.pose.orientation.w = 1.0
24+
scene.add_box('object', pose, size=(0.05, 0.05, 0.2))
25+
26+
group = "panda_arm"
27+
eef_frame = "panda_link8"
28+
29+
# Cartesian interpolation planner
30+
cartesian = core.CartesianPath()
31+
32+
task = core.Task()
33+
34+
# start from current robot state
35+
task.add(stages.CurrentState("current state"))
36+
37+
move = stages.MoveTo("to object", cartesian)
38+
move.group = group
39+
header = Header(frame_id = "object")
40+
move.setGoal(PoseStamped(header=header, pose=Pose(position=Point(0,0,0.18),orientation=Quaternion(0.92388, -0.38268, 0, 0))))
41+
task.add(move)
42+
43+
create_object()
44+
if task.plan():
45+
task.publish(task.solutions[0])
46+
rospy.spin()

demo/scripts/pick.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#! /usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
from std_msgs.msg import Header
5+
from geometry_msgs.msg import TwistStamped, Twist, Vector3Stamped, Vector3, PoseStamped, Pose, Point, Quaternion
6+
from moveit.task_constructor import core, stages
7+
import moveit_commander
8+
import rospy
9+
import numpy
10+
11+
from moveit.python_tools import roscpp_init
12+
roscpp_init("mtc_tutorial")
13+
rospy.init_node('mtc_tutorial_py', anonymous=False)
14+
15+
group = 'panda_arm'
16+
eef = 'panda_hand'
17+
eef_frame = "panda_link8"
18+
19+
sampling_planner = core.JointInterpolationPlanner()
20+
cartesian_planner = core.CartesianPath()
21+
22+
task = core.Task()
23+
24+
task.properties.update({'group': group, 'eef': eef, 'hand': eef, 'hand_grasping_frame': eef, 'ik_frame': eef_frame})
25+
26+
currstate = stages.CurrentState('current state')
27+
#task.add(currstate) # Adding it to the task results in error for argument types in setMonitoredStage in GenerateGraspPose
28+
29+
open_hand = stages.MoveTo("open hand", sampling_planner)
30+
open_hand.group = eef
31+
open_hand.setGoal('open')
32+
task.add(open_hand)
33+
34+
connect = stages.Connect('move to pick', [(group, sampling_planner)])
35+
connect.timeout = 5
36+
connect.properties.configureInitFrom(core.PARENT)
37+
task.add(connect)
38+
39+
grasp = core.SerialContainer('pick object')
40+
task.properties.exposeTo(grasp.properties, ['eef', 'hand', 'group', 'ik_frame'])
41+
grasp.properties.configureInitFrom(core.PARENT, ['eef', 'hand', 'group', 'ik_frame'])
42+
43+
approach_object = stages.MoveRelative("approach_object", cartesian_planner)
44+
approach_object.properties.update({'marker_ns': 'approach_object', 'link': eef_frame})
45+
approach_object.properties.configureInitFrom(core.PARENT, ['group'])
46+
approach_object.min_distance = 0.01
47+
approach_object.max_distance = 0.1
48+
print(approach_object.properties.__getitem__('group')) # Why is this None? how to get properties from within SerialContainer?
49+
approach_object.setDirection(TwistStamped(header=Header(frame_id = eef_frame), twist=Twist(linear=Vector3(0,0,0.1))))
50+
grasp.insert(approach_object)
51+
52+
generatepose = stages.GenerateGraspPose('generate grasp pose')
53+
generatepose.properties.configureInitFrom(core.PARENT)
54+
generatepose.properties.update({'marker_ns': 'grasp_pose'})
55+
generatepose.pregrasp = 'open'
56+
generatepose.object = 'base'
57+
generatepose.angle_delta = numpy.pi/12
58+
generatepose.setMonitoredStage(currstate)
59+
60+
# To be continued
61+
task.add(grasp)
62+
63+
if task.plan():
64+
task.publish(task.solutions[0])
65+
rospy.spin()

0 commit comments

Comments
 (0)