Skip to content

Commit f1fc447

Browse files
committed
establish utils namespace
leaves us a place to put free helper functions
1 parent 48959c6 commit f1fc447

File tree

7 files changed

+90
-30
lines changed

7 files changed

+90
-30
lines changed

core/include/moveit/task_constructor/moveit_compat.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,3 @@
5757
#define MOVEIT_HAS_OBJECT_POSE MOVEIT_VERSION_GE(1, 1, 6)
5858

5959
#define MOVEIT_HAS_STATE_RIGID_PARENT_LINK MOVEIT_VERSION_GE(1, 1, 6)
60-
61-
#if !MOVEIT_HAS_STATE_RIGID_PARENT_LINK
62-
#include <moveit/robot_state/robot_state.h>
63-
inline const moveit::core::LinkModel* getRigidlyConnectedParentLinkModel(const moveit::core::RobotState& state,
64-
std::string frame) {
65-
const moveit::core::LinkModel* link{ nullptr };
66-
67-
if (state.hasAttachedBody(frame)) {
68-
link = state.getAttachedBody(frame)->getAttachedLink();
69-
} else if (state.getRobotModel()->hasLinkModel(frame))
70-
link = state.getLinkModel(frame);
71-
72-
return state.getRobotModel()->getRigidlyConnectedParentLinkModel(link);
73-
}
74-
#endif

core/include/moveit/task_constructor/stage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ enum InterfaceFlag
8484
GENERATE = WRITES_PREV_END | WRITES_NEXT_START,
8585
};
8686

87-
using InterfaceFlags = Flags<InterfaceFlag>;
87+
using InterfaceFlags = utils::Flags<InterfaceFlag>;
8888

8989
/** invert interface such that
9090
* - new end can connect to old start

core/include/moveit/task_constructor/utils.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,27 @@
3232
* POSSIBILITY OF SUCH DAMAGE.
3333
*********************************************************************/
3434

35-
/* Authors: Robert Haschke
36-
Desc: Project-agnostic utility classes
35+
/* Authors: Robert Haschke, Michael 'v4hn' Goerner
36+
Desc: Miscellaneous utilities
3737
*/
3838

3939
#pragma once
4040

41+
#include <string>
4142
#include <type_traits>
4243
#include <initializer_list>
4344

45+
namespace moveit {
46+
47+
namespace core {
48+
class LinkModel;
49+
class RobotState;
50+
} // namespace core
51+
52+
namespace task_constructor {
53+
54+
namespace utils {
55+
4456
/** template class to compose flags from enums in a type-safe fashion */
4557
template <typename Enum>
4658
class Flags
@@ -118,3 +130,9 @@ class Flags
118130
};
119131

120132
#define DECLARE_FLAGS(Flags, Enum) using Flags = QFlags<Enum>;
133+
134+
const moveit::core::LinkModel* getRigidlyConnectedParentLinkModel(const moveit::core::RobotState& state,
135+
std::string frame);
136+
} // namespace utils
137+
} // namespace task_constructor
138+
} // namespace moveit

core/src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ add_library(${PROJECT_NAME}
2828
stage.cpp
2929
storage.cpp
3030
task.cpp
31+
utils.cpp
3132

3233
solvers/planner_interface.cpp
3334
solvers/cartesian_path.cpp

core/src/stages/compute_ik.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,7 @@ void ComputeIK::compute() {
294294
}
295295
ik_pose = scene->getCurrentState().getFrameTransform(ik_pose_msg.header.frame_id) * ik_pose;
296296

297-
#if MOVEIT_HAS_STATE_RIGID_PARENT_LINK
298-
link = scene->getCurrentState().getRigidlyConnectedParentLinkModel(ik_pose_msg.header.frame_id);
299-
#else
300-
link = getRigidlyConnectedParentLinkModel(scene->getCurrentState(), ik_pose_msg.header.frame_id);
301-
#endif
297+
link = utils::getRigidlyConnectedParentLinkModel(scene->getCurrentState(), ik_pose_msg.header.frame_id);
302298

303299
// transform target pose such that ik frame will reach there if link does
304300
target_pose = target_pose * ik_pose.inverse() * scene->getCurrentState().getFrameTransform(link->getName());

core/src/stages/move_to.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <moveit/task_constructor/stages/move_to.h>
4444
#include <moveit/task_constructor/cost_terms.h>
4545
#include <moveit/task_constructor/moveit_compat.h>
46+
#include <moveit/task_constructor/utils.h>
4647

4748
#include <rviz_marker_tools/marker_creation.h>
4849

@@ -262,13 +263,8 @@ bool MoveTo::compute(const InterfaceState& state, planning_scene::PlanningSceneP
262263
add_frame(target, "target frame");
263264
add_frame(ik_pose_world, "ik frame");
264265

265-
const moveit::core::LinkModel* parent {
266-
#if MOVEIT_HAS_STATE_RIGID_PARENT_LINK
267-
scene->getCurrentState().getRigidlyConnectedParentLinkModel(ik_pose_msg.header.frame_id)
268-
#else
269-
getRigidlyConnectedParentLinkModel(scene->getCurrentState(), ik_pose_msg.header.frame_id)
270-
#endif
271-
};
266+
const moveit::core::LinkModel* parent{ utils::getRigidlyConnectedParentLinkModel(scene->getCurrentState(),
267+
ik_pose_msg.header.frame_id) };
272268

273269
// transform target pose such that ik frame will reach there if link does
274270
Eigen::Isometry3d ik_pose;

core/src/utils.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*********************************************************************
2+
* Software License Agreement (BSD License)
3+
*
4+
* Copyright (c) 2017, Hamburg University
5+
* Copyright (c) 2017, Bielefeld University
6+
* All rights reserved.
7+
*
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions
10+
* are met:
11+
*
12+
* * Redistributions of source code must retain the above copyright
13+
* notice, this list of conditions and the following disclaimer.
14+
* * Redistributions in binary form must reproduce the above
15+
* copyright notice, this list of conditions and the following
16+
* disclaimer in the documentation and/or other materials provided
17+
* with the distribution.
18+
* * Neither the name of Bielefeld University nor the names of its
19+
* contributors may be used to endorse or promote products derived
20+
* from this software without specific prior written permission.
21+
*
22+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32+
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33+
* POSSIBILITY OF SUCH DAMAGE.
34+
*********************************************************************/
35+
36+
/* Authors: Michael Goerner, Robert Haschke */
37+
38+
#include <moveit/robot_state/robot_state.h>
39+
40+
#include <moveit/task_constructor/moveit_compat.h>
41+
42+
namespace moveit {
43+
namespace task_constructor {
44+
namespace utils {
45+
46+
const moveit::core::LinkModel* getRigidlyConnectedParentLinkModel(const moveit::core::RobotState& state,
47+
std::string frame) {
48+
#if MOVEIT_HAS_STATE_RIGID_PARENT_LINK
49+
return state.getRigidlyConnectedParentLinkModel(frame);
50+
#else
51+
const moveit::core::LinkModel* link{ nullptr };
52+
53+
if (state.hasAttachedBody(frame)) {
54+
link = state.getAttachedBody(frame)->getAttachedLink();
55+
} else if (state.getRobotModel()->hasLinkModel(frame))
56+
link = state.getLinkModel(frame);
57+
58+
return state.getRobotModel()->getRigidlyConnectedParentLinkModel(link);
59+
#endif
60+
}
61+
62+
} // namespace utils
63+
} // namespace task_constructor
64+
} // namespace moveit

0 commit comments

Comments
 (0)