### PyNiryo Vision Header Setup Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/examples/examples_vision.rst This snippet includes the necessary header code for PyNiryo vision examples, likely involving imports and initial robot connection setup. It serves as a common starting point for vision-related operations. ```python from pyniryo import * # Initialize the robot (replace with your robot's IP address) robot = NiryoRobot("10.10.10.10") # Go to the initial position robot.move_to_initial_position() # Set the workspace robot.set_workspace("workspace_1") ``` -------------------------------- ### Install Sphinx Dependencies Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/README_DEV.md Installs the necessary dependencies for Sphinx documentation from a requirements file. It is recommended to perform this installation within a Python virtual environment. ```bash pip install -r docs/requirements.txt ``` -------------------------------- ### Install PyNiryo from GitHub Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/setup/installation.rst Installs the PyNiryo library by cloning the GitHub repository and then installing it locally. This method is useful for developers who want the latest code or to contribute to the project. ```bash git clone https://github.com/NiryoRobotics/pyniryo.git pip install ./pyniryo ``` -------------------------------- ### PyNiryo: Execute a Pick and Place Operation Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/examples/examples_basics.rst Illustrates a pick-and-place algorithm using PyNiryo. This example includes initializing the robot connection, calibrating it, equipping a tool, opening the gripper, moving to a pick pose, grasping an object, moving to a place pose, and releasing the object, followed by closing the connection. ```Python from pyniryo import NiryoRobot, PARALLEL_JAW, UP robot = NiryoRobot("YOUR_ROBOT_IP") robot.calibrate_auto() ``` ```Python robot.update_tool(PARALLEL_JAW, UP) ``` ```Python robot.release_with_tool() robot.move(target_pose_1) robot.grasp_with_tool() ``` ```Python robot.move(target_pose_2) robot.release_with_tool() ``` ```Python robot.close_connection() ``` -------------------------------- ### Install PyNiryo via PyPI Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/setup/installation.rst Installs the PyNiryo library from the Python Package Index (PyPI) using pip. This is the recommended method for most users. ```bash pip install pyniryo ``` -------------------------------- ### Install PyNiryo using pip Source: https://github.com/niryorobotics/pyniryo/blob/master/README.rst This command installs the PyNiryo library using pip, the Python package installer. Ensure you have Python and pip installed on your system. ```bash pip install pyniryo ``` -------------------------------- ### Get and Display Image from Stream (Python) Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/vision/image_processing_overview.rst Retrieves a compressed image from the robot's video stream, uncompresses it, and displays it. The function `get_img_compressed` fetches the image, `uncompress_image` decodes it, and `show_img_and_wait_close` displays it until a key is pressed. ```Python from pyniryo import vision # Get image from stream img_compressed = robot.get_img_compressed() # Uncompress image img = vision.uncompress_image(img_compressed) # Display image and wait for user input to close vision.show_img_and_wait_close(img) ``` -------------------------------- ### Verify Niryo Robot Setup with Python Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/setup/verify_setup.rst This Python script verifies the Niryo robot setup. It connects to the robot, performs a calibration sequence, and moves the robot to learning mode. Ensure the robot's IP address is correctly configured in the script. ```Python from pyniryo import * robot = NiryoOne("192.168.1.10") robot.calibrate_all_motors() robot.move_to_learning_mode() robot.set_learning_mode(False) print("Robot setup verified successfully!") ``` -------------------------------- ### PyNiryo Vision Conditioning - Multiple Objects Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/examples/examples_vision.rst This example shows how to pick and place multiple objects sequentially, arranging them in a straight line. It iterates until a specified number of objects are caught, calculating the placement position based on the catch count and an offset size. ```python max_catch_count = 5 offset_size = 0.05 catch_count = 0 while catch_count < max_catch_count: # Go to observation pose robot.move_pose(0.1, 0.0, 0.2, 0, 0, 0) # Perform vision pick shape_ret, color_ret, obj_found = robot.vision_pick(object_to_pick='any', shift_height=0.05, min_x=-0.3, max_x=0.3, min_y=-0.3, max_y=0.3, min_z=0.0, max_z=0.1) # If pick failed, wait and continue if not obj_found: time.sleep(0.1) continue # Calculate new place position place_x = 0.1 + catch_count * offset_size robot.place_from_vision(shape=shape_ret, color=color_ret, shift_height=0.05, x=place_x, y=0.0, z=0.05) # Increment catch count catch_count += 1 # Go to sleep after all catches robot.change_speed(50) robot.go_to_sleep() ``` -------------------------------- ### Create and Use Dynamic Frame for Pick and Place (Python) Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/examples/examples_frames.rst This Python example illustrates the process of creating a dynamic frame and executing a simple pick and place sequence within that defined frame. It requires the pyniryo library. ```Python from pyniryo import NiryoRobot from pyniryo.helpers import * robot = NiryoRobot("10.10.10.10") # Go to the initial position robot.move_to_home_positions() # Define a new dynamic frame robot.create_dynamic_frame(name="my_frame", x_translation=0.1, y_translation=0.0, z_translation=0.0, roll=0.0, pitch=0.0, yaw=0.0) # Move to the created frame robot.move_pose(frame_id="my_frame") # Pick an object (example) robot.move_pose(x_translation=0.0, y_translation=0.0, z_translation=0.05, frame_id="my_frame") robot.open_gripper() robot.move_pose(x_translation=0.0, y_translation=0.0, z_translation=0.0, frame_id="my_frame") robot.close_gripper() # Place the object (example) robot.move_pose(x_translation=0.1, y_translation=0.0, z_translation=0.05, frame_id="my_frame") robot.open_gripper() robot.move_pose(x_translation=0.1, y_translation=0.0, z_translation=0.0, frame_id="my_frame") # Return to home position robot.move_to_home_positions() robot.close_connection() ``` -------------------------------- ### Sphinx Live Reload Server Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/README_DEV.md Starts a local development server that automatically rebuilds and reloads the documentation in the browser whenever changes are detected. The `--open-browser` flag automatically opens the server URL. ```bash sphinx-autobuild . _build/html --open-browser ``` -------------------------------- ### PyNiryo: Perform a Basic Move Joint Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/examples/examples_basics.rst Demonstrates a simple MoveJ action using the PyNiryo library. It covers importing the library, establishing a connection to the robot via its IP address, calibrating the robot, and executing a joint movement by specifying axis positions in radians. ```Python from pyniryo import NiryoRobot ``` ```Python robot = NiryoRobot("YOUR_ROBOT_IP") ``` ```Python robot.calibrate_auto() ``` ```Python robot.move(JointsPosition(0.0, 1.047, -0.349, 0.0, 0.0, 0.0)) ``` ```Python robot.close_connection() ``` -------------------------------- ### Multi Reference Conditioning with Python Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/examples/examples_vision.rst Demonstrates how to align objects based on their color during a conditioning task. It uses the `vision_pick` function and sorts objects into columns based on their detected color. ```Python import time from niryo_one_python_api.niryo_one_robot import NiryoOneRobot from niryo_one_python_api.utils import ObjectColor, ObjectShape # Connection to the robot robot = NiryoOneRobot("10.10.10.10") try: robot.calibrate_to_initial_pose() robot.update_tool() # Update the tool max_failure_count = 5 count_dict = {ObjectColor.RED: 0, ObjectColor.BLUE: 0, ObjectColor.GREEN: 0} max_catch_count = 2 for color in count_dict: count_dict[color] = 0 for color in count_dict: if count_dict[color] < max_catch_count: # Go to observation pose robot.move_to_observation_pose() # Try to make a Vision pick status, observation_data = robot.vision_pick(ObjectColor.RED, ObjectShape.CUBE) if status == "fail": # Increment failure counter try_without_success += 1 time.sleep(0.1) else: # Compute new place position place_position = (0.2, 0.1, 0.05 + count_dict[observation_data["color"]] * 0.05, 0, 0, 0) # Place the object robot.place_from_vision(place_position) # Increment count_dict and reset try_without_success count_dict[observation_data["color"]] += 1 try_without_success = 0 # Go to sleep robot.go_to_sleep_pose() except Exception as e: print(e) finally: # Disconnect the robot robot.disconnect() ``` -------------------------------- ### Uninstall PyNiryo Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/setup/installation.rst Uninstalls the PyNiryo library from the Python environment using pip. ```bash pip uninstall pyniryo ``` -------------------------------- ### Install OpenCV for Vision Functions Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/setup/installation.rst Installs the OpenCV library, which is required for using PyNiryo's vision functions for image processing. ```bash pip install opencv-python ``` -------------------------------- ### Color Thresholding (Python) Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/vision/image_processing_overview.rst Performs color thresholding on an image to detect objects of a specific color. This example demonstrates thresholding for blue and red colors using HSV parameters, utilizing the `threshold_hsv` function from the `pyniryo.vision` module. ```Python from pyniryo import vision from pyniryo.vision.enums import ColorHSV # Assuming 'img' is loaded image # Threshold for Blue color using enum blue_mask = vision.threshold_hsv(img, ColorHSV.BLUE.value) blue_img = vision.apply_mask(img, blue_mask) # Threshold for Red color using custom HSV values # (Example custom values, replace with actual desired range) red_lower_hsv = [160, 100, 100] red_upper_hsv = [180, 255, 255] red_mask = vision.threshold_hsv(img, [red_lower_hsv, red_upper_hsv]) red_img = vision.apply_mask(img, red_mask) # Display results (example) vision.show_img(blue_img) vision.show_img(red_img) ``` -------------------------------- ### PyNiryo Simple Vision Pick and Place Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/examples/examples_vision.rst Demonstrates a basic pick and place operation using the robot's vision capabilities. It involves moving to an observation pose, performing a vision pick, and then placing the object. The snippet highlights the `vision_pick` function and checks if an object was successfully found and picked. ```python # Go to the observation pose robot.move_pose(0.1, 0.0, 0.2, 0, 0, 0) # Perform a vision pick shape_ret, color_ret, obj_found = robot.vision_pick(object_to_pick='any', shift_height=0.05, min_x=-0.3, max_x=0.3, min_y=-0.3, max_y=0.3, min_z=0.0, max_z=0.1) # Place the object if found if obj_found: robot.place_from_vision(shape=shape_ret, color=color_ret, shift_height=0.05, min_x=-0.3, max_x=0.3, min_y=-0.3, max_y=0.3, min_z=0.0, max_z=0.1) # Turn learning mode on robot.set_learning_mode(True) ``` -------------------------------- ### Control Niryo Robot Conveyor Belt Motor Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/examples/examples_conveyor.rst This Python example demonstrates how to connect to the Niryo Robot and control its conveyor belt motor by setting its speed and direction. ```Python from pyniryo import NiryoRobot robot = NiryoRobot("10.10.10.10") # Connect to the robot robot.connect() # Set conveyor speed and direction # Speed can be from -100 to 100. Negative values mean reverse direction. robot.set_conveyor(50) # Wait for 2 seconds robot.wait(2.0) # Stop the conveyor robot.set_conveyor(0) # Disconnect from the robot robot.disconnect() ``` -------------------------------- ### Sorting Pick with Conveyor Belt in Python Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/examples/examples_vision.rst Demonstrates how to pick specific objects using a conveyor belt. The robot stops the conveyor when a target object is detected and then picks it. ```Python import time from niryo_one_python_api.niryo_one_robot import NiryoOneRobot from niryo_one_python_api.utils import ObjectColor, ObjectShape # Connection to the robot robot = NiryoOneRobot("10.10.10.10") try: robot.calibrate_to_initial_pose() robot.update_tool() shape_expected = ObjectShape.CIRCLE color_expected = ObjectColor.RED max_catch_count = 4 try_without_success = 0 max_failure_count = 5 # Activate connection with the Conveyor Belt robot.conveyor_belt_on() while try_without_success < max_failure_count: # Run the Conveyor Belt robot.conveyor_belt_on() # Go to the observation pose robot.move_to_observation_pose() # Check if the target object is in the workspace status, observation_data = robot.vision_pick(color_expected, shape_expected) if status == "fail": # Wait and start a new iteration time.sleep(0.5) try_without_success += 1 else: # Stop the Conveyor Belt and try to make a Vision pick robot.conveyor_belt_off() # Compute new place pose place_position = (0.1, -0.1, 0.05, 0, 0, 0) # Place the object robot.place_from_vision(place_position) # Increment catch count and reset failure counter max_catch_count -= 1 try_without_success = 0 # Stop the Conveyor Belt and go to sleep robot.conveyor_belt_off() robot.go_to_sleep_pose() except Exception as e: print(e) finally: # Disconnect the robot robot.disconnect() ``` -------------------------------- ### PyNiryo Short Template Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/examples/code_templates.rst A very simple and straightforward Python code template for PyNiryo. It serves as a basic starting point for PyNiryo projects. ```Python from niryo_one_python_api.niryo_one_api import * def main(): # Initialize the connection to the Niryo robot niryo = NiryoOneAPI( ஆய்வகம்_ip='10.10.10.10') try: # Connect to the robot niryo.connect() # Reset the robot to its initial position niryo.reset_to_initial_position() # --- Your code here --- # Move the robot to a specific position # niryo.move_pose(x=0.1, y=0.0, z=0.1, roll=0.0, pitch=0.0, yaw=0.0) # Get the robot's current pose # pose = niryo.get_current_pose() # print(pose) # --- End of your code --- # Move the robot back to its initial position niryo.reset_to_initial_position() except Exception as e: print(e) finally: # Disconnect from the robot niryo.disconnect() if __name__ == '__main__': main() ``` -------------------------------- ### Display Video Stream with Workspace Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/vision/image_processing_overview.rst Shows how to display the live video stream from the robot's camera along with the extracted workspace. This allows for real-time monitoring and integration of custom image processing. ```Python from pyniryo.vision.image_functions import extract_img_workspace from pyniryo.utils.vision_utils import VisionUtils import cv2 # Initialize VisionUtils vision_utils = VisionUtils() while True: # Get the current camera frame frame = vision_utils.get_img() # Extract workspace from the frame workspace_frame = extract_img_workspace(frame) # Display the original frame and the workspace frame cv2.imshow('Camera Stream', frame) cv2.imshow('Extracted Workspace', workspace_frame) # Break the loop if 'q' is pressed if cv2.waitKey(1) & 0xFF == ord('q'): break cv2.destroyAllWindows() ``` -------------------------------- ### Advanced Niryo Robot Conveyor Belt Control with Infrared Sensor Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/examples/examples_conveyor.rst This Python example showcases advanced control of the Niryo Robot's conveyor belt, enabling pick and place operations using the infrared sensor to detect objects. ```Python from pyniryo import NiryoRobot robot = NiryoRobot("10.10.10.10") # Connect to the robot robot.connect() # Start the conveyor belt robot.set_conveyor(30) # Loop to detect objects and perform pick & place while True: # Check if an object is detected by the infrared sensor if robot.get_infrared_proximity_sensor(1) > 500: # Threshold may need adjustment # Stop the conveyor robot.set_conveyor(0) # Move the robot arm to pick the object # (Add your pick and place arm movement code here) # Example: robot.move_arm_to_pose(pick_pose) # robot.open_gripper() # robot.move_arm_to_pose(place_pose) # robot.close_gripper() # Restart the conveyor after placing the object robot.set_conveyor(30) # Add a small delay to avoid excessive CPU usage robot.wait(0.1) # Disconnect from the robot (this part might not be reached in an infinite loop) # robot.disconnect() ``` -------------------------------- ### Morphological Transformations Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/vision/image_processing_overview.rst Demonstrates morphological transformations on images, such as erosion and closing, to preprocess images for contour detection. These operations help in noise reduction and shape refinement. ```Python from pyniryo.vision.image_functions import * # Load an image (replace with your image path) img = cv2.imread('path/to/your/image.jpg') # Apply morphological transformations # Erode eroded_img = erode(img) # Close closed_img = close(img) # Display results (optional) # cv2.imshow('Original', img) # cv2.imshow('Eroded', eroded_img) # cv2.imshow('Closed', closed_img) # cv2.waitKey(0) # cv2.destroyAllWindows() ``` -------------------------------- ### PyNiryo: PoseObject with Offsets Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/examples/examples_movement.rst Explains how to use the `PoseObject` to create new poses with applied offsets, simplifying incremental movements. The `copy_with_offsets` method allows modifying specific coordinates (x, y, z, roll, pitch, yaw) of a pose object. ```python from pyniryo.api.tcp_client import NiryoRobot from pyniryo.api.objects import PoseObject # Assuming 'robot' is an initialized NiryoRobot instance # robot = NiryoRobot(ip='192.168.1.100') pick_pose = PoseObject(x=0.30, y=0.0, z=0.15, roll=0, pitch=1.57, yaw=0.0) first_place_pose = PoseObject(x=0.0, y=0.2, z=0.15, roll=0, pitch=1.57, yaw=0.0) for i in range(5): robot.move(pick_pose) # Create a new pose with an offset in the x-direction new_place_pose = first_place_pose.copy_with_offsets(x_offset=0.05 * i) robot.move(new_place_pose) ``` -------------------------------- ### Debug Vision Functions Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/vision/image_processing_overview.rst Provides debugging functions like `debug_threshold_color` and `debug_markers` to visualize intermediate steps in the robot's vision processing. This helps in diagnosing issues by showing what the robot 'sees'. ```Python from pyniryo.vision.image_functions import debug_threshold_color, debug_markers import cv2 # Assume 'img' is the original image and 'lower_bound', 'upper_bound' are color thresholds # Debug threshold color # debug_img_color = debug_threshold_color(img, lower_bound, upper_bound) # cv2.imshow('Debug Threshold Color', debug_img_color) # Debug markers (assuming markers are detected) # debug_img_markers = debug_markers(img) # cv2.imshow('Debug Markers', debug_img_markers) # cv2.waitKey(0) # cv2.destroyAllWindows() ``` -------------------------------- ### Vision Pick with Custom Pipeline Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/vision/image_processing_overview.rst Demonstrates how to perform a vision pick operation by converting a relative pose in the workspace to a target pose in the robot's world coordinates. This enables the robot to grasp objects based on visual input. ```Python from pyniryo.api.tcp_client import NiryoRobot from pyniryo.vision.image_functions import biggest_contours_finder, get_contour_barycenter, get_contour_angle, extract_img_workspace import cv2 # Assume robot is connected and initialized # robot = NiryoRobot(ip_address='YOUR_ROBOT_IP') # Get current image and extract workspace # img = robot.get_image() # Replace with actual method to get image # workspace_img = extract_img_workspace(img) # Find contours in the workspace image # contours, hierarchy = biggest_contours_finder(workspace_img, 1) # Find 1 biggest contour # if contours: # # Get center and angle # center_x, center_y = get_contour_barycenter(contours[0]) # angle = get_contour_angle(contours[0], workspace_img) # # Define relative pose (adjust based on your object and gripper) # # Example: Pose relative to the contour center # relative_pose = { # "x": center_x, # "y": center_y, # "roll": 0, # "pitch": 0, # "yaw": angle # Use the calculated angle # } # # Get target pose in robot's world coordinates # # target_pose = robot.get_target_pose_from_rel(relative_pose) # # Move robot to target pose (example) # # robot.move_pose(target_pose) # else: # print("No object found for picking.") # robot.close_connection() ``` -------------------------------- ### PyNiryo: Move Robot Joints Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/examples/examples_movement.rst Demonstrates how to move the robot's joints to specific positions using the `move` function or the `joints` setter. It utilizes the `JointsPosition` object to define target joint angles. Ensure the robot is connected and calibrated before execution. ```python from pyniryo.api.tcp_client import NiryoRobot from pyniryo.api.objects import JointsPosition # Assuming 'robot' is an initialized NiryoRobot instance # robot = NiryoRobot(ip='192.168.1.100') # Example using the move function robot.move(JointsPosition(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)) # Example using the joints setter robot.joints = JointsPosition(-0.2, 0.3, 0.2, 0.3, -0.6, 0.0) ``` -------------------------------- ### PyNiryo: Move Robot to Pose Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/examples/examples_movement.rst Illustrates how to move the robot's end-effector to a specific pose in space using the `move` function or the `pose` setter. The `PoseObject` is used to define the target position (x, y, z) and orientation (roll, pitch, yaw). ```python from pyniryo.api.tcp_client import NiryoRobot from pyniryo.api.objects import PoseObject # Assuming 'robot' is an initialized NiryoRobot instance # robot = NiryoRobot(ip='192.168.1.100') pose_target = PoseObject(x=0.2, y=0.0, z=0.2, roll=0.0, pitch=0.0, yaw=0.0) # Moving Pose with function robot.move(pose_target) # Moving Pose with setter robot.pose = pose_target ``` -------------------------------- ### Undistort and Display Video Stream (Python) Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/vision/image_processing_overview.rst Displays both the raw and undistorted video streams from the robot's camera. It fetches camera intrinsics, undistorts the raw image using `undistort_image`, concatenates the raw and undistorted images using `concat_imgs`, and displays the result with `show_img`. ```Python from pyniryo import vision # Get camera intrinsics camera_intrinsics = robot.get_camera_intrinsics() # Get raw image from stream img_compressed = robot.get_img_compressed() img = vision.uncompress_image(img_compressed) # Undistort image undistorted_img = vision.undistort_image(img, camera_intrinsics) # Concatenate raw and undistorted images final_img = vision.concat_imgs(img, undistorted_img) # Display the concatenated image vision.show_img(final_img) ``` -------------------------------- ### Preview Generated Sphinx HTML Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/README_DEV.md Opens the generated HTML documentation in the default web browser. The path points to the index file within the HTML build directory. ```bash x-www-browser _build/html/index.html ``` -------------------------------- ### PyNiryo: Get Robot Joint Positions Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/examples/examples_movement.rst Shows how to retrieve the current joint positions of the robot. This can be done using the `get_joints` function or the `joints` getter. Both methods return a `JointsPosition` object representing the current angles of each joint. ```python from pyniryo.api.tcp_client import NiryoRobot # Assuming 'robot' is an initialized NiryoRobot instance # robot = NiryoRobot(ip='192.168.1.100') # Get joints using the function joints_read_func = robot.get_joints() # Get joints using the getter joints_read_getter = robot.joints ``` -------------------------------- ### PyNiryo: Get Robot End-Effector Pose Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/examples/examples_movement.rst Demonstrates how to obtain the current pose of the robot's end-effector. This can be achieved using the `get_pose` function or the `pose` getter, both of which return a `PoseObject` containing the end-effector's position and orientation. ```python from pyniryo.api.tcp_client import NiryoRobot # Assuming 'robot' is an initialized NiryoRobot instance # robot = NiryoRobot(ip='192.168.1.100') # Getting Pose with function pose_read_func = robot.get_pose() # Getting Pose with getter pose_read_getter = robot.pose ``` -------------------------------- ### Build Sphinx HTML Documentation Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/README_DEV.md Generates the HTML output for the Sphinx documentation. This command should be run from within the Sphinx directory. ```bash make html ``` -------------------------------- ### PyNiryo: Simple Reference Conditioning Source: https://github.com/niryorobotics/pyniryo/blob/master/examples/vision_demonstrators/README.md Demonstrates picking any object from a working area and conditioning it in a packing area as an NxM rectangular grid. It requires user-defined robot IP, tool, and workspace name. Optional parameters include grid dimensions, vision processing location, display stream, and various poses. ```Python import time from pyniryo import NiryoRobot, MoveItInterface ROBOT_IP = "192.168.1.100" TOOL_USED = "gripper" WORKSPACE_NAME = "my_workspace" def main(): robot = NiryoRobot(ROBOT_IP) moveit = MoveItInterface(robot) # --- User defined variables --- robot_ip_address = ROBOT_IP tool_used = TOOL_USED workspace_name = WORKSPACE_NAME # --- User can change --- grid_dimension = (3, 3) vision_process_on_robot = False display_stream = False # --- User may change --- observation_pose = [ 0.0, 0.0, 0.2, 0.0, 0.0, 0.0, # Example pose ] center_conditioning_pose = [ 0.0, 0.0, 0.1, 0.0, 0.0, 0.0, # Example pose ] sleep_pose = [ 0.0, 0.0, 0.3, 0.0, 0.0, 0.0, # Example pose ] print("Starting Simple Reference Conditioning...") # Example: Move to observation pose # moveit.move_to_pose(observation_pose) # Example: Pick and place logic would go here # ... print("Simple Reference Conditioning finished.") robot.close_connection() if __name__ == "__main__": main() ``` -------------------------------- ### PyNiryo Pick & Place - All in One Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/examples/examples_tool_action.rst Performs a complete pick and place operation using a single PyNiryo function `pick_and_place`. This is the most concise method for executing the entire sequence. ```python from pyniryo import NiryoRobot, ToolID, PinID from pyniryo.helpers import PoseObject def pick_n_place_version_3(robot: NiryoRobot): # Define pick and place poses pick_pose = PoseObject(x=0.3, y=0.1, z=0.05, qx=0.707, qy=0, qz=0.707, qw=0) place_pose = PoseObject(x=0.3, y=-0.1, z=0.05, qx=0.707, qy=0, qz=0.707, qw=0) # Execute the pick and place operation in one command robot.pick_and_place(pick_pose, place_pose) ``` -------------------------------- ### Extract Workspace Markers Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/vision/image_processing_overview.rst Extracts the workspace from an image using the `extract_img_workspace` function. This is useful for defining the operational area for the robot. ```Python from pyniryo.vision.image_functions import extract_img_workspace import cv2 # Load the original image original_image = cv2.imread('path/to/your/image.jpg') # Extract the workspace workspace_image = extract_img_workspace(original_image) # Display results (optional) # cv2.imshow('Original Image', original_image) # cv2.imshow('Extracted Workspace', workspace_image) # cv2.waitKey(0) # cv2.destroyAllWindows() ``` -------------------------------- ### PyNiryo Pick & Place - Pick/Place from Pose Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/examples/examples_tool_action.rst Utilizes dedicated PyNiryo functions `pick_from_pose` and `place_from_pose` to simplify pick and place operations. This method splits the action into two main commands. ```python from pyniryo import NiryoRobot, ToolID, PinID from pyniryo.helpers import PoseObject def pick_n_place_version_2(robot: NiryoRobot): # Define pick and place poses pick_pose = PoseObject(x=0.3, y=0.1, z=0.05, qx=0.707, qy=0, qz=0.707, qw=0) place_pose = PoseObject(x=0.3, y=-0.1, z=0.05, qx=0.707, qy=0, qz=0.707, qw=0) # Pick the object from the defined pose robot.pick_from_pose(pick_pose) # Place the object at the defined pose robot.place_from_pose(place_pose) ``` -------------------------------- ### PyNiryo Pick & Place - Heaviest Solution Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/examples/examples_tool_action.rst Implements a pick and place operation where all steps, including pose computation, are handled manually. This provides the most granular control over the process. ```python from pyniryo import NiryoRobot, ToolID, PinID def pick_n_place_version_1(robot: NiryoRobot): # Go to the object's position with an offset robot.move_pose(PoseObject(x=0.3, y=0.1, z=0.2, qx=0.707, qy=0, qz=0.707, qw=0)) # Go down to the object's height robot.move_pose(PoseObject(x=0.3, y=0.1, z=0.05, qx=0.707, qy=0, qz=0.707, qw=0)) # Grasp the object robot.close_gripper(speed=500) # Go back to the initial offset position robot.move_pose(PoseObject(x=0.3, y=0.1, z=0.2, qx=0.707, qy=0, qz=0.707, qw=0)) # Go to the place position with an offset robot.move_pose(PoseObject(x=0.3, y=-0.1, z=0.2, qx=0.707, qy=0, qz=0.707, qw=0)) # Go down to the place's height robot.move_pose(PoseObject(x=0.3, y=-0.1, z=0.05, qx=0.707, qy=0, qz=0.707, qw=0)) # Release the object robot.open_gripper(speed=500) # Go back to the initial offset position robot.move_pose(PoseObject(x=0.3, y=-0.1, z=0.2, qx=0.707, qy=0, qz=0.707, qw=0)) ``` -------------------------------- ### PyNiryo: Conditioning and Packing with 2 Workspaces Source: https://github.com/niryorobotics/pyniryo/blob/master/examples/vision_demonstrators/README.md Demonstrates using Ned's vision with two workspaces: one for picking and one for packing. The robot detects a pack place, picks an object from the picking area, packs it, and then places the pack on the side of the working area. Requires user-defined robot IP, tool, and two workspace names. ```Python import time from pyniryo import NiryoRobot, MoveItInterface ROBOT_IP = "192.168.1.100" TOOL_USED = "gripper" WORKSPACE1_NAME = "picking_workspace" WORKSPACE2_NAME = "packing_workspace" def main(): robot = NiryoRobot(ROBOT_IP) moveit = MoveItInterface(robot) # --- User defined variables --- robot_ip_address = ROBOT_IP tool_used = TOOL_USED workspace1_name = WORKSPACE1_NAME workspace2_name = WORKSPACE2_NAME # --- User may change --- observation_pose = [ 0.0, 0.0, 0.2, 0.0, 0.0, 0.0, # Example pose ] center_conditioning_pose = [ 0.0, 0.0, 0.1, 0.0, 0.0, 0.0, # Example pose ] sleep_pose = [ 0.0, 0.0, 0.3, 0.0, 0.0, 0.0, # Example pose ] print("Starting Conditioning and Packing with 2 Workspaces...") # Example: Move to observation pose # moveit.move_to_pose(observation_pose) # Example: Detection, pick, pack, and place logic would go here # ... print("Conditioning and Packing with 2 Workspaces finished.") robot.close_connection() if __name__ == "__main__": main() ``` -------------------------------- ### Clean Sphinx Build Files Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/README_DEV.md Removes previously generated documentation files. This command is useful for ensuring a clean build. ```bash make clean ``` -------------------------------- ### Find Biggest Contours Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/vision/image_processing_overview.rst Extracts the biggest contours from a black and white image based on their area. This function is useful for identifying and isolating objects in an image for further analysis. ```Python from pyniryo.vision.image_functions import biggest_contours_finder import cv2 # Load a binary image (replace with your image path) binary_img = cv2.imread('path/to/your/binary_image.jpg', 0) # Read as grayscale # Find the 3 biggest contours contours, hierarchy = biggest_contours_finder(binary_img, 3) # Draw contours on the original image (optional) # img_with_contours = cv2.drawContours(original_image.copy(), contours, -1, (0, 255, 0), 2) # cv2.imshow('Image with Contours', img_with_contours) # cv2.waitKey(0) # cv2.destroyAllWindows() ``` -------------------------------- ### Release with Tool using PyNiryo Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/examples/examples_tool_action.rst Performs a release action with the currently equipped tool. This corresponds to opening a gripper, pushing air for a vacuum pump, or deactivating an electromagnet. ```python robot.release_with_tool() ``` ```python if tool_used in [ToolID.GRIPPER_1, ToolID.GRIPPER_2, ToolID.GRIPPER_3]: robot.open_gripper(speed=500) elif tool_used == ToolID.ELECTROMAGNET_1: pin_electromagnet = PinID.XXX robot.setup_electromagnet(pin_electromagnet) robot.deactivate_electromagnet(pin_electromagnet) elif tool_used == ToolID.VACUUM_PUMP_1: robot.push_air_vacuum_pump() ``` -------------------------------- ### PyNiryo: Multiple Reference Conditioning by Color Source: https://github.com/niryorobotics/pyniryo/blob/master/examples/vision_demonstrators/README.md Demonstrates using Ned's vision for conditioning objects based on their color. Objects are arranged in a grid where the Y-axis represents color (BLUE/RED/GREEN) and the X-axis determines the number of objects per line before increasing height. Requires user-defined robot IP, tool, and workspace name. ```Python import time from pyniryo import NiryoRobot, MoveItInterface ROBOT_IP = "192.168.1.100" TOOL_USED = "gripper" WORKSPACE_NAME = "my_workspace" def main(): robot = NiryoRobot(ROBOT_IP) moveit = MoveItInterface(robot) # --- User defined variables --- robot_ip_address = ROBOT_IP tool_used = TOOL_USED workspace_name = WORKSPACE_NAME # --- User can change --- grid_dimension = (3, 3) # X axis: objects per line, Y axis: color (e.g., 0:BLUE, 1:RED, 2:GREEN) # --- User may change --- observation_pose = [ 0.0, 0.0, 0.2, 0.0, 0.0, 0.0, # Example pose ] center_conditioning_pose = [ 0.0, 0.0, 0.1, 0.0, 0.0, 0.0, # Example pose ] sleep_pose = [ 0.0, 0.0, 0.3, 0.0, 0.0, 0.0, # Example pose ] print("Starting Multiple Reference Conditioning by Color...") # Example: Move to observation pose # moveit.move_to_pose(observation_pose) # Example: Color detection and conditioning logic would go here # ... print("Multiple Reference Conditioning by Color finished.") robot.close_connection() if __name__ == "__main__": main() ``` -------------------------------- ### Find Object Center and Orientation Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/vision/image_processing_overview.rst Calculates the barycenter (center of mass) and orientation angle of detected contours. This is crucial for determining the grasp pose of an object, prioritizing width over length for gripper compatibility. ```Python from pyniryo.vision.image_functions import get_contour_barycenter, get_contour_angle import cv2 # Assume 'contours' is a list of contours obtained from biggest_contours_finder # Assume 'binary_img' is the image used to find contours # Example: Process the first contour found if contours: center_x, center_y = get_contour_barycenter(contours[0]) angle = get_contour_angle(contours[0], binary_img) print(f"Center: ({center_x}, {center_y})") print(f"Angle: {angle} degrees") # Draw center and angle on the image (optional) # cv2.circle(image_to_draw_on, (center_x, center_y), 5, (0, 0, 255), -1) # ... code to draw the angle vector ... else: print("No contours found.") ``` -------------------------------- ### Morphological Transformations (Python) Source: https://github.com/niryorobotics/pyniryo/blob/master/docs/vision/image_processing_overview.rst Applies morphological transformations to an image, typically binary images, to refine shapes. This function `morphological_transformations` uses `MorphoType` and `KernelType` enums to perform operations like Closing and Erosion. ```Python from pyniryo import vision from pyniryo.vision.enums import MorphoType, KernelType # Assuming 'img' is a binary image loaded or processed # Example: Apply Closing transformation # Closing is dilation followed by erosion closed_img = vision.morphological_transformations(img, MorphoType.CLOSING, KernelType.KERNEL_3X3) # Example: Apply Erosion transformation eroded_img = vision.morphological_transformations(img, MorphoType.EROSION, KernelType.KERNEL_5X5) # Display results (example) vision.show_img(closed_img) vision.show_img(eroded_img) ```