Examples: Tool action

This document shows how to control Ned robot’s tools via the Python ROS Wrapper.

If you want see more about Ned robot’s tool package, go to Niryo robot tools commander

Danger

If you are using the real robot, make sure the environment around it is clear.

Tool control

Setup tool

In order to use a tool, it should be mechanically plugged to the robot but also recognized by the robot software.

To do that, we must use the function update_tool(). It will scan motor connections and set the new tool.

robot.update_tool()

Grasp

To grasp with any tool, you can use the function: grasp_with_tool(). This action can, depending on the tool, correspond to:

  • close the gripper

  • pull Air from a vacuum pump

  • activate an electromagnet

Simple grasping example:

 1#!/usr/bin/env python3
 2
 3from niryo_robot_python_ros_wrapper import NiryoRosWrapper
 4
 5# Instantiate the ROS wrapper and initialize the ROS node
 6robot = NiryoRosWrapper.init_with_node()
 7
 8# Calibrate if needed
 9robot.calibrate_auto()  # Only for Ned2
10
11# Setup the tool
12robot.update_tool()
13
14# Grasp
15robot.grasp_with_tool()

Advanced grasping with parameters example:

 1#!/usr/bin/env python3
 2
 3from niryo_robot_python_ros_wrapper import NiryoRosWrapper, ToolID, PinID
 4
 5# Instantiate the ROS wrapper and initialize the ROS node
 6robot = NiryoRosWrapper.init_with_node()
 7
 8# Calibrate if needed
 9robot.calibrate_auto()  # Only for Ned2
10
11# Setup the tool
12robot.update_tool()
13
14# Get the current tool ID
15current_tool_id = robot.get_current_tool_id()
16
17if current_tool_id in [ToolID.GRIPPER_1, ToolID.GRIPPER_2, ToolID.GRIPPER_3]:
18    robot.close_gripper(speed=500)
19elif current_tool_id == ToolID.ELECTROMAGNET_1:
20    electromagnet_pin = PinID.GPIO_1A  # Replace with the pin ID of your electromagnet
21    robot.setup_electromagnet(electromagnet_pin)
22    robot.activate_electromagnet(electromagnet_pin)
23elif current_tool_id in [ToolID.VACUUM_PUMP_1, ToolID.VACUUM_PUMP_2]:
24    robot.pull_air_vacuum_pump()

Release

To release with any tool, you can use the function: release_with_tool(). This action can, depending on the tool, correspond to:

  • open the gripper

  • push Air from a vacuum pump

  • deactivate an electromagnet

Simple releasing example:

 1#!/usr/bin/env python3
 2
 3from niryo_robot_python_ros_wrapper import NiryoRosWrapper
 4
 5# Instantiate the ROS wrapper and initialize the ROS node
 6robot = NiryoRosWrapper.init_with_node()
 7
 8# Calibrate if needed
 9robot.calibrate_auto()  # Only for Ned2
10
11# Setup the tool
12robot.update_tool()
13
14# Release
15robot.release_with_tool()

Advanced releasing with parameters example:

 1#!/usr/bin/env python3
 2
 3from niryo_robot_python_ros_wrapper import NiryoRosWrapper, ToolID, PinID
 4
 5# Instantiate the ROS wrapper and initialize the ROS node
 6robot = NiryoRosWrapper.init_with_node()
 7
 8# Calibrate if needed
 9robot.calibrate_auto()  # Only for Ned2
10
11# Setup the tool
12robot.update_tool()
13
14# Get the current tool ID
15current_tool_id = robot.get_current_tool_id()
16
17if current_tool_id in [ToolID.GRIPPER_1, ToolID.GRIPPER_2, ToolID.GRIPPER_3]:
18    robot.open_gripper(speed=500)
19elif current_tool_id == ToolID.ELECTROMAGNET_1:
20    electromagnet_pin = PinID.GPIO_1A  # Replace with the pin ID of your electromagnet
21    robot.setup_electromagnet(electromagnet_pin)
22    robot.deactivate_electromagnet(electromagnet_pin)
23elif current_tool_id in [ToolID.VACUUM_PUMP_1, ToolID.VACUUM_PUMP_2]:
24    robot.push_air_vacuum_pump()