Skip to content

Commit e595cfd

Browse files
author
Yuxiang Gao
committed
grasp data sending
1 parent 8a562a4 commit e595cfd

File tree

6 files changed

+29
-12
lines changed

6 files changed

+29
-12
lines changed

ropi_msgs/msg/GraspData.msg

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
geometry_msgs/Point center
2-
float32 radius
1+
geometry_msgs/Point position
2+
geometry_msgs/Point target_position
3+
float32 diameter
34
float32 angle
45
float32 height

ropi_msgs/msg/GraspDataArray.msg

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ropi_msgs/GraspData[] data

ropi_msgs/srv/MoveObjects.srv

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ ropi_msgs/RegionSelectionMsg source_selection
22
ropi_msgs/RegionSelectionMsg target_selection
33
---
44
bool success
5-
ropi_msgs/GraspData[] pick_data
6-
ropi_msgs/GraspData[] place_data
5+
ropi_msgs/GraspData[] object_data
76
string message

ropi_tangible_surface/scripts/pick_and_place.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def move_joints(self, joints, duration=3.0):
193193
self.joints_pos_start = joints
194194
rospy.loginfo('[move_joints] Result: {}'.format(self.client.wait_for_result()))
195195
finish_state = self.client.get_state()
196-
if (not finish_state == UR_STATES['ACTIVE'] or not finish_state == UR_STATES['SUCCEEDED']):
196+
if (not finish_state == UR_STATES['ACTIVE'] and not finish_state == UR_STATES['SUCCEEDED']):
197197
raise UR5MissionError(finish_state, inspect.stack()[0][3])
198198
except KeyboardInterrupt:
199199
self.client.cancel_goal()
@@ -223,7 +223,7 @@ def move_traj(self, traj, duration=3.0):
223223
# self.client.wait_for_result()
224224
rospy.loginfo('[move_traj] Result: {}'.format(self.client.wait_for_result()))
225225
finish_state = self.client.get_state()
226-
if (not finish_state == UR_STATES['ACTIVE'] or finish_state == UR_STATES['SUCCEEDED']):
226+
if (not finish_state == UR_STATES['ACTIVE'] and not finish_state == UR_STATES['SUCCEEDED']):
227227
raise UR5MissionError(finish_state, inspect.stack()[0][3])
228228
except KeyboardInterrupt:
229229
self.client.cancel_goal()
@@ -259,7 +259,7 @@ def find_ik(self, traj):
259259
# pt: [[x,y], angle]
260260
def pick_and_place(self, pt1, pt2, object_height, object_diameter=0.14):
261261
try:
262-
self.gripper_sc.move_to(np.clip(object_diameter + 0.02, 0, 0.14))
262+
self.gripper_sc.move_to(np.clip(object_diameter + 0.05, 0, 0.14))
263263
traj = self.generate_trajectory(pt1, pt2, object_height)
264264
# print('traj: {}'.format(traj))
265265
self.move_traj(traj[:2])

ropi_tangible_surface/scripts/ropi_tangible_surface/object_detection.py

+12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import cv2
66
import tf
77

8+
from ropi_msgs.msg import GraspData
9+
from geometry_msgs.msg import Point
10+
811
class GraspDataClass:
912
def __init__(self, position, diameter, angle, height):
1013
self.position = np.asarray(position)
@@ -26,6 +29,15 @@ def draw(self, img, color):
2629
cv2.line(debug_img, pt1, pt2, color, 5)
2730
return debug_img
2831

32+
def make_msg(self):
33+
msg = GraspData()
34+
msg.position = Point(self.position[0], self.position[1], self.height)
35+
if self.target_position is not None:
36+
msg.target_position = Point(self.target_position[0], self.target_position[1], self.height)
37+
msg.diameter = self.diameter
38+
msg.height = self.height
39+
msg.angle = self.angle
40+
2941
def __repr__(self):
3042
return '[GraspDataClass]: {}-{}-|Height: {}|Angle: {} |Diameter: {}'.format(self.position, self.target_position, self.height,self.angle, self.diameter)
3143
# return repr(self.position)

ropi_tangible_surface/scripts/tangible_surface.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def subscribe(self, img_topic, depth_topic):
8181
'delete_selection', DeleteSelection, self.delete_selection_callback)
8282
self.move_server = rospy.Service(
8383
'move_objects', MoveObjects, self.move_objects_callback)
84+
self.grasp_pub = rospy.Publisher('grasp_data', GraspData, queue_size=1)
8485

8586
def detect_objects_in_region(self, msg):
8687
self.selection_manager.update([msg])
@@ -99,6 +100,8 @@ def move_objects_callback(self, req):
99100
response.success = True
100101
response.message = '{} source objects detected.'.format(len(mission))
101102
rospy.loginfo('mission generated, executing mission.')
103+
# response.object_data = [x.make_msg() for x in mission]
104+
# self.grasp_pub.publish([x.make_msg() for x in mission])
102105
try:
103106
self.robot_interface.pick_and_place_mission(mission)
104107
except:
@@ -161,9 +164,9 @@ def region_selection_callback(self, req):
161164
grasp_data = []
162165
for gp in grasp_points:
163166
grasp_datum = GraspData()
164-
grasp_datum.center.x = gp.center[0]
165-
grasp_datum.center.y = gp.center[1]
166-
grasp_datum.radius = gp.radius
167+
grasp_datum.position.x = gp.position[0]
168+
grasp_datum.position.y = gp.position[1]
169+
grasp_datum.diameter = gp.diameter
167170
grasp_datum.angle = gp.angle
168171
grasp_datum.height = gp.height
169172
grasp_data.append(grasp_datum)
@@ -294,7 +297,7 @@ def detect_fingertip(self, img):
294297

295298
def detect_object(self, img):
296299
objects = []
297-
threshed = my_threshold(img, 15, 150)
300+
threshed = my_threshold(img, 5, 150)
298301
mask = np.zeros(img.shape, dtype=np.uint8)
299302
mask[threshed > 0] = 255
300303
dst = img.copy()
@@ -304,7 +307,8 @@ def detect_object(self, img):
304307
merge_list = lambda l1, l2: l2 if not l1 else (l1 if not l2 else np.concatenate((l1, l2)))
305308
object_contours = []
306309
if len(contours) != 0:
307-
contours = filter(lambda c: cv2.contourArea(c) > 400 and cv2.contourArea(c) < 1500, contours)
310+
# print([cv2.contourArea(c) for c in contours])
311+
contours = filter(lambda c: cv2.contourArea(c) > 400 and cv2.contourArea(c) < 3000, contours)
308312
debug_img = dst.copy()
309313
objects = self.object_detector.update(contours, dst, debug_img)
310314
debug_img = self.object_detector.debug_img

0 commit comments

Comments
 (0)