32 lrfviewer_spec = [
"implementation_id",
"LRFViewer",
33 "type_name",
"LRFViewer",
34 "description",
"Laser Range Finder Viewer component",
36 "vendor",
"Noriaki Ando, AIST",
37 "category",
"example",
38 "activity_type",
"DataFlowComponent",
41 "lang_type",
"SCRIPT",
52 OpenRTM_aist.DataFlowComponentBase.__init__(self, manager)
61 _pose3D = RTC.Pose3D(RTC.Point3D(0.0, 0.0, 0.0),
62 RTC.Orientation3D(0.0, 0.0, 0.0))
63 _size3D = RTC.Size3D(0.0, 0.0, 0.0)
64 _geometry3D = RTC.Geometry3D(_pose3D, _size3D)
65 _rangerConfig = RTC.RangerConfig(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
68 RTC.RangerGeometry(_geometry3D, []),
86 if self._rangeDataIn.isNew():
87 _rangeData = self._rangeDataIn.read()
90 self.
end_point = _rangeData.config.maxAngle
137 ToggleItem.__init__(self)
139 self.
id = self.canvas.create_text(x, y, text=text)
149 self.
id = self.canvas.create_text(self.
x, self.
y, text=self.
text)
160 self.canvas.delete(self.
id)
164 def __init__(self, canvas, x0, y0, width, height, pitch, color, linewd):
165 ToggleItem.__init__(self)
184 x_start = int(self.
x0 % self.
pitch)
185 x_num = int((self.
width - x_start) / self.
pitch) + 1
186 for x
in range(x_num):
187 x0 = x_start + self.
pitch * x
188 id = self.canvas.create_line(x0, 0, x0, self.
height,
192 y_start = int(self.
y0 % self.
pitch)
193 y_num = int((self.
height - y_start) / self.
pitch) + 1
194 for y
in range(y_num):
195 y0 = y_start + self.
pitch * y
196 id = self.canvas.create_line(0, y0, self.
width, y0,
201 self.canvas.tag_lower(i)
203 self.canvas.tag_lower(i)
209 self.canvas.delete(i)
211 self.canvas.delete(i)
223 def __init__(self, canvas, width, height, color="#ffffff", linewd=1):
224 ToggleItem.__init__(self)
239 self.
id[0] = self.canvas.create_line(0, self.
height/2,
243 self.
id[1] = self.canvas.create_text(self.
width - 10,
248 self.
id[2] = self.canvas.create_line(self.
width/2, 0,
252 self.
id[3] = self.canvas.create_text(self.
width/2 + 10,
261 self.canvas.delete(i)
268 self.
tick = simulator.get_tick()
270 self.
trans = simulator.get_translation()
274 return self.
trans(x, y, dx, dy, dth)
277 return self.simulator.get_tick()
286 line_color=
"#ff0000", fill_color=
"#ff0000", linewd=1):
287 ScaledObject.__init__(self, simulator)
311 self.threshold_check.set(
True)
313 self.tfilter_check.set(
True)
315 self.sfilter_check.set(
True)
320 self.tfilter_var.set(self.
tfilter)
322 self.sfilter_var.set(self.
sfilter)
329 self.lrf_fill_check.set(
"on")
331 self.lrf_line_check.set(
"on")
333 text = Label(frame, text=
"LRF range area", anchor=W, justify=LEFT)
335 line = Checkbutton(frame, text=
"Line",
336 onvalue=
"on", offvalue=
"off",
337 justify=LEFT, anchor=W,
341 fill = Checkbutton(frame, text=
"Fill",
342 onvalue=
"on", offvalue=
"off",
343 justify=LEFT, anchor=W,
347 thresh = Checkbutton(frame, text=
"Threshold",
348 onvalue=
True, offvalue=
False,
349 justify=LEFT, anchor=W,
351 thresh_scale = Scale(frame, from_=0, to=100, resolution=0.1,
355 tfilter = Checkbutton(frame, text=
"Filter(Time)",
356 onvalue=
True, offvalue=
False,
357 justify=LEFT, anchor=W,
359 tfilter_scale = Scale(frame, from_=0, to=1, resolution=0.01,
363 sfilter = Checkbutton(frame, text=
"Filter(Spacial)",
364 onvalue=
True, offvalue=
False,
365 justify=LEFT, anchor=W,
367 sfilter_scale = Scale(frame, from_=0, to=1, resolution=0.01,
371 for w
in [text, line, fill, thresh, thresh_scale,
372 tfilter, tfilter_scale, sfilter, sfilter_scale]:
373 w.pack(side=TOP, anchor=W, fill=X)
377 self.
threshold = self.threshold_var.get()
381 self.
sfilter = self.sfilter_var.get()
385 self.
tfilter = self.tfilter_var.get()
389 if self.lrf_line_check.get() ==
"on":
396 if self.lrf_fill_check.get() ==
"on":
413 rpos.append(self.
translate(0, 0, 0, 0, 0))
415 self.
poly_id = self.canvas.create_polygon(rpos,
427 tfilter = self.tfilter_check.get()
428 sfilter = self.sfilter_check.get()
429 thresh = self.threshold_check.get()
432 if tfilter
and len(data) == len(self.
pre_data):
433 for (n, d)
in enumerate(data):
435 data[n] = self.
pre_data[n] * k_t + d * (1 - k_t)
438 for (n, d)
in enumerate(data):
445 d = pre_d * k_s + d * (1 - k_s)
455 pos.append(self.
translate(x, y, 0, 0, 0))
461 self.canvas.delete(self.
poly_id)
466 rdata = self.source.get_range_data()
470 res = self.source.get_angular_res()
474 beg_angle = self.source.get_start_point()
478 end_angle = self.source.get_end_point()
493 def __init__(self, master=None, width=480, height=480):
494 Frame.__init__(self, master)
512 self.scale_var.set(self.
scale)
519 self.tickscale_var.set(self.
tick)
522 self.axis_check.set(
"on")
524 self.grid_check.set(
"on")
538 self.canvas.pack(side=LEFT)
547 self.frame.pack(side=LEFT)
552 self.scrctrl_frame.pack(side=TOP, fill=X)
559 self.lrfctrl_frame.pack(side=TOP, fill=X)
585 dummy = Frame(frame, width=self.
wd)
587 sl = Scale(frame, from_=0, to=10, resolution=0.01,
588 label=
"Scale Factor", command=self.
on_scale,
589 variable=self.
scale_var, orient=HORIZONTAL)
590 bt = Button(frame, text=
"Reset Scale", command=self.
reset_scale)
591 sl.pack(side=TOP, fill=X)
592 bt.pack(side=TOP, fill=X)
602 self.can_grid.set_pitch(pitch)
606 self.scale_var.set(1.)
609 self.can_grid.set_pitch(pitch)
613 v = self.tickscale_var.get()
630 axis = Checkbutton(frame, text=
"Axis",
631 onvalue=
"on", offvalue=
"off",
632 justify=LEFT, anchor=W,
634 command=self.can_axis.toggle)
635 grid = Checkbutton(frame, text=
"Grid",
636 onvalue=
"on", offvalue=
"off",
637 justify=LEFT, anchor=W,
639 command=self.can_grid.toggle)
640 for w
in [axis, grid]:
641 w.pack(side=TOP, anchor=W, fill=X)
644 for r
in self.rnames.keys():
658 x_tmp = (math.cos(dt) * x - math.sin(dt) * y + dx)/self.
scale 659 y_tmp = (math.sin(dt) * x + math.cos(dt) * y + dy)/self.
scale 662 yo = -y_tmp + self.
y0 669 threading.Thread.__init__(self)
687 data[i] = pre * 0.9 + random.randint(0, 255) * 0.1
692 self.lrf.set_value(data)
699 m.master.title(
"Laser Range Finder Viewer")
701 mgr = OpenRTM_aist.Manager.init(sys.argv)
702 mgr.activateManager()
704 mgr.registerFactory(profile, LRFViewer, OpenRTM_aist.Delete)
706 lrf_rtc = mgr.createComponent(
"LRFViewer")
707 m.lrf.set_data_source(lrf_rtc)
712 if __name__ ==
'__main__':
main()
def on_rname_toggle(self)
def __init__(self, canvas, text, x, y)
def get_start_point(self)
def set_value(self, data)
def create_checkbutton(self, frame)
def set_data_source(self, source)
def draw_text(self, x, y, text)
The Properties class represents a persistent set of properties.
def on_tfilter(self, var)
def __init__(self, simulator, line_color="#ff0000", fill_color="#ff0000", linewd=1)
def __init__(self, manager)
def create_scale(self, frame)
def create_ctrl(self, frame)
def __init__(self, canvas, width, height, color="#ffffff", linewd=1)
def onDeactivated(self, ec_id)
def on_tickchange(self, val)
def get_translation(self)
def on_threshold(self, var)
def translate(self, x, y, dx, dy, dth)
def range_to_pos(self, data)
def __init__(self, lrf, step=681)
def onExecute(self, ec_id)
def __init__(self, simulator)
def addInPort(self, name, inport)
def real_to_canvas(self, x, y, dx, dy, dt)
def set_pitch(self, pitch)
def onShutdown(self, ec_id)
def __init__(self, master=None, width=480, height=480)
def __init__(self, canvas, x0, y0, width, height, pitch, color, linewd)
def on_sfilter(self, var)
def reset_tickscale(self)
DataFlowComponentBase class.
def get_angular_res(self)