-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
254 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
lbr_demos/lbr_demos_moveit_python/doc/lbr_demos_moveit_python.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
112 changes: 112 additions & 0 deletions
112
lbr_demos/lbr_demos_moveit_python/lbr_demos_moveit_python/sequenced_motion.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
], | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |