38 print(
"> Request to align frame {} with frame {} mode {}".format(request.name, request.source_name, request.mode))
40 response = AlignFrameResponse()
41 response.error_code = 0
43 if request.name ==
"":
44 print(
" Error: No name given")
45 response.error_code = 1
47 elif request.source_name ==
"":
48 print(
" Error: No source name given")
49 response.error_code = 3
51 elif request.name
not in self.editor.frames:
52 print(
" Error: Frame not found: {}".format(request.name))
53 response.error_code = 2
56 frame = self.editor.frames[request.name]
60 if m & 1: mode.append(
"x")
61 if m & 2: mode.append(
"y")
62 if m & 4: mode.append(
"z")
63 if m & 8: mode.append(
"a")
64 if m & 16: mode.append(
"b")
65 if m & 32: mode.append(
"c")
73 print(
"> Request to edit frame {}".format(request.name))
75 response = EditFrameResponse()
76 response.error_code = 0
78 if request.name ==
"":
82 elif request.name
not in self.editor.frames:
83 print(
" Error: Frame not found: {}".format(request.name))
84 response.error_code = 2
94 print(
"> Request to get frame {}".format(request.name))
96 response = GetFrameResponse()
97 response.error_code = 0
99 if request.name ==
"":
100 print(
" Error: No name given")
101 response.error_code = 1
103 elif request.name
not in self.editor.frames:
104 print(
" Error: Frame not found: {}".format(request.name))
105 response.error_code = 2
108 f = self.editor.frames[request.name]
110 response.name = f.name
111 response.parent = f.parent
112 response.pose =
ToPose(f.position, f.orientation)
118 print(
"> Request to remove frame {}".format(request.name))
120 response = RemoveFrameResponse()
121 response.error_code = 0
123 if request.name ==
"":
124 print(
" Error: No name given")
125 response.error_code = 1
127 elif request.name
not in self.editor.frames:
128 print(
" Error: Frame not found: {}".format(request.name))
129 response.error_code = 2
138 print(
"> Request to set (or add) frame {} {}".format(request.name, request.parent))
140 response = SetFrameResponse()
142 if request.name ==
"":
143 print(
" Error: No name given")
144 response.error_code = 1
147 if request.parent ==
"":
148 if request.name
in self.editor.frames:
149 request.parent = self.editor.frames[request.name].parent
151 print(
"Error: No parent given and frame previously not existing")
152 response.error_code = 2
155 f =
Frame(request.name,
161 response.error_code = 0
166 print(
"> Request to set parent_frame {} {}".format(request.name, request.parent))
168 response = SetParentFrameResponse()
169 response.error_code = 0
171 if request.name ==
"":
172 print(
" Error: No frame_name given")
173 response.error_code = 1
175 elif request.parent ==
"":
176 print(
" Error: No parent_name given")
177 response.error_code = 2
180 f = self.editor.frames[request.name]
186 print(
"> Request to load yaml file:'{}'".format(request.filename))
188 response = LoadYamlResponse()
190 self.editor.load_file(os.path.expanduser(request.filename))
191 response.success =
True 192 response.message =
"file loaded" 193 except Exception
as e:
194 response.success =
False 195 response.message =
"Exception: {}".format(str(e))
200 print(
"> Request to save yaml file to:'{}'".format(request.filename))
202 response = SaveYamlResponse()
204 self.editor.save_file(os.path.expanduser(request.filename))
205 response.success =
True 206 response.message =
"file saved" 207 except Exception
as e:
208 response.success =
False 209 response.message =
"Exception: {}".format(str(e))
214 print(
"> Request to copy frame '{}' with new name '{}' and new parent name '{}'".format(request.source_name, request.name, request.parent))
216 response = CopyFrameResponse()
217 response.error_code = 0
219 if request.name ==
"":
220 print(
" Error: No name given")
221 response.error_code = 1
223 elif request.source_name ==
"":
224 print(
" Error: No source name given")
225 response.error_code = 3
232 if request.name
not in self.editor.frames:
236 if request.parent ==
"":
237 if request.source_name
in self.editor.frames:
238 request.parent = self.editor.frames[request.source_name].parent
240 print(
" Error: No parent name given")
241 response.error_code = 3
244 Frame.wait_for_transform(request.source_name, request.parent, rospy.Duration(1.0))
246 Frame.wait_for_transform(request.parent, request.name, rospy.Duration(1.0))
250 frame = self.editor.frames[request.name]
252 Frame.wait_for_transform(request.source_name, request.parent, rospy.Duration(1.0))
253 if (request.parent !=
"")
and (frame.parent != request.parent):
259 Frame.wait_for_transform(frame.parent, frame.name, rospy.Duration(1.0))
261 except Exception
as e:
262 print(
"Error: unhandled exception {}".format(e))
263 response.error_code = 9
265 print(time.time() - t)
def callback_load_yaml(self, request)
def callback_set_parent_frame(self, request)
def callback_edit_frame(self, request)
def callback_copy_frame(self, request)
def __init__(self, frame_editor)
def callback_remove_frame(self, request)
def callback_get_frame(self, request)
def callback_align_frame(self, request)
def callback_save_yaml(self, request)
def callback_set_frame(self, request)