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, PinID
4from niryo_robot_tools_commander.api.tools_ros_wrapper_enums import ToolID
5
6# Instantiate the ROS wrapper and initialize the ROS node
7robot = NiryoRosWrapper.init_with_node()
8
9# Calibrate if needed
10robot.calibrate_auto() # Only for Ned2
11
12# Setup the tool
13robot.update_tool()
14
15# Get the current tool ID
16current_tool_id = robot.get_current_tool_id()
17
18if current_tool_id in [ToolID.GRIPPER_1, ToolID.GRIPPER_2, ToolID.GRIPPER_3]:
19 robot.close_gripper(speed=500)
20elif current_tool_id == ToolID.ELECTROMAGNET_1:
21 electromagnet_pin = PinID.GPIO_1A # Replace with the pin ID of your electromagnet
22 robot.setup_electromagnet(electromagnet_pin)
23 robot.activate_electromagnet(electromagnet_pin)
24elif current_tool_id in [ToolID.VACUUM_PUMP_1, ToolID.VACUUM_PUMP_2]:
25 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, PinID
4from niryo_robot_tools_commander.api.tools_ros_wrapper_enums import ToolID
5
6# Instantiate the ROS wrapper and initialize the ROS node
7robot = NiryoRosWrapper.init_with_node()
8
9# Calibrate if needed
10robot.calibrate_auto() # Only for Ned2
11
12# Setup the tool
13robot.update_tool()
14
15# Get the current tool ID
16current_tool_id = robot.get_current_tool_id()
17
18if current_tool_id in [ToolID.GRIPPER_1, ToolID.GRIPPER_2, ToolID.GRIPPER_3]:
19 robot.open_gripper(speed=500)
20elif current_tool_id == ToolID.ELECTROMAGNET_1:
21 electromagnet_pin = PinID.GPIO_1A # Replace with the pin ID of your electromagnet
22 robot.setup_electromagnet(electromagnet_pin)
23 robot.deactivate_electromagnet(electromagnet_pin)
24elif current_tool_id in [ToolID.VACUUM_PUMP_1, ToolID.VACUUM_PUMP_2]:
25 robot.push_air_vacuum_pump()