зеркало из https://github.com/microsoft/roman.git
added move_and_grasp
This commit is contained in:
Родитель
38590cd931
Коммит
1b00cb583f
|
@ -1,28 +0,0 @@
|
||||||
import os
|
|
||||||
rootdir = os.path.dirname(os.path.dirname(__file__))
|
|
||||||
os.sys.path.insert(0, rootdir)
|
|
||||||
|
|
||||||
# this brings in most of the relevant parts. It requires numpy, scipy and pybullet
|
|
||||||
import math
|
|
||||||
import random
|
|
||||||
from roman import *
|
|
||||||
|
|
||||||
def rand(max):
|
|
||||||
return (random.random()-0.5)*max
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
# connect to robot.
|
|
||||||
robot = connect(use_sim=True)
|
|
||||||
|
|
||||||
# move the arm in small relative increments
|
|
||||||
t_step = 0.1
|
|
||||||
r_step = 1
|
|
||||||
for i in range(5):
|
|
||||||
robot.move_simple(rand(t_step), rand(t_step), rand(t_step), rand(r_step), max_speed = 0.5)
|
|
||||||
|
|
||||||
# now step instead (sustain the move for a fixed time)
|
|
||||||
for i in range(40):
|
|
||||||
robot.step(rand(t_step), rand(t_step), rand(t_step), rand(r_step), max_speed = 1, max_acc=1)
|
|
||||||
|
|
||||||
robot.disconnect()
|
|
||||||
|
|
|
@ -87,19 +87,6 @@ class Robot:
|
||||||
self.__check_connected()
|
self.__check_connected()
|
||||||
return self.hand.state.object_detected()
|
return self.hand.state.object_detected()
|
||||||
|
|
||||||
def move_simple(self, dx, dy, dz, dyaw, max_speed=0.5, max_acc=0.5, timeout=0.2):
|
|
||||||
'''
|
|
||||||
Moves the arm relative to the current position in carthesian coordinates,
|
|
||||||
assuming the gripper is vertical (aligned with the z-axis), pointing down.
|
|
||||||
This version returns after the amount of time specified by dt.
|
|
||||||
'''
|
|
||||||
self.__check_connected()
|
|
||||||
self.arm.read()
|
|
||||||
pose = self.arm.state.tool_pose()
|
|
||||||
pose = Tool.from_xyzrpy(pose.to_xyzrpy() + [dx, dy, dz, 0, 0, dyaw])
|
|
||||||
self.arm.move(pose, max_speed=max_speed, max_acc=max_acc, blocking=False)
|
|
||||||
self.__complete_move(timeout, None)
|
|
||||||
|
|
||||||
def get_inverse_kinematics(self, target):
|
def get_inverse_kinematics(self, target):
|
||||||
self.__check_connected()
|
self.__check_connected()
|
||||||
return self.arm.get_inverse_kinematics(target)
|
return self.arm.get_inverse_kinematics(target)
|
||||||
|
@ -170,6 +157,21 @@ class Robot:
|
||||||
blocking=False)
|
blocking=False)
|
||||||
return self.__complete_move(timeout, completion)
|
return self.__complete_move(timeout, completion)
|
||||||
|
|
||||||
|
def move_and_grasp(self,
|
||||||
|
arm_target,
|
||||||
|
max_speed=UR_DEFAULT_MAX_SPEED,
|
||||||
|
max_acc=UR_DEFAULT_ACCELERATION,
|
||||||
|
force_limit=None,
|
||||||
|
max_final_speed=0,
|
||||||
|
grasp_target=Position.CLOSED,
|
||||||
|
grasp_speed=255,
|
||||||
|
grasp_force=0,
|
||||||
|
timeout=None,
|
||||||
|
completion=None):
|
||||||
|
self.__check_connected()
|
||||||
|
self.hand.move(position=grasp_target, speed=grasp_speed, force=grasp_force, blocking=False)
|
||||||
|
return self.move(target=arm_target, max_speed=max_speed, max_acc=max_acc, force_limit=force_limit, max_final_speed=max_final_speed, timeout=timeout, completion=completion)
|
||||||
|
|
||||||
def set_hand_mode(self, mode=GraspMode.BASIC):
|
def set_hand_mode(self, mode=GraspMode.BASIC):
|
||||||
self.__check_connected()
|
self.__check_connected()
|
||||||
self.hand.set_mode(mode)
|
self.hand.set_mode(mode)
|
||||||
|
|
|
@ -172,6 +172,11 @@ class Hand:
|
||||||
self.command.make(Command._CMD_KIND_CHANGE, Finger.All, 0, 0, 0, mode)
|
self.command.make(Command._CMD_KIND_CHANGE, Finger.All, 0, 0, 0, mode)
|
||||||
self.__execute(True)
|
self.__execute(True)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
def normalize(position):
|
def normalize(position):
|
||||||
return position / 255
|
return position / 255
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def from_normalized(position):
|
||||||
|
return int(position * 255)
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче