11 from jsk_rviz_plugins.srv
import RequestMarkerOperate
12 from jsk_rviz_plugins.msg
import TransformableMarkerOperate
13 from jsk_interactive_marker.msg
import MarkerDimensions
14 from jsk_interactive_marker.msg
import PoseStampedWithName
15 from jsk_interactive_marker.srv
import GetTransformableMarkerFocus
16 from jsk_interactive_marker.srv
import GetTransformableMarkerFocusRequest
17 from jsk_interactive_marker.srv
import SetTransformableMarkerPose
18 from jsk_interactive_marker.srv
import SetTransformableMarkerPoseRequest
19 from jsk_interactive_marker.srv
import SetTransformableMarkerColor
20 from jsk_interactive_marker.srv
import SetTransformableMarkerColorRequest
21 from jsk_interactive_marker.srv
import SetMarkerDimensions
22 from jsk_interactive_marker.srv
import SetMarkerDimensionsRequest
23 from jsk_recognition_utils.color
import labelcolormap
24 from jsk_recognition_msgs.msg
import BoundingBox
25 from jsk_recognition_msgs.msg
import BoundingBoxArray
30 if not hasattr(__builtins__,
'xrange'):
37 self.
server = rospy.resolve_name(
'~server')
41 rospy.logfatal(
"config_file '{}' does not exist"
47 osp.join(self.
server,
'request_marker_operate'),
50 osp.join(self.
server,
'set_color'), SetTransformableMarkerColor)
52 osp.join(self.
server,
'set_pose'), SetTransformableMarkerPose)
54 osp.join(self.
server,
'set_dimensions'), SetMarkerDimensions)
56 osp.join(self.
server,
'get_focus'),
57 GetTransformableMarkerFocus)
58 rospy.wait_for_service(self.
req_marker.resolved_name)
59 rospy.wait_for_service(self.
req_color.resolved_name)
60 rospy.wait_for_service(self.
req_pose.resolved_name)
61 rospy.wait_for_service(self.
req_dim.resolved_name)
62 rospy.wait_for_service(self.
req_focus.resolved_name)
70 boxes = self.
config[
'boxes']
72 cmap = labelcolormap(n_boxes)
76 frame_id = box.get(
'frame_id',
'/map')
78 type=TransformableMarkerOperate.BOX)
79 self.
set_color(name, (cmap[i][0], cmap[i][1], cmap[i][2], 0.5))
80 dim = box.get(
'dimensions', [1, 1, 1])
82 pos = box.get(
'position', [0, 0, 0])
83 ori = box.get(
'orientation', [0, 0, 0, 1])
84 self.
set_pose(box[
'name'], box[
'frame_id'], pos, ori)
86 position=Vector3(*pos),
87 orientation=Quaternion(*ori),
90 rospy.loginfo(
"Inserted transformable box '{}'.".format(name))
93 osp.join(self.
server,
'marker_dimensions'),
97 osp.join(self.
server,
'pose_with_name'),
101 do_auto_save = rospy.get_param(
'~config_auto_save',
True)
107 '~output/boxes', BoundingBoxArray, queue_size=1)
112 msg = TransformableMarkerOperate(
115 action=TransformableMarkerOperate.INSERT,
122 req = SetTransformableMarkerColorRequest()
123 req.target_name = name
124 req.color.r = rgba[0]
125 req.color.g = rgba[1]
126 req.color.b = rgba[2]
127 req.color.a = rgba[3]
131 req = SetMarkerDimensionsRequest()
132 req.target_name = name
133 req.dimensions.x = dimensions[0]
134 req.dimensions.y = dimensions[1]
135 req.dimensions.z = dimensions[2]
138 def set_pose(self, name, frame_id, position, orientation):
139 req = SetTransformableMarkerPoseRequest()
140 req.target_name = name
141 req.pose_stamped.header.frame_id = frame_id
142 req.pose_stamped.pose.position.x = position[0]
143 req.pose_stamped.pose.position.y = position[1]
144 req.pose_stamped.pose.position.z = position[2]
145 req.pose_stamped.pose.orientation.x = orientation[0]
146 req.pose_stamped.pose.orientation.y = orientation[1]
147 req.pose_stamped.pose.orientation.z = orientation[2]
148 req.pose_stamped.pose.orientation.w = orientation[3]
152 req = GetTransformableMarkerFocusRequest()
154 return res.target_name
164 bbox_array_msg = BoundingBoxArray()
165 bbox_array_msg.header.frame_id = self.
config[
'boxes'][0][
'frame_id']
166 bbox_array_msg.header.stamp = event.current_real
167 for box
in self.
config[
'boxes']:
168 bbox_msg = BoundingBox()
170 bbox_msg.header.frame_id = bbox_array_msg.header.frame_id
171 bbox_msg.header.stamp = bbox_array_msg.header.stamp
174 bbox_msg.dimensions.x = dimensions.x
175 bbox_msg.dimensions.y = dimensions.y
176 bbox_msg.dimensions.z = dimensions.z
177 bbox_array_msg.boxes.append(bbox_msg)
181 for i, box
in enumerate(self.
config[
'boxes']):
182 box_cfg = self.
config[
'boxes'][i]
183 box_cfg[
'name'] = box[
'name']
188 'frame_id': box[
'frame_id'],
209 if __name__ ==
'__main__':
210 rospy.init_node(
'transformable_markers_client')