### MoveIt2 Setup and Pose Movement Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/README.md This example demonstrates the basic setup for using MoveIt2, including node creation and initializing the MoveIt2 interface. It then shows how to move the robot to a specified pose. ```python # Imports import rclpy from pymoveit2 import MoveIt2 # Setup node = rclpy.create_node("example") moveit2 = MoveIt2(node=node, ...) # Usage moveit2.move_to_pose(position=[0.3, 0.2, 0.5], ...) ``` -------------------------------- ### GripperCommand Example Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/gripper-api.md Instantiate and configure a GripperCommand object. Ensure the node and joint names are correctly provided. ```python from pymoveit2 import GripperCommand gripper = GripperCommand( node=node, gripper_joint_names=["panda_finger_joint1", "panda_finger_joint2"], open_gripper_joint_positions=[0.04, 0.04], closed_gripper_joint_positions=[0.0, 0.0], max_effort=170.0, ) ``` -------------------------------- ### Computing Inverse Kinematics with an Optional Seed State Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/errors.md This example shows how to compute the inverse kinematics for a target pose. It includes an optional `start_joint_state` which can help guide the IK solver, especially in complex configurations. If no solution is found, it returns `None`. ```python # Compute IK with optional seed joint_state = moveit2.compute_ik( position=[0.3, 0.2, 0.5], quat_xyzw=[0.0, 0.0, 0.0, 1.0], start_joint_state=[0.0, -1.57, 0.0, -1.57, 0.0, 1.57, 0.0], ) if joint_state is None: print("No IK solution found") ``` -------------------------------- ### Install MoveIt 2 Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/INDEX.md Installs the MoveIt 2 package using apt. Ensure your ROS_DISTRO environment variable is set. ```bash sudo apt install ros-${ROS_DISTRO}-moveit ``` -------------------------------- ### MoveIt 2 Servo Example Source: https://github.com/andrejorsula/pymoveit2/blob/main/README.md Demonstrates using MoveIt 2 Servo to achieve continuous end-effector motion, such as a circular path. ```bash ros2 run pymoveit2 ex_servo.py ``` -------------------------------- ### Source ROS 2 Workspace Source: https://github.com/andrejorsula/pymoveit2/blob/main/README.md After building, source the local setup script to enable importing the pymoveit2 module in external workspaces. ```bash source install/local_setup.bash ``` -------------------------------- ### Panda Robot Example Usage Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/robots-presets.md Demonstrates initializing MoveIt2 and MoveIt2Gripper for the Panda robot using its preset constants. Ensure the 'node' object is properly initialized before use. ```python from pymoveit2 import MoveIt2, MoveIt2Gripper from pymoveit2.robots import panda # Arm arm = MoveIt2( node=node, joint_names=panda.joint_names(), base_link_name=panda.base_link_name(), end_effector_name=panda.end_effector_name(), ) # Gripper 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, ) ``` -------------------------------- ### UR Robot Example Usage Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/robots-presets.md Initializes MoveIt2 for a UR robot using its preset functions for joint names, base link, and end-effector. The 'node' must be available. ```python from pymoveit2 import MoveIt2 from pymoveit2.robots import ur arm = MoveIt2( node=node, joint_names=ur.joint_names(), base_link_name=ur.base_link_name(), end_effector_name=ur.end_effector_name(), ) ``` -------------------------------- ### GripperInterface Example Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/gripper-api.md Instantiate GripperInterface with robot-specific joint names and positions. The interface automatically selects the appropriate gripper control method. ```python from pymoveit2 import GripperInterface from pymoveit2.robots import panda gripper = GripperInterface( node=node, gripper_joint_names=panda.gripper_joint_names(), open_gripper_joint_positions=[0.04, 0.04], closed_gripper_joint_positions=[0.0, 0.0], ) # Interface is automatically selected at runtime gripper.open() gripper.close() ``` -------------------------------- ### Launch MoveIt 2 Control Source: https://github.com/andrejorsula/pymoveit2/blob/main/README.md Before running examples, launch either the fake control or Gazebo simulation environment for MoveIt 2. This sets up the necessary ROS 2 nodes and topics for robot control. ```bash ros2 launch panda_moveit_config ex_fake_control.launch.py ``` ```bash ros2 launch panda_moveit_config ex_gz_control.launch.py ``` -------------------------------- ### PyMoveIt2 Installation Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/INDEX.md Clones the PyMoveIt2 repository, installs dependencies, and builds the package within a ROS 2 workspace. ```bash # Clone into ROS 2 workspace git clone https://github.com/AndrejOrsula/pymoveit2.git # Install dependencies rosdep install -y -r -i --rosdistro ${ROS_DISTRO} --from-paths . # Build colcon build --merge-install --symlink-install ``` -------------------------------- ### General Robot Preset Pattern Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/robots-presets.md Demonstrates the standard pattern for initializing MoveIt2 with a robot preset, including getting joint and frame names. ```python from pymoveit2.robots import [robot_name] # 1. Get joint names joints = [robot_name].joint_names() # 2. Get frame names base = [robot_name].base_link_name() effector = [robot_name].end_effector_name() # 3. Create interface moveit2 = MoveIt2( node=node, joint_names=joints, base_link_name=base, end_effector_name=effector, ) ``` -------------------------------- ### Build PyMoveIt2 with Colcon Source: https://github.com/andrejorsula/pymoveit2/blob/main/README.md Clone the repository, install dependencies using rosdep, and build the project with colcon. Ensure you are using a compatible ROS 2 distribution (Galactic, Humble, or Iron). ```bash git clone https://github.com/AndrejOrsula/pymoveit2.git rosdep install -y -r -i --rosdistro ${ROS_DISTRO} --from-paths . colcon build --merge-install --symlink-install --cmake-args "-DCMAKE_BUILD_TYPE=Release" ``` -------------------------------- ### Adjusting Planning Parameters for Difficult Goals Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/errors.md This example shows how to increase `allowed_planning_time` and `num_planning_attempts` to help the planner find a path when facing difficult goals or potential timeouts. It also checks if the plan returned `None`, indicating failure. ```python # Increase planning parameters moveit2.allowed_planning_time = 2.0 moveit2.num_planning_attempts = 20 trajectory = moveit2.plan(position=[0.3, 0.2, 0.5], quat_xyzw=[0.0, 0.0, 0.0, 1.0]) if trajectory is None: print("Goal unreachable or planning timeout") ``` -------------------------------- ### Install Trimesh Dependency Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/errors.md Command to install the 'trimesh' Python package, which is an optional dependency for some PyMoveIt2 functionalities. ```bash pip install trimesh ``` -------------------------------- ### Kinova Robot Example Usage Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/robots-presets.md Sets up MoveIt2 for a Kinova robot by utilizing its predefined joint names, base link, and end-effector names. Requires a valid 'node' object. ```python from pymoveit2 import MoveIt2 from pymoveit2.robots import kinova arm = MoveIt2( node=node, joint_names=kinova.joint_names(), base_link_name=kinova.base_link_name(), end_effector_name=kinova.end_effector_name(), ) ``` -------------------------------- ### LBR Robot Example Usage Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/robots-presets.md Initializes MoveIt2 for a KUKA LBR robot using its specific joint names, base link, and end-effector name presets. Ensure 'node' is initialized. ```python from pymoveit2 import MoveIt2 from pymoveit2.robots import lbr arm = MoveIt2( node=node, joint_names=lbr.joint_names(), base_link_name=lbr.base_link_name(), end_effector_name=lbr.end_effector_name(), ) ``` -------------------------------- ### Implement Timeout Management for Blocking Operations Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/errors.md This example demonstrates how to manage timeouts for blocking operations, such as waiting for a motion to complete. It includes a loop that checks the elapsed time against a defined timeout and cancels execution if the timeout is exceeded. ```python import time # Set timeout for blocking operations start = time.time() timeout = 5.0 # 5 seconds while moveit2.query_state() != MoveIt2State.IDLE: if time.time() - start > timeout: print("Timeout waiting for motion") moveit2.cancel_execution() break rclpy.spin_once(node, timeout_sec=0.1) ``` -------------------------------- ### Gripper Control with GripperInterface Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/INDEX.md Shows how to initialize and use the GripperInterface for opening, closing, and moving the gripper to a specific position. Requires the node and gripper joint names. ```python from pymoveit2 import GripperInterface gripper = GripperInterface( node=node, gripper_joint_names=panda.gripper_joint_names(), open_gripper_joint_positions=[0.04, 0.04], closed_gripper_joint_positions=[0.0, 0.0], ) gripper.open() gripper.close() gripper.move_to_position(0.02) ``` -------------------------------- ### Basic Motion Planning and Execution with MoveIt2 Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/INDEX.md Demonstrates initializing MoveIt2, moving to a Cartesian pose, and then to a specific joint configuration. Requires ROS 2 initialization and the panda robot configuration. ```python import rclpy from pymoveit2 import MoveIt2 from pymoveit2.robots import panda # Initialize ROS 2 rclpy.init() node = rclpy.create_node("moveit2_example") # Create MoveIt2 interface moveit2 = MoveIt2( node=node, joint_names=panda.joint_names(), base_link_name=panda.base_link_name(), end_effector_name=panda.end_effector_name(), ) # Move to Cartesian pose moveit2.move_to_pose( position=[0.3, 0.2, 0.5], quat_xyzw=[0.0, 0.0, 0.0, 1.0], ) # Move to joint configuration moveit2.move_to_configuration([0.0, -1.57, 0.0, -1.57, 0.0, 1.57, 0.0]) # Cleanup rclpy.shutdown() ``` -------------------------------- ### Get Panda Robot Joint Names Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/types.md Retrieves the joint names for the Panda robot, optionally with a prefix. ```python joint_names = panda.joint_names(prefix="panda_") base_link = panda.base_link_name(prefix="panda_") end_effector = panda.end_effector_name(prefix="panda_") gripper_joints = panda.gripper_joint_names(prefix="panda_") ``` -------------------------------- ### Get Execution Future Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/moveit2-api.md Retrieves the Future object associated with the currently executing motion. Returns None if no motion is executing. ```python def get_execution_future(self) -> Optional[Future] ``` -------------------------------- ### Initialize MoveIt2 Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/README.md Construct the MoveIt2 interface with necessary robot and planning parameters. ```python moveit2 = MoveIt2( node=node, joint_names=[...], base_link_name="base_link", end_effector_name="tool0", ) ``` -------------------------------- ### Get Inverse Kinematics Result Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/moveit2-api.md Extracts the inverse kinematics result from a Future object obtained from an asynchronous IK computation. ```python def get_compute_ik_result( self, future: Future, ) -> Optional[JointState] ``` -------------------------------- ### open() Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/gripper-api.md Opens the gripper. Optionally skips the action if the gripper is already in the open state. ```APIDOC ### open() Open the gripper. ```python def open(self, skip_if_noop: bool = False) -> None ``` **Parameters:** | Parameter | Type | Default | Description | |-----------|------|---------|-------------| | skip_if_noop | bool | False | If True, skip if already open | **Returns:** None **Example:** ```python gripper.open() gripper.open(skip_if_noop=True) ``` ``` -------------------------------- ### Get Forward Kinematics Result Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/moveit2-api.md Extracts the forward kinematics result from a Future object obtained from an asynchronous FK computation. ```python def get_compute_fk_result( self, future: Future, fk_link_names: Optional[List[str]] = None, ) -> Optional[Union[PoseStamped, List[PoseStamped]]] ``` -------------------------------- ### Get Last Execution Error Code Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/moveit2-api.md Retrieves the error code from the last motion execution. Returns an optional MoveItErrorCodes object. ```python def get_last_execution_error_code(self) -> Optional[MoveItErrorCodes] ``` -------------------------------- ### Initialize MoveIt2Gripper Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/gripper-api.md Instantiate the MoveIt2Gripper class with necessary parameters. Ensure you have a ROS 2 node and define gripper joint names and positions. ```python from pymoveit2 import MoveIt2Gripper from pymoveit2.robots import panda node = rclpy.create_node("gripper_example") gripper = MoveIt2Gripper( node=node, gripper_joint_names=panda.gripper_joint_names(), open_gripper_joint_positions=[0.04, 0.04], closed_gripper_joint_positions=[0.0, 0.0], gripper_group_name="gripper", ) ``` -------------------------------- ### Initialize and Enable Servo Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/errors.md Create a MoveIt2Servo object, optionally enabling it at initialization. Explicitly enable the servo if it was not auto-enabled. ```python from pymoveit2 import MoveIt2Servo servo = MoveIt2Servo( node=node, frame_id="panda_link0", enable_at_init=True, # Auto-enable on construction ) # Or enable explicitly if servo.enable(sync=True): servo.servo(linear=(1.0, 0.0, 0.0)) ``` -------------------------------- ### GripperInterface Constructor Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/gripper-api.md Initializes the GripperInterface, which abstracts MoveIt2Gripper and GripperCommand. 'execute_via_moveit' and 'skip_planning' control the execution strategy. ```python GripperInterface( node: Node, gripper_joint_names: List[str], open_gripper_joint_positions: List[float], closed_gripper_joint_positions: List[float], gripper_group_name: str = "gripper", execute_via_moveit: bool = False, ignore_new_calls_while_executing: bool = False, skip_planning: bool = False, skip_planning_fixed_motion_duration: float = 0.5, max_effort: float = 0.0, callback_group: Optional[CallbackGroup] = None, follow_joint_trajectory_action_name: str = "DEPRECATED", gripper_command_action_name: str = "gripper_action_controller/gripper_cmd", use_move_group_action: bool = False, ) ``` -------------------------------- ### Retrieve Robot Joint Names from URDF Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/errors.md Example of how to potentially retrieve robot joint names by parsing the URDF description. This is a common step when diagnosing 'Joint Names Mismatch' errors. ```python # Verify joint names match URDF import subprocess result = subprocess.run(["ros2", "param", "get", "/robot_description"], capture_output=True, text=True) # Parse URDF to find actual joint names ``` -------------------------------- ### Configure Panda Robot Arm and Gripper Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/configuration.md Instantiate MoveIt2 for the arm and MoveIt2Gripper for the gripper using predefined Panda robot configurations. Ensure the ROS 2 node is initialized. ```python from pymoveit2 import MoveIt2, MoveIt2Gripper from pymoveit2.robots import panda # Arm arm = MoveIt2( node=node, joint_names=panda.joint_names(), base_link_name=panda.base_link_name(), end_effector_name=panda.end_effector_name(), group_name="arm", ) # Gripper 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="gripper", ) ``` -------------------------------- ### Converting MoveIt Error Codes to String Names Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/errors.md This example shows how to convert a numerical MoveIt error code into its corresponding string name using the `enum_to_str` utility function from `pymoveit2.utils`. ```python from pymoveit2.utils import enum_to_str from moveit_msgs.msg import MoveItErrorCodes error_code = MoveItErrorCodes.INVALID_GROUP_NAME error_name = enum_to_str(MoveItErrorCodes, error_code) print(f"Error: {error_name}") # Output: "INVALID_GROUP_NAME" ``` -------------------------------- ### Initialize and Use Gripper Interface Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/errors.md Instantiate a GripperInterface and perform an open action. The interface type is automatically determined on the first call. ```python from pymoveit2 import GripperInterface gripper = GripperInterface( node=node, gripper_joint_names=["gripper_joint1", "gripper_joint2"], open_gripper_joint_positions=[0.04, 0.04], closed_gripper_joint_positions=[0.0, 0.0], ) # Interface selected automatically during first call gripper.open() # Determines which interface to use ``` -------------------------------- ### Configure Panda Gripper with GripperCommand Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/configuration.md Initialize a GripperCommand for a Panda robot, specifying joint names, open/closed positions, maximum effort, and the action server name. This is an alternative to MoveIt2Gripper. ```python from pymoveit2 import GripperCommand from pymoveit2.robots import panda gripper = GripperCommand( node=node, gripper_joint_names=panda.gripper_joint_names(), open_gripper_joint_positions=[0.04, 0.04], closed_gripper_joint_positions=[0.0, 0.0], max_effort=170.0, gripper_command_action_name="gripper_action_controller/gripper_command", ) ``` -------------------------------- ### GripperCommand Constructor Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/gripper-api.md Initializes the GripperCommand class. Use this for direct gripper control via action servers. ```python GripperCommand( node: Node, gripper_joint_names: List[str], open_gripper_joint_positions: Union[float, List[float]], closed_gripper_joint_positions: Union[float, List[float]], max_effort: float = 0.0, ignore_new_calls_while_executing: bool = True, callback_group: Optional[CallbackGroup] = None, gripper_command_action_name: str = "gripper_action_controller/gripper_command", ) ``` -------------------------------- ### Initialize MoveIt2Servo Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/servo-api.md Instantiate the MoveIt2Servo class with a ROS 2 node and specify the reference frame. Optional parameters allow for speed scaling and initial enabling. ```python import rclpy from pymoveit2 import MoveIt2Servo node = rclpy.create_node("servo_example") servo = MoveIt2Servo( node=node, frame_id="panda_link0", linear_speed=0.5, angular_speed=0.5, enable_at_init=True, ) ``` -------------------------------- ### PyMoveIt2 Entry Points Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/INDEX.md Imports for the main classes, enums, robot presets, and utilities in PyMoveIt2. ```python # Main classes from pymoveit2 import MoveIt2, MoveIt2Gripper, GripperCommand, GripperInterface, MoveIt2Servo # Enums from pymoveit2 import MoveItState # Robot presets from pymoveit2 import robots from pymoveit2.robots import panda, ur, kinova, lbr, crane_x7, phantomx_pincher # Utilities from pymoveit2.utils import enum_to_str ``` -------------------------------- ### Initialize MoveIt2 Interface Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/moveit2-api.md Instantiate the MoveIt2 interface with necessary robot parameters. Ensure ROS 2 node and robot-specific details like joint names, base link, and end-effector name are provided. ```python import rclpy from pymoveit2 import MoveIt2 from pymoveit2.robots import panda node = rclpy.create_node("moveit2_example") moveit2 = MoveIt2( node=node, joint_names=panda.joint_names(), base_link_name=panda.base_link_name(), end_effector_name=panda.end_effector_name(), group_name="arm", ) ``` -------------------------------- ### Real-Time Servo Control with MoveIt2Servo Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/INDEX.md Demonstrates setting up and using MoveIt2Servo for real-time Cartesian and joint velocity commands. Requires a node and a frame ID. ```python from pymoveit2 import MoveIt2Servo servo = MoveIt2Servo( node=node, frame_id="panda_link0", linear_speed=0.5, angular_speed=0.5, ) # Cartesian velocity command servo.servo(linear=(1.0, 0.0, 0.0)) # Joint velocity command servo.servo_jog( joint_names=("panda_joint1", "panda_joint2"), velocities=(0.5, -0.3), ) ``` -------------------------------- ### GripperInterface Constructor Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/gripper-api.md Initializes the GripperInterface, which selects between MoveIt2Gripper and GripperCommand. ```APIDOC ## GripperInterface Constructor ### Description Initializes the GripperInterface, which selects between MoveIt2Gripper and GripperCommand based on available actions. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **node** (Node) - Required - ROS 2 node * **gripper_joint_names** (List[str]) - Required - Names of gripper joints * **open_gripper_joint_positions** (List[float]) - Required - Positions when open * **closed_gripper_joint_positions** (List[float]) - Required - Positions when closed * **gripper_group_name** (str) - Optional - Planning group name, defaults to "gripper" * **execute_via_moveit** (bool) - Optional - Whether to execute via MoveIt, defaults to False * **ignore_new_calls_while_executing** (bool) - Optional - Ignore concurrent requests, defaults to False * **skip_planning** (bool) - Optional - Skip planning phase, defaults to False * **skip_planning_fixed_motion_duration** (float) - Optional - Duration for direct trajectory, defaults to 0.5 * **max_effort** (float) - Optional - Max effort for GripperCommand interface, defaults to 0.0 * **callback_group** (Optional[CallbackGroup]) - Optional - ROS 2 callback group, defaults to None * **follow_joint_trajectory_action_name** (str) - Optional - DEPRECATED, defaults to "DEPRECATED" * **gripper_command_action_name** (str) - Optional - GripperCommand action server name, defaults to "gripper_action_controller/gripper_cmd" * **use_move_group_action** (bool) - Optional - Use MoveGroup action, defaults to False ### Request Example ```python from pymoveit2 import GripperInterface from pymoveit2.robots import panda gripper = GripperInterface( node=node, gripper_joint_names=panda.gripper_joint_names(), open_gripper_joint_positions=[0.04, 0.04], closed_gripper_joint_positions=[0.0, 0.0], ) # Interface is automatically selected at runtime gripper.open() gripper.close() ``` ### Response None ``` -------------------------------- ### GripperInterface Methods Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/gripper-api.md All methods from both MoveIt2Gripper and GripperCommand are available through GripperInterface. ```APIDOC ## GripperInterface Methods All methods from both `MoveIt2Gripper` and `GripperCommand` are available: ### open() #### Description Open the gripper. #### Method `open(self, skip_if_noop: bool = False) -> None` ### close() #### Description Close the gripper. #### Method `close(self, skip_if_noop: bool = False) -> None` ### move_to_position() #### Description Move gripper to a specific position. #### Method `move_to_position(self, position: float) -> None` ### toggle() #### Description Toggle gripper between open and closed states. #### Method `toggle(self) -> None` ``` -------------------------------- ### GripperCommand Constructor Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/gripper-api.md Initializes the GripperCommand class with specified parameters for controlling a gripper. ```APIDOC ## GripperCommand Constructor ### Description Initializes the GripperCommand class with specified parameters for controlling a gripper. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **node** (Node) - Required - ROS 2 node * **gripper_joint_names** (List[str]) - Required - Names of gripper joints * **open_gripper_joint_positions** (Union[float, List[float]]) - Required - Position(s) when open * **closed_gripper_joint_positions** (Union[float, List[float]]) - Required - Position(s) when closed * **max_effort** (float) - Optional - Maximum effort when closing (N), defaults to 0.0 * **ignore_new_calls_while_executing** (bool) - Optional - Ignore requests while executing, defaults to True * **callback_group** (Optional[CallbackGroup]) - Optional - ROS 2 callback group, defaults to None * **gripper_command_action_name** (str) - Optional - Action server name, defaults to "gripper_action_controller/gripper_command" ### Request Example ```python from pymoveit2 import GripperCommand gripper = GripperCommand( node=node, gripper_joint_names=["panda_finger_joint1", "panda_finger_joint2"], open_gripper_joint_positions=[0.04, 0.04], closed_gripper_joint_positions=[0.0, 0.0], max_effort=170.0, ) ``` ### Response None ``` -------------------------------- ### Launch MoveIt 2 Move Group Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/INDEX.md Launches the move_group node with your robot's configuration. Replace [robot] with your specific robot name. ```bash ros2 launch [robot]_moveit_config move_group.launch.py ``` -------------------------------- ### MoveIt2 Constructor: Execution Mode Selection Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/configuration.md Choose between using the MoveGroup action for combined planning and execution, or separate planning services and execution actions. The latter is generally recommended. ```python # Mode 1: Using MoveGroup action (combines planning and execution) moveit2 = MoveIt2( node=node, joint_names=joint_names, base_link_name=base_link_name, end_effector_name=end_effector_name, use_move_group_action=True, # Planning and execution in one action ) ``` ```python # Mode 2: Using separate planning service + execution action (recommended) moveit2 = MoveIt2( node=node, joint_names=joint_names, base_link_name=base_link_name, end_effector_name=end_effector_name, use_move_group_action=False, # Default - separate planning and execution ) ``` -------------------------------- ### Reset Gripper to Open Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/gripper-api.md Use reset_open() to set the gripper to its open configuration, typically for simulated robots. ```python def reset_open(self) -> None: pass ``` -------------------------------- ### MoveIt2 Constructor Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/moveit2-api.md Initializes the MoveIt2 Python interface. It sets up the connection to the MoveIt 2 planning system and configures robot-specific parameters. ```APIDOC ## Class: MoveIt2 ### Constructor ```python MoveIt2( node: Node, joint_names: List[str], base_link_name: str, end_effector_name: str, group_name: str = "arm", execute_via_moveit: bool = False, ignore_new_calls_while_executing: bool = False, callback_group: Optional[CallbackGroup] = None, follow_joint_trajectory_action_name: str = "DEPRECATED", use_move_group_action: bool = False, ) ``` **Parameters:** | Parameter | Type | Default | Description | |-----------|------|---------|-------------| | node | Node | — | ROS 2 node this interface attaches to | | joint_names | List[str] | — | List of joint names for the robot arm | | base_link_name | str | — | Name of robot base link (reference frame) | | end_effector_name | str | — | Name of end-effector link | | group_name | str | "arm" | Planning group name for robot arm | | execute_via_moveit | bool | False | **Deprecated.** Use `use_move_group_action` instead | | ignore_new_calls_while_executing | bool | False | If True, rejects new motion requests while executing | | callback_group | Optional[CallbackGroup] | None | Optional callback group for ROS 2 communication | | follow_joint_trajectory_action_name | str | "DEPRECATED" | **Deprecated.** ExecuteTrajectory action used instead | | use_move_group_action | bool | False | If True, uses MoveGroup action for execution; otherwise uses ExecuteTrajectory action | **Example:** ```python import rclpy from pymoveit2 import MoveIt2 from pymoveit2.robots import panda node = rclpy.create_node("moveit2_example") moveit2 = MoveIt2( node=node, joint_names=panda.joint_names(), base_link_name=panda.base_link_name(), end_effector_name=panda.end_effector_name(), group_name="arm", ) ``` ``` -------------------------------- ### PyMoveIt2 Directory Structure Source: https://github.com/andrejorsula/pymoveit2/blob/main/README.md Illustrates the hierarchical organization of files and directories within the PyMoveIt2 ROS 2 package. ```bash . ├── examples/ # [dir] Examples demonstrating the use of `pymoveit2` ├── pymoveit2/ # [dir] ROS 2 launch scripts ├── robots/ # [dir] Presets for robots (data that can be extracted from URDF/SRDF) ├── gripper_command.py # Interface for Gripper that is controlled by GripperCommand ├── moveit2_gripper.py # Interface for MoveIt 2 Gripper that is controlled by JointTrajectoryController ├── moveit2_servo.py # Interface for MoveIt 2 Servo that enables real-time control in Cartesian Space └── moveit2.py # Interface for MoveIt 2 that enables planning and execution of trajectories ├── CMakeLists.txt # Colcon-enabled CMake recipe └── package.xml # ROS 2 package metadata ``` -------------------------------- ### Open Gripper Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/gripper-api.md Call the open() method to open the gripper. Use skip_if_noop=True to avoid action if the gripper is already open. ```python gripper.open() gripper.open(skip_if_noop=True) ``` -------------------------------- ### Planning a Cartesian Path with a Fraction Threshold Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/errors.md This snippet demonstrates planning a Cartesian path and setting a `cartesian_fraction_threshold`. The plan will be rejected if the completed fraction of the path is less than the specified threshold (e.g., 0.9 for 90%). ```python # Require 90% of path completion trajectory = moveit2.plan( position=[0.3, 0.2, 0.5], quat_xyzw=[0.0, 0.0, 0.0, 1.0], cartesian=True, cartesian_fraction_threshold=0.9, ) ``` -------------------------------- ### Custom Robot Configuration Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/robots-presets.md Initializes the MoveIt2 interface for a custom robot by manually providing joint names, base link, and end effector names. ```python from pymoveit2 import MoveIt2 # Define your robot's configuration arm = MoveIt2( node=node, joint_names=[ "joint_1", "joint_2", "joint_3", "joint_4", "joint_5", "joint_6", ], base_link_name="base_link", end_effector_name="tool0", group_name="manipulator", ) ``` -------------------------------- ### Move to Pose with Cartesian Planning Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/moveit2-api.md Execute motion to a target Cartesian pose using Cartesian path planning. Specify maximum step size for the Cartesian path. ```python # Move with Cartesian path planning moveit2.move_to_pose( position=[0.3, 0.2, 0.5], quat_xyzw=[0.0, 0.0, 0.0, 1.0], cartesian=True, cartesian_max_step=0.01, ) ``` -------------------------------- ### GripperInterface Methods Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/gripper-api.md Provides access to all methods from MoveIt2Gripper and GripperCommand for unified gripper control. ```python def open(self, skip_if_noop: bool = False) -> None ``` ```python def close(self, skip_if_noop: bool = False) -> None ``` ```python def move_to_position(self, position: float) -> None ``` ```python def toggle(self) -> None ``` -------------------------------- ### Custom Prefix for Namespaced Robots Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/robots-presets.md Shows how to use a custom prefix when initializing robot presets for namespaced instances. ```python from pymoveit2.robots import panda # Standard prefix joints = panda.joint_names() # ["panda_joint1", "panda_joint2", ...] # Custom prefix for multiple instances joints_1 = panda.joint_names(prefix="panda_1_") # ["panda_1_joint1", ...] joints_2 = panda.joint_names(prefix="panda_2_") # ["panda_2_joint1", ...] ``` -------------------------------- ### Configure MoveIt2Servo Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/configuration.md Initialize a MoveIt2Servo object, setting the reference frame, linear and angular speed scaling factors, and whether to enable servo at initialization. Uses default servo namespace if not specified. ```python from pymoveit2 import MoveIt2Servo servo = MoveIt2Servo( node=node, frame_id="panda_link0", namespace="", # Use default servo namespace linear_speed=0.5, # Scale linear velocity to 0.5 m/s angular_speed=0.5, # Scale angular velocity to 0.5 rad/s enable_at_init=True, ) ``` -------------------------------- ### Check Service Availability Before Planning Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/errors.md Before initiating a planning request, verify that the planning service is ready to avoid unnecessary errors. This snippet demonstrates how to check service availability and print a message if it's not ready. ```python # Verify service availability before planning if not moveit2._plan_kinematic_path_service.service_is_ready(): print("Planning service not available") return trajectory = moveit2.plan(position=[0.3, 0.2, 0.5], quat_xyzw=[0.0, 0.0, 0.0, 1.0]) ``` -------------------------------- ### Move to Pose using Tuples Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/moveit2-api.md Execute motion to a target Cartesian pose specified by position and orientation tuples. Defaults to kinematic planning. ```python # Move to pose using tuples moveit2.move_to_pose( position=[0.3, 0.2, 0.5], quat_xyzw=[0.0, 0.0, 0.0, 1.0], ) ``` -------------------------------- ### Configure Panda Gripper with MoveIt2Gripper Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/configuration.md Initialize a MoveIt2Gripper for a Panda robot, specifying joint names, open/closed positions, and gripper group name. Set skip_planning to False for standard operation. ```python from pymoveit2 import MoveIt2Gripper from pymoveit2.robots import panda gripper = MoveIt2Gripper( node=node, gripper_joint_names=panda.gripper_joint_names(), open_gripper_joint_positions=[0.04, 0.04], closed_gripper_joint_positions=[0.0, 0.0], gripper_group_name="gripper", skip_planning=False, ) ``` -------------------------------- ### PhantomX Pincher Robot Configuration Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/robots-presets.md Initializes the MoveIt2 interface for the PhantomX Pincher robot using its predefined joint and link names. ```python from pymoveit2 import MoveIt2 from pymoveit2.robots import phantomx_pincher arm = MoveIt2( node=node, joint_names=phantomx_pincher.joint_names(), base_link_name=phantomx_pincher.base_link_name(), end_effector_name=phantomx_pincher.end_effector_name(), ) ``` -------------------------------- ### Set Pose Goal using Combined or Component Formats Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/types.md Illustrates various ways to specify a pose goal for moveit2.move_to_pose, including using a Pose message, a PoseStamped message with a frame_id, or separate position, orientation, and frame_id parameters. ```python from geometry_msgs.msg import Pose, PoseStamped, Point, Quaternion # As Pose pose = Pose( position=Point(x=0.3, y=0.2, z=0.5), orientation=Quaternion(x=0.0, y=0.0, z=0.707, w=0.707), ) moveit2.move_to_pose(pose=pose) # As PoseStamped with frame pose_stamped = PoseStamped( header=Header(frame_id="panda_link0"), pose=pose, ) moveit2.move_to_pose(pose=pose_stamped) # As separate components moveit2.move_to_pose( position=[0.3, 0.2, 0.5], quat_xyzw=[0.0, 0.0, 0.707, 0.707], frame_id="panda_link0", ) ``` -------------------------------- ### Configure Gripper to Ignore New Calls While Executing Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/errors.md Set up the GripperInterface to ignore new commands while a gripper action is in progress. This prevents command queuing and ensures only the current command is processed. ```python gripper = GripperInterface( node=node, gripper_joint_names=gripper_joints, open_gripper_joint_positions=[0.04, 0.04], closed_gripper_joint_positions=[0.0, 0.0], ignore_new_calls_while_executing=True, # Queue-blocking mode ) gripper.close() # Ignore further commands until done ``` -------------------------------- ### Read MoveIt2 Properties Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/moveit2-api.md Demonstrates how to read various properties of the MoveIt2 interface, such as joint names and end-effector configuration. ```python # Read properties print(f"Joint names: {moveit2.joint_names}") print(f"End-effector: {moveit2.end_effector_name}") ``` -------------------------------- ### MoveIt2Servo Constructor Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/servo-api.md Initializes the MoveIt2Servo class, setting up real-time control for robot end-effectors. It requires a ROS 2 node and a reference frame ID for twist commands. ```APIDOC ## MoveIt2Servo Constructor ### Description Initializes the MoveIt2Servo class, setting up real-time control for robot end-effectors. It requires a ROS 2 node and a reference frame ID for twist commands. ### Parameters #### Path Parameters - **node** (Node) - Required - ROS 2 node - **frame_id** (str) - Required - Reference frame for twist commands - **namespace** (str) - Optional - Namespace for servo node topics - **linear_speed** (float) - Optional - Scaling factor for linear velocity commands - **angular_speed** (float) - Optional - Scaling factor for angular velocity commands - **enable_at_init** (bool) - Optional - If True, enable servo during initialization - **callback_group** (Optional[CallbackGroup]) - Optional - ROS 2 callback group ### Request Example ```python import rclpy from pymoveit2 import MoveIt2Servo node = rclpy.create_node("servo_example") servo = MoveIt2Servo( node=node, frame_id="panda_link0", linear_speed=0.5, angular_speed=0.5, enable_at_init=True, ) ``` ``` -------------------------------- ### GripperCommand Methods Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/gripper-api.md Common methods for controlling the gripper's state. 'skip_if_noop' can prevent redundant actions. ```python def open(self, skip_if_noop: bool = False) -> None ``` ```python def close(self, skip_if_noop: bool = False) -> None ``` ```python def move_to_position(self, position: float) -> None ``` ```python def toggle(self) -> None ``` ```python def wait_until_executed(self) -> bool ``` -------------------------------- ### Gripper Control (GripperCommand) Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/README.md Control the gripper using open(), close(), move_to_position(), or toggle() methods. ```python gripper.open() ``` ```python gripper.close() ``` ```python gripper.move_to_position() ``` ```python gripper.toggle() ``` -------------------------------- ### CraneX7 Robot Configuration Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/robots-presets.md Initializes the MoveIt2 interface for the CraneX7 robot using its predefined joint and link names. ```python from pymoveit2 import MoveIt2 from pymoveit2.robots import crane_x7 arm = MoveIt2( node=node, joint_names=crane_x7.joint_names(), base_link_name=crane_x7.base_link_name(), end_effector_name=crane_x7.end_effector_name(), ) ``` -------------------------------- ### reset_open() Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/gripper-api.md Resets the gripper to its open configuration. This is typically used for simulated robots. ```APIDOC ### reset_open() Reset gripper to open configuration (for simulated robots). ```python def reset_open(self) -> None ``` **Returns:** None ``` -------------------------------- ### update_planning_scene Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/moveit2-api.md Fetches the current planning scene from MoveIt 2. ```APIDOC ## update_planning_scene() ### Description Fetch current planning scene from MoveIt 2. ### Method Signature ```python def update_planning_scene(self) -> bool ``` ### Returns `bool` - True if successful ``` -------------------------------- ### Configure Custom Robot Arm Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/configuration.md Instantiate MoveIt2 for a custom robot by providing explicit joint names, base link, end effector, and group name. This is useful for robots not predefined in PyMoveIt2. ```python arm = MoveIt2( node=node, joint_names=[ "shoulder_pan_joint", "shoulder_lift_joint", "elbow_joint", "wrist_1_joint", "wrist_2_joint", "wrist_3_joint", ], base_link_name="base_link", end_effector_name="tool0", group_name="manipulator", ) ``` -------------------------------- ### GripperCommand Methods Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/gripper-api.md Methods available for controlling the gripper using GripperCommand. ```APIDOC ## GripperCommand Methods ### open() #### Description Open the gripper. #### Method `open(self, skip_if_noop: bool = False) -> None` ### close() #### Description Close the gripper. #### Method `close(self, skip_if_noop: bool = False) -> None` ### move_to_position() #### Description Move gripper to a specific position. #### Method `move_to_position(self, position: float) -> None` ### toggle() #### Description Toggle gripper between open and closed states. #### Method `toggle(self) -> None` ### wait_until_executed() #### Description Block until gripper motion completes. #### Method `wait_until_executed(self) -> bool` #### Returns `bool` - True if successful ``` -------------------------------- ### Control Gripper Action Source: https://github.com/andrejorsula/pymoveit2/blob/main/README.md Toggle the gripper's state or explicitly open/close it. Use 'toggle' for alternating states or 'open'/'close' for specific actions. ```bash ros2 run pymoveit2 ex_gripper.py --ros-args -p action:="toggle" ``` -------------------------------- ### Handling Service Timeouts During Planning Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/errors.md This snippet illustrates how to handle potential service timeouts when performing motion planning. If the planning service is unavailable or times out (default 3 seconds), `moveit2.plan()` will return `None`. ```python # Services have 3-second default timeouts # Results in warning logs but return None: trajectory = moveit2.plan(position=[0.3, 0.2, 0.5], quat_xyzw=[0.0, 0.0, 0.0, 1.0]) if trajectory is None: print("Planning service unavailable or timeout") ``` -------------------------------- ### Set Orientation Goal as Tuple or Quaternion Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/types.md Shows how to set an orientation goal using either a tuple (x, y, z, w) or a geometry_msgs.msg.Quaternion object. The set_orientation_goal function accepts both formats. ```python from geometry_msgs.msg import Quaternion # As tuple (x, y, z, w) moveit2.set_orientation_goal(quat_xyzw=[0.0, 0.0, 0.707, 0.707]) # As Quaternion message quat = Quaternion(x=0.0, y=0.0, z=0.707, w=0.707) moveit2.set_orientation_goal(quat_xyzw=quat) ``` -------------------------------- ### Plan Trajectory to Pose Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/moveit2-api.md Plans a trajectory to a target pose defined by position and orientation. Returns the planned trajectory or None if planning fails. ```python trajectory = moveit2.plan( position=[0.3, 0.2, 0.5], quat_xyzw=[0.0, 0.0, 0.0, 1.0], ) if trajectory: print(f"Planned {len(trajectory.points)} waypoints") else: print("Planning failed") ``` -------------------------------- ### Set Position Goal as Tuple or Point Source: https://github.com/andrejorsula/pymoveit2/blob/main/_autodocs/types.md Demonstrates setting a position goal using either a tuple of floats or a geometry_msgs.msg.Point object. Both methods are accepted by set_position_goal. ```python from geometry_msgs.msg import Point # As tuple moveit2.set_position_goal(position=[0.3, 0.2, 0.5]) # As Point message point = Point(x=0.3, y=0.2, z=0.5) moveit2.set_position_goal(position=point) ```