Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions shared/tests/ros2-pymoveit2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
tests:
# The package and its robot presets import (rclpy and the message packages load).
- python:
imports:
- pymoveit2
- pymoveit2.robots.panda
pip_check: false
# Smoke test without a running MoveIt: the arm and gripper interfaces of the Panda preset are created on a node (action and service clients for move_group), and the arm interface receives a JointState published on the same node.
- script:
env:
ROS_LOCALHOST_ONLY: "1"
ROS_AUTOMATIC_DISCOVERY_RANGE: LOCALHOST
content:
- python pymoveit2_smoke_test.py
files:
recipe:
- pymoveit2_smoke_test.py
79 changes: 79 additions & 0 deletions shared/tests/ros2-pymoveit2/pymoveit2_smoke_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env python3
"""Smoke test for pymoveit2, without a running MoveIt.

Creates the arm and gripper interfaces for the Panda preset on one node (this loads
rclpy, the RMW and the type support of every message, service and action package
pymoveit2 uses), publishes a JointState on the same node and checks that the arm
interface receives it, then destroys everything.
"""

import sys
import time

import rclpy
from rclpy.executors import SingleThreadedExecutor
from sensor_msgs.msg import JointState

from pymoveit2 import MoveIt2, MoveIt2Gripper
from pymoveit2.robots import panda

TIMEOUT_SEC = 20.0


def main() -> int:
rclpy.init()
node = rclpy.create_node("pymoveit2_smoke_test")
executor = SingleThreadedExecutor()
executor.add_node(node)

joint_names = panda.joint_names()
moveit2 = MoveIt2(
node=node,
joint_names=joint_names,
base_link_name=panda.base_link_name(),
end_effector_name=panda.end_effector_name(),
group_name=panda.MOVE_GROUP_ARM,
)
gripper = MoveIt2Gripper(
node=node,
gripper_joint_names=panda.gripper_joint_names(),
open_gripper_joint_positions=panda.OPEN_GRIPPER_JOINT_POSITIONS,
closed_gripper_joint_positions=panda.CLOSED_GRIPPER_JOINT_POSITIONS,
gripper_group_name=panda.MOVE_GROUP_GRIPPER,
)

assert moveit2.joint_names == joint_names, moveit2.joint_names
assert moveit2.joint_state is None, "joint state before anything was published"

# Same node, so the same DDS participant: no network discovery is involved.
publisher = node.create_publisher(JointState, "joint_states", 1)
msg = JointState()
msg.name = joint_names
msg.position = [0.1 * i for i in range(len(joint_names))]

deadline = time.monotonic() + TIMEOUT_SEC
while moveit2.joint_state is None and time.monotonic() < deadline:
msg.header.stamp = node.get_clock().now().to_msg()
publisher.publish(msg)
executor.spin_once(timeout_sec=0.1)

received = moveit2.joint_state
ok = received is not None and list(received.name) == joint_names
if ok:
print("pymoveit2 smoke test: joint state received:", list(received.position))
else:
print(
f"pymoveit2 smoke test: no joint state within {TIMEOUT_SEC} s",
file=sys.stderr,
)

gripper.destroy()
moveit2.destroy()
executor.shutdown()
node.destroy_node()
rclpy.shutdown()
return 0 if ok else 1


if __name__ == "__main__":
sys.exit(main())
1 change: 1 addition & 0 deletions shared/vinca.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ packages_select_by_deps:
- py_trees_ros_interfaces
- py_trees_ros_tutorials
- py_trees_ros_viewer
- pymoveit2
- radar_msgs
- random_numbers
- rclc
Expand Down
Loading