Skip to content

Commit

Permalink
#159: added sequenced demo
Browse files Browse the repository at this point in the history
  • Loading branch information
mhubii committed May 5, 2024
1 parent 7c8121a commit dcf3d8c
Show file tree
Hide file tree
Showing 11 changed files with 254 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lbr_bringup/lbr_bringup/launch_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ def moveit_configs_builder(
f"urdf/{robot_name}/{robot_name}.urdf.xacro",
),
)
.planning_pipelines(default_planning_pipeline="ompl", pipelines=["ompl"])
.planning_pipelines(
default_planning_pipeline="ompl",
pipelines=["pilz_industrial_motion_planner", "ompl"],
)
)

@staticmethod
Expand All @@ -78,9 +81,7 @@ def params_move_group() -> Dict[str, Any]:
"allow_trajectory_execution"
),
# Note: Wrapping the following values is necessary so that the parameter value can be the empty string
"capabilities": ParameterValue(
LaunchConfiguration("capabilities"), value_type=str
),
"capabilities": "pilz_industrial_motion_planner/MoveGroupSequenceAction pilz_industrial_motion_planner/MoveGroupSequenceService",
"disable_capabilities": ParameterValue(
LaunchConfiguration("disable_capabilities"), value_type=str
),
Expand Down
17 changes: 17 additions & 0 deletions lbr_demos/lbr_demos_moveit_python/doc/lbr_demos_moveit_python.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# LBR Demos Moveit Python
1. Install Pilz industrial motion planner
```shell
sudo apt install ros-humble-pilz-industrial-motion-planner

```
2. Run simulation or real robot
```shell
ros2 launch lbr_bringup bringup.launch.py \
moveit:=true \
model:=iiwa7 # [iiwa7, iiwa14, med7, med14]
```

3. Run sequenced motion example
```shell
ros2 run lbr_demos_moveit_python sequenced_motion
```
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
from typing import List

import rclpy
from geometry_msgs.msg import Point, Pose, Quaternion
from moveit_msgs.action import MoveGroupSequence
from moveit_msgs.msg import (
BoundingVolume,
Constraints,
MotionPlanRequest,
MotionSequenceItem,
OrientationConstraint,
PlanningScene,
PositionConstraint,
RobotState,
)
from rclpy.action import ActionClient
from rclpy.node import Node
from sensor_msgs.msg import JointState
from shape_msgs.msg import SolidPrimitive
from std_msgs.msg import Header


class SequencedMotion(Node):
def __init__(self):
super().__init__("sequenced_motion")
self._planning_scene_sub = self.create_subscription(
PlanningScene, "/lbr/monitored_planning_scene", self._on_planning_scene, 1
)
self._robot_state = None

self._action_client = ActionClient(
self, MoveGroupSequence, "/lbr/sequence_move_group"
)
while not self._action_client.wait_for_server(timeout_sec=1.0):
self.get_logger().info(f"Waiting for {self._action_client._action_name}...")

self._base = "link_0"
self._end_effector = "link_ee"
self._move_group_name = "arm"

def _on_planning_scene(self, msg: PlanningScene) -> None:
self._robot_state = msg.robot_state

def _build_motion_plan_request(self, target_pose: Pose) -> MotionPlanRequest:
req = MotionPlanRequest()

# general config
req.pipeline_id = "pilz_industrial_motion_planner"
req.planner_id = "PTP" # For Pilz PTP, LIN of CIRC
req.allowed_planning_time = 10.0
req.group_name = self._move_group_name
req.max_acceleration_scaling_factor = 0.1
req.max_velocity_scaling_factor = 0.01
req.num_planning_attempts = 100

# goal constraints
req.goal_constraints.append(
Constraints(
position_constraints=[
PositionConstraint(
header=Header(frame_id=self._base),
link_name=self._end_effector,
constraint_region=BoundingVolume(
primitives=[SolidPrimitive(type=2, dimensions=[0.0001])],
primitive_poses=[Pose(position=target_pose.position)],
),
weight=1.0,
)
],
orientation_constraints=[
OrientationConstraint(
header=Header(frame_id=self._base),
link_name=self._end_effector,
orientation=target_pose.orientation,
absolute_x_axis_tolerance=0.001,
absolute_y_axis_tolerance=0.001,
absolute_z_axis_tolerance=0.001,
weight=1.0,
)
],
)
)
return req

def execute_sequence(self, target_poses: List[Pose]) -> None:
goal = MoveGroupSequence.Goal()
for idx, target_pose in enumerate(target_poses):
goal.request.items.append(
MotionSequenceItem(
blend_radius=(
0.05 if idx != len(target_poses) - 1 else 0.0
), # last radius must be 0
req=self._build_motion_plan_request(target_pose),
)
)
future = self._action_client.send_goal_async(goal)
rclpy.spin_until_future_complete(self, future)


def main() -> None:
rclpy.init()
sequenced_motion = SequencedMotion()
target_poses = [
Pose(position=Point(x=0.0, y=0.0, z=1.0), orientation=Quaternion(w=1.0)),
Pose(position=Point(x=0.2, y=0.2, z=0.8), orientation=Quaternion(w=1.0)),
]
sequenced_motion.execute_sequence(target_poses=target_poses)
rclpy.shutdown()


if __name__ == "__main__":
main()
18 changes: 18 additions & 0 deletions lbr_demos/lbr_demos_moveit_python/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>lbr_demos_moveit_python</name>
<version>1.4.3</version>
<description>MoveIt examples in Python.</description>
<maintainer email="martin.huber@kcl.ac.uk">mhubii</maintainer>
<license>Apache-2.0</license>

<test_depend>ament_copyright</test_depend>
<test_depend>ament_flake8</test_depend>
<test_depend>ament_pep257</test_depend>
<test_depend>python3-pytest</test_depend>

<export>
<build_type>ament_python</build_type>
</export>
</package>
Empty file.
4 changes: 4 additions & 0 deletions lbr_demos/lbr_demos_moveit_python/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[develop]
script_dir=$base/lib/lbr_demos_moveit_python
[install]
install_scripts=$base/lib/lbr_demos_moveit_python
25 changes: 25 additions & 0 deletions lbr_demos/lbr_demos_moveit_python/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from setuptools import find_packages, setup

package_name = "lbr_demos_moveit_python"

setup(
name=package_name,
version="1.4.3",
packages=find_packages(exclude=["test"]),
data_files=[
("share/ament_index/resource_index/packages", ["resource/" + package_name]),
("share/" + package_name, ["package.xml"]),
],
install_requires=["setuptools"],
zip_safe=True,
maintainer="mhubii",
maintainer_email="martin.huber@kcl.ac.uk",
description="TODO: Package description",
license="Apache-2.0",
tests_require=["pytest"],
entry_points={
"console_scripts": [
"sequenced_motion = lbr_demos_moveit_python.sequenced_motion:main",
],
},
)
25 changes: 25 additions & 0 deletions lbr_demos/lbr_demos_moveit_python/test/test_copyright.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2015 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from ament_copyright.main import main
import pytest


# Remove the `skip` decorator once the source file(s) have a copyright header
@pytest.mark.skip(reason='No copyright header has been placed in the generated source file.')
@pytest.mark.copyright
@pytest.mark.linter
def test_copyright():
rc = main(argv=['.', 'test'])
assert rc == 0, 'Found errors'
25 changes: 25 additions & 0 deletions lbr_demos/lbr_demos_moveit_python/test/test_flake8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2017 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from ament_flake8.main import main_with_errors
import pytest


@pytest.mark.flake8
@pytest.mark.linter
def test_flake8():
rc, errors = main_with_errors(argv=[])
assert rc == 0, \
'Found %d code style errors / warnings:\n' % len(errors) + \
'\n'.join(errors)
23 changes: 23 additions & 0 deletions lbr_demos/lbr_demos_moveit_python/test/test_pep257.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2015 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from ament_pep257.main import main
import pytest


@pytest.mark.linter
@pytest.mark.pep257
def test_pep257():
rc = main(argv=['.', 'test'])
assert rc == 0, 'Found code style errors / warnings'

0 comments on commit dcf3d8c

Please sign in to comment.