33 """ Map a ROS msg dict to API """
34 if not isinstance(msg, dict):
35 raise ValueError(
"msg is not a dict: {}".format(msg))
36 if rostype ==
'shape_msgs/Plane':
38 return {
'normal': {
'x': c[0],
'y': c[1],
'z': c[2]},
'distance': c[3]}
39 elif rostype ==
'rc_reason_msgs/CalibrateBasePlaneRequest':
40 new_msg = copy.deepcopy(msg)
41 if msg[
'plane_estimation_method'] ==
'STEREO':
42 new_msg[
'stereo'] = {
'plane_preference': msg[
'stereo_plane_preference']}
43 del new_msg[
'stereo_plane_preference']
45 elif rostype ==
'rc_reason_msgs/LoadCarrierModel':
46 new_msg = copy.deepcopy(msg)
48 new_msg[
'pose'] = msg[
'pose'][
'pose']
49 new_msg[
'pose_frame'] = msg[
'pose'][
'header'][
'frame_id']
51 elif rostype
in [
'rc_reason_msgs/DetectLoadCarriersRequest',
52 'rc_reason_msgs/DetectFillingLevelRequest',
53 'rc_reason_msgs/DetectTagsRequest',
54 'rc_reason_msgs/SilhouetteMatchDetectObjectRequest',
55 'rc_reason_msgs/CadMatchDetectObjectRequest']:
56 new_msg = copy.deepcopy(msg)
58 if msg[
'pose_frame'] !=
'external':
59 del new_msg[
'robot_pose']
61 elif rostype
in [
'rc_reason_msgs/ComputeGraspsRequest']:
62 new_msg = {k: msg[k]
for k
in [
'pose_frame',
'item_models',
'suction_surface_length',
'suction_surface_width']}
64 if msg[
'pose_frame'] ==
'external':
65 new_msg[
'robot_pose'] = msg[
'robot_pose']
66 if msg[
'region_of_interest_id']:
67 new_msg[
'region_of_interest_id'] = msg[
'region_of_interest_id']
68 if msg[
'load_carrier_id']:
69 new_msg[
'load_carrier_id'] = msg[
'load_carrier_id']
70 if all([msg[
'load_carrier_compartment'][
'box'][k] > 0
for k
in [
'x',
'y',
'z']]):
71 new_msg[
'load_carrier_compartment'] = msg[
'load_carrier_compartment']
72 if msg[
'collision_detection'][
'gripper_id']:
73 new_msg[
'collision_detection'] = msg[
'collision_detection']
75 elif rostype
in [
'rc_reason_msgs/DetectItemsRequest']:
76 new_msg = {k: msg[k]
for k
in [
'pose_frame',
'item_models']}
78 if msg[
'pose_frame'] ==
'external':
79 new_msg[
'robot_pose'] = msg[
'robot_pose']
80 if msg[
'region_of_interest_id']:
81 new_msg[
'region_of_interest_id'] = msg[
'region_of_interest_id']
82 if msg[
'load_carrier_id']:
83 new_msg[
'load_carrier_id'] = msg[
'load_carrier_id']
84 if all([msg[
'load_carrier_compartment'][
'box'][k] > 0
for k
in [
'x',
'y',
'z']]):
85 new_msg[
'load_carrier_compartment'] = msg[
'load_carrier_compartment']
87 elif rostype ==
'rc_reason_msgs/RegionOfInterest3D':
88 new_msg = {
'id': msg[
'id'],
'pose': msg[
'pose'][
'pose'],
'pose_frame': msg[
'pose'][
'header'][
'frame_id']}
89 d = msg[
'primitive'][
'dimensions']
90 if msg[
'primitive'][
'type'] == 1:
91 new_msg[
'type'] =
'BOX'
92 new_msg[
'box'] = {
'x': d[0],
'y': d[1],
'z': d[2]}
93 elif msg[
'primitive'][
'type'] == 2:
94 new_msg[
'type'] =
'SPHERE'
95 new_msg[
'sphere'] = {
'radius': d[0]}
97 elif rostype
in [
'rc_reason_msgs/SetLoadCarrierRequest']:
98 new_msg = copy.deepcopy(msg)
100 if not msg[
'load_carrier'][
'pose_frame']:
101 del new_msg[
'load_carrier'][
'pose']
109 if 'pose_frame' not in msg:
113 if key
not in [
'pose',
'pose_frame',
'timestamp']:
114 new_msg[key] = msg[key]
115 header = {
'frame_id': msg[
'pose_frame']}
116 stamp = msg.get(
'timestamp', timestamp)
117 if stamp
is not None:
118 header[
'stamp'] = stamp
119 new_msg[
'pose'] = {
'pose': msg[
'pose'],
'header': header}
124 """ Map an API msg to ROS """
125 if not isinstance(msg, dict):
126 raise ValueError(
"msg is not a dict: {}".format(msg))
127 if rostype ==
'rc_reason_msgs/DetectedTag':
129 header = {
'stamp': msg[
'timestamp'],
'frame_id': msg[
'pose_frame']}
130 new_msg[
'header'] = header
131 new_msg[
'tag'] = {
'id': msg[
'id'],
'size': msg[
'size']}
132 new_msg[
'pose'] = {
'pose': msg[
'pose'],
'header': header}
133 new_msg[
'instance_id'] = msg[
'instance_id']
135 elif rostype ==
'shape_msgs/Plane':
136 return {
'coef': [msg[
'normal'][
'x'], msg[
'normal'][
'y'], msg[
'normal'][
'z'], msg[
'distance']]}
137 elif rostype
in [
'rc_reason_msgs/GetBasePlaneCalibrationResponse',
'rc_reason_msgs/CalibrateBasePlaneResponse']:
138 new_msg = copy.deepcopy(msg)
139 new_msg[
'pose_frame'] = msg[
'plane'][
'pose_frame']
140 del new_msg[
'plane'][
'pose_frame']
142 elif rostype
in [
'rc_reason_msgs/LoadCarrier',
143 'rc_reason_msgs/LoadCarrierModel'
146 elif rostype
in [
'rc_reason_msgs/ComputeGraspsResponse',
147 'rc_reason_msgs/DetectFillingLevelResponse',
148 'rc_reason_msgs/DetectLoadCarriersResponse',
149 'rc_reason_msgs/DetectItemsResponse',
150 'rc_reason_msgs/CadMatchDetectObjectResponse'
152 new_msg = {k: v
for k, v
in msg.items()
if k
not in [
'load_carriers']}
153 new_msg[
'load_carriers'] = []
154 for lc
in msg[
'load_carriers']:
157 elif rostype
in [
'rc_reason_msgs/SuctionGrasp']:
158 new_msg = {k: v
for k, v
in msg.items()
if k
not in [
'pose',
'pose_frame',
'timestamp',
'type']}
159 header = {
'stamp': msg[
'timestamp'],
'frame_id': msg[
'pose_frame']}
160 new_msg[
'pose'] = {
'pose': msg[
'pose'],
'header': header}
162 elif rostype
in [
'rc_reason_msgs/Item']:
164 elif rostype ==
'rc_reason_msgs/RegionOfInterest3D':
165 new_msg = {
'id': msg[
'id']}
166 header = {
'frame_id': msg[
'pose_frame']}
167 new_msg[
'pose'] = {
'pose': msg[
'pose'],
'header': header}
168 if msg[
'type'] ==
'BOX':
169 new_msg[
'primitive'] = {
'type': 1,
'dimensions': [msg[
'box'][
'x'], msg[
'box'][
'y'], msg[
'box'][
'z']]}
170 elif msg[
'type'] ==
'SPHERE':
171 new_msg[
'primitive'] = {
'type': 2,
'dimensions': [msg[
'sphere'][
'radius']]}
173 elif rostype ==
'rc_reason_msgs/SilhouetteMatchDetectObjectResponse':
174 new_msg = {
'timestamp': msg[
'timestamp']}
175 new_msg[
'matches'] = msg[
'instances']
176 new_msg[
'grasps'] = msg.get(
'grasps', [])
177 new_msg[
'load_carriers'] = []
178 for lc
in msg[
'load_carriers']:
180 new_msg[
'object_id'] = msg[
'object_id']
182 elif rostype ==
'rc_reason_msgs/Match':
185 if 'object_id' in new_msg:
186 new_msg[
'template_id'] = new_msg[
'object_id']
187 del new_msg[
'object_id']
189 if 'uuid' not in new_msg:
190 new_msg[
'uuid'] = msg[
'id']
193 if 'score' not in new_msg:
194 new_msg[
'score'] = -1.0
196 elif rostype ==
'rc_reason_msgs/Grasp':
199 if 'instance_uuid' in new_msg:
200 new_msg[
'match_uuid'] = msg[
'instance_uuid']
201 del new_msg[
'instance_uuid']