Skip to content

Commit 841033f

Browse files
ipa-pgtLorenz Halt
authored andcommitted
headless version
1 parent 4ed840c commit 841033f

File tree

4 files changed

+98
-61
lines changed

4 files changed

+98
-61
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ rqt
5858
roslaunch frame_editor frame_editor.launch
5959
```
6060

61+
#### A headless version is available through this launch file:
62+
63+
```
64+
roslaunch frame_editor frame_editor_headless.launch
65+
```
66+
6167
### Known issues:
6268
#### Starting the plugin twice
6369
When starting the rqt plugin twice, you will receive a long error message with these last lines:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0"?>
2+
3+
<launch>
4+
<node pkg="frame_editor" type="editor.py" name="frame_editor"
5+
args="--load '$(find frame_editor)/etc/frames.yaml'"
6+
output="screen"/>
7+
</launch>

frame_editor/src/frame_editor/editor.py

Lines changed: 79 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/usr/bin/env python
22

3+
import os
4+
import sys
5+
36
import time
47
import threading
58
import yaml
@@ -16,6 +19,12 @@
1619
from python_qt_binding import QtCore
1720
from python_qt_binding.QtWidgets import QUndoStack
1821

22+
## Views
23+
from frame_editor.interface_interactive_marker import FrameEditor_InteractiveMarker
24+
from frame_editor.interface_services import FrameEditor_Services
25+
from frame_editor.interface_markers import FrameEditor_Markers
26+
from frame_editor.interface_tf import FrameEditor_TF
27+
1928

2029
class FrameEditor(QtCore.QObject):
2130

@@ -24,7 +33,7 @@ def __init__(self):
2433

2534
self.frames = {}
2635
self.active_frame = None
27-
36+
2837
## Undo/Redo
2938
self.observers = []
3039
self.undo_level = 0
@@ -164,7 +173,7 @@ def load_data(self, data):
164173
f.set_color(color)
165174
else:
166175
f = Frame(name, position, orientation, frame["parent"])
167-
176+
168177
self.command(Command_AddElement(self, f))
169178

170179
self.undo_stack.endMacro()
@@ -198,13 +207,13 @@ def save_file(self, filename):
198207

199208
if frame.style == "plane":
200209
f["data"] = { "length": frame.length, "width":frame.width, "color": frame.color }
201-
210+
202211
elif frame.style == "cube":
203212
f["data"] = { "length": frame.length, "width": frame.width, "height": frame.height , "color": frame.color}
204-
213+
205214
elif frame.style == "sphere":
206215
f["data"] = { "diameter": frame.diameter, "color": frame.color }
207-
216+
208217
elif frame.style == "axis":
209218
f["data"] = { "length": frame.length, "width": frame.width, "color": frame.color }
210219

@@ -258,17 +267,77 @@ def update_file_format(self, frame):
258267
# Do nothing if conversion not needed
259268
pass
260269

270+
def run(self):
271+
print "> Going for some spins"
272+
rate = rospy.Rate(200) # hz
273+
while not rospy.is_shutdown():
274+
self.broadcast()
275+
rate.sleep()
276+
277+
def parse_args(self, argv):
278+
## Args ##
279+
##
280+
# Process standalone plugin command-line arguments
281+
from argparse import ArgumentParser
282+
parser = ArgumentParser()
283+
# Add argument(s) to the parser.
284+
parser.add_argument("-q", "--quiet", action="store_true",
285+
dest="quiet",
286+
help="Put plugin in silent mode")
287+
parser.add_argument("-l", "--load", action="append",
288+
dest="file",
289+
help="Load a file at startup. [rospack filepath/file]")
290+
291+
args, unknowns = parser.parse_known_args(argv)
292+
if not args.quiet:
293+
print 'arguments: ', args
294+
print 'unknowns: ', unknowns
295+
296+
## Load file ##
297+
##
298+
if args.file:
299+
arg_path = args.file[0].split()
300+
if len(arg_path) == 1:
301+
#load file
302+
filename = arg_path[0]
303+
print "Loading", filename
304+
success = self.load_file(str(filename))
305+
elif len(arg_path) == 2:
306+
#load rospack
307+
rospack = rospkg.RosPack()
308+
filename = os.path.join(rospack.get_path(arg_path[0]), arg_path[1])
309+
print "Loading", filename
310+
success = self.load_file(str(filename))
311+
else:
312+
print "Load argument not understood! --load", arg_path
313+
print "Please use --load 'myRosPackage pathInMyPackage/myYaml.yaml'"
314+
print "or use --load 'fullPathToMyYaml.yaml'"
315+
success = None
316+
317+
if success:
318+
return filename
319+
elif success == False:
320+
print "ERROR LOADING FILE"
321+
return ''
322+
323+
def init_views(self):
324+
## Views
325+
self.interface_tf = FrameEditor_TF(self)
326+
self.interactive = FrameEditor_InteractiveMarker(self)
327+
self.services = FrameEditor_Services(self)
328+
self.interface_markers = FrameEditor_Markers(self)
329+
261330
if __name__ == "__main__":
262331

263332
rospy.init_node('frame_editor')
264333

265334
editor = FrameEditor()
266-
editor.load_params(rospy.get_name())
335+
# editor.load_params(rospy.get_name())
336+
337+
editor.parse_args(sys.argv[1:])
338+
editor.init_views()
267339

268340
print "Frame editor ready!"
269-
rate = rospy.Rate(100) # hz
270-
while not rospy.is_shutdown():
271-
editor.broadcast()
272-
rate.sleep()
341+
editor.run()
273342

274343
# eof

frame_editor/src/frame_editor/rqt_editor.py

Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@
2323
from frame_editor.interface import Interface
2424

2525
## Views
26-
from frame_editor.interface_interactive_marker import FrameEditor_InteractiveMarker
27-
from frame_editor.interface_services import FrameEditor_Services
28-
from frame_editor.interface_markers import FrameEditor_Markers
2926
from frame_editor.interface_gui import FrameEditor_StyleWidget
30-
from frame_editor.interface_tf import FrameEditor_TF
3127

3228

3329
class FrameEditorGUI(ProjectPlugin, Interface):
@@ -42,45 +38,11 @@ def __init__(self, context):
4238
self.file_type = "YAML files(*.yaml)"
4339

4440

45-
## Args ##
46-
##
47-
# Process standalone plugin command-line arguments
48-
from argparse import ArgumentParser
49-
parser = ArgumentParser()
50-
# Add argument(s) to the parser.
51-
parser.add_argument("-q", "--quiet", action="store_true",
52-
dest="quiet",
53-
help="Put plugin in silent mode")
54-
parser.add_argument("-l", "--load", action="append",
55-
dest="file",
56-
help="Load a file at startup. [rospack filepath/file]")
57-
58-
args, unknowns = parser.parse_known_args(context.argv())
59-
if not args.quiet:
60-
print 'arguments: ', args
61-
print 'unknowns: ', unknowns
62-
63-
64-
## Load file ##
65-
##
6641
self.filename = ""
67-
if args.file:
68-
arg_path = args.file[0].split()
69-
if len(arg_path) == 1:
70-
#load file
71-
filename = arg_path[0]
72-
print "Loading", filename
73-
self.load_file(str(filename))
74-
elif len(arg_path) == 2:
75-
#load rospack
76-
rospack = rospkg.RosPack()
77-
filename = os.path.join(rospack.get_path(arg_path[0]), arg_path[1])
78-
print "Loading", filename
79-
self.load_file(str(filename))
80-
else:
81-
print "Load argument not understood! --load", arg_path
82-
print "Please use --load 'myRosPackage pathInMyPackage/myYaml.yaml'"
83-
print "or use --load 'fullPathToMyYaml.yaml'"
42+
43+
filename = self.editor.parse_args(context.argv())
44+
if filename:
45+
self.set_current_file(filename)
8446

8547

8648
## Update thread ##
@@ -121,10 +83,7 @@ def create_main_widget(self):
12183

12284

12385
## Views
124-
self.interface_tf = FrameEditor_TF(self.editor)
125-
self.interactive = FrameEditor_InteractiveMarker(self.editor)
126-
self.services = FrameEditor_Services(self.editor)
127-
self.interface_markers = FrameEditor_Markers(self.editor)
86+
self.editor.init_views()
12887
self.interface_style = FrameEditor_StyleWidget(self.editor)
12988

13089
widget.style_frame.layout().addWidget(self.interface_style.get_widget())
@@ -169,11 +128,7 @@ def create_main_widget(self):
169128

170129

171130
def _update_thread_run(self):
172-
print "> Going for some spins"
173-
rate = rospy.Rate(200) # hz
174-
while not rospy.is_shutdown():
175-
self.editor.broadcast()
176-
rate.sleep()
131+
self.editor.run()
177132

178133
@Slot()
179134
def _update_finished(self):

0 commit comments

Comments
 (0)