33 tkmobilerobotsimulator_spec = [
"implementation_id",
"TkMobileRobotSimulator",
34 "type_name",
"TkMobileRobotSimulator",
35 "description",
"sample component for Python and Tkinter",
37 "vendor",
"Noriaki Ando, AIST",
38 "category",
"example",
39 "activity_type",
"DataFlowComponent",
42 "lang_type",
"SCRIPT",
49 OpenRTM_aist.DataFlowComponentBase.__init__(self, manager)
56 self.
_d_vel = RTC.TimedFloatSeq(RTC.Time(0,0),[])
59 self.
_d_pos = RTC.TimedFloatSeq(RTC.Time(0,0),[])
120 ToggleItem.__init__(self)
148 ToggleItem.__init__(self)
150 self.
trans = simulator.get_translation()
165 rx, ry, rt = self.
robot.get_pos()
171 x0, y0 = self.
trans(tmp_x0, tmp_y0, rx, ry, 0)
172 x1, y1 = self.
trans(tmp_x1, tmp_y1, rx, ry, 0)
176 fill=
"", outline=
"#aaaaaa")
181 lx0 = xo + (r / math.sqrt(2))
182 ly0 = yo - (r / math.sqrt(2))
191 anchor=E, text=self.
name)
192 pos_text =
'(%5.2f, %5.2f, %5.2f)' % (rx, ry, (rt*180/math.pi)%360)
194 anchor=E, text=pos_text)
213 def __init__(self, canvas, x0, y0, width, height, pitch, color, linewd):
214 ToggleItem.__init__(self)
234 x_start = int(self.
x0 % self.
pitch)
235 x_num = int((self.
width - x_start) / self.
pitch) + 1
236 for x
in range(x_num):
237 x0 = x_start + self.
pitch * x
242 y_start = int(self.
y0 % self.
pitch)
243 y_num = int((self.
height - y_start) / self.
pitch) + 1
244 for y
in range(y_num):
245 y0 = y_start + self.
pitch * y
246 id = self.
canvas.create_line(0, y0, self.
width, y0,
273 ToggleItem.__init__(self)
309 self.
tick = simulator.get_tick()
311 self.
trans = simulator.get_translation()
315 return self.
trans(x, y, dx, dy, dth)
321 import tkSimpleDialog
352 self.
param.
append({
"label":label,
"var":variable,
"unit":unit})
358 self.
input.
append({
"label":label,
"var":variable,
"unit":unit})
364 self.
output.
append({
"label":label,
"var":variable,
"unit":unit})
385 w0 = LabelFrame(f, label=
"Robot's Profile",
386 options=
"frame.anchor w frame.justify left")
387 prof_frame = w0.subwidget(
'frame')
390 w1 = LabelFrame(f, label=
"Robot's Parameters")
391 param_frame = w1.subwidget(
'frame')
396 w2 = LabelFrame(f, label=
"Robot's Input Values")
397 input_frame = w2.subwidget(
'frame')
402 w3 = LabelFrame(f, label=
"Robot's Output Values")
403 output_frame = w3.subwidget(
'frame')
409 for w
in [w0, w1, w2, w3]:
410 w.pack(side=TOP, anchor=W, fill=X)
421 bt = Button(master, text=label, command=func, width=10,
423 bt.pack(side=TOP, padx=5, pady=5)
428 t = [
"Robot's name: ",
"Robot's type: ",
"Description: ",
"Vendor: "]
429 for i
in range(len(t)):
430 Label(master, text=t[i], anchor=W).grid(row=i, sticky=W,
433 for i
in range(len(l)):
434 Label(master, text=l[i], anchor=W).grid(row=i, column=1, sticky=W,
441 l0 = Label(f, text=label0, width=self.
label_len, justify=LEFT, anchor=W)
442 e =
Entry(f, width=7, textvariable=var,
443 justify=RIGHT, relief=GROOVE, bd=2)
444 l1 = Label(f, text=label1, width=self.
unit_len, justify=LEFT, anchor=W)
445 for w
in [l0, e, l1]:
446 w.pack(side=LEFT, anchor=W, padx=3, pady=3)
457 def __init__(self, radius, wheeld, pos = (0, 0, math.pi/2), dt=0.1):
504 x_dot = self.
radius * (w1 + w2) * math.cos(self.
pre_t)
505 y_dot = self.
radius * (w1 + w2) * math.sin(self.
pre_t)
526 def __init__(self, simulator, radius=2, wheeld=20,
527 pos = (0, 0, math.pi/2)):
528 SimulatedObject.__init__(self, simulator)
531 self.
fig = [[10, 0], [5, 10], [-10, 10], [-10, -10], [5, -10]]
535 self.
name =
"DDMobileRobot" + str(self.__class__.count)
536 self.__class__.count += 1
537 self.
comp = OpenRTM_aist.Manager.instance().createComponent(
"TkMobileRobotSimulator")
587 v = self.
comp.get_velocity()
592 self.
comp.set_position((self.x, self.y, self.
th_deg))
593 self.
xentry.set(
'%5.2f'%self.x)
594 self.
yentry.set(
'%5.2f'%self.y)
605 robotfig.append(self.
translate(pos[0], pos[1],
606 self.x, self.y, self.
th))
609 self.
id = self.
canvas.create_polygon(robotfig,
623 p.set_profile(self.
name,
"DDMobileRobot",
624 "Differential Drive Mobile Robot",
"AIST")
625 p.append_parameter(
"Wheel radius r: ", self.
rentry,
"[m]")
626 p.append_parameter(
"Wheel distance d: ", self.
dentry,
"[m]")
627 p.append_input(
"Angular velocity (LEFT) wl: ", self.
wlentry,
"[rad/s]")
628 p.append_input(
"Angular velocity (RIGHT) wr: ", self.
wrentry,
"[rad/s]")
629 p.append_output(
"Robot position x : ", self.
xentry,
"[m]")
630 p.append_output(
"Robot position y : ", self.
yentry,
"[m]")
631 p.append_output(
"Robot position th: ", self.
tentry,
"[deg]")
640 self.
set_pos((0.0, 0.0, math.pi/2))
645 r = float(self.
rentry.get())
646 d = float(self.
dentry.get())
647 self.
model.set_wheel_radius(r)
648 self.
model.set_wheel_distance(d)
661 def __init__(self, master=None, width=800, height=600):
662 Frame.__init__(self, master)
712 self.
canvas.pack(side=LEFT)
720 self.
frame.pack(side=LEFT)
739 for o
in self.
robots.keys():
741 for r
in self.
rnames.keys():
762 dummy = Frame(frame, width=self.
wd)
764 sl = Scale(frame, from_=0, to=10, resolution=0.01,
765 label=
"Scale Factor", command=self.
on_scale,
766 variable=self.
scale_var, orient=HORIZONTAL)
767 bt = Button(frame, text=
"Reset Scale", command=self.
reset_scale)
768 sl.pack(side=TOP, fill=X)
769 bt.pack(side=TOP, fill=X)
771 sl = Scale(frame, from_=0.001, to=1, resolution=0.001,
775 sl.pack(side=TOP, fill=X)
776 bt.pack(side=TOP, fill=X)
817 axis = Checkbutton(frame, text=
"Axis",
818 onvalue=
"on", offvalue=
"off",
819 justify=LEFT, anchor=W,
822 grid = Checkbutton(frame, text=
"Grid",
823 onvalue=
"on", offvalue=
"off",
824 justify=LEFT, anchor=W,
827 rname = Checkbutton(frame, text=
"Robots' name",
828 onvalue=
"on", offvalue=
"off",
829 justify=LEFT, anchor=W,
832 for w
in [axis, grid, rname]:
833 w.pack(side=TOP, anchor=W, fill=X)
838 for r
in self.
rnames.keys():
850 lb = Label(frame, text=
"Robot Type", anchor=W, justify=LEFT)
852 om = OptionMenu(frame, label=
"Type: ", variable=self.
robot_kind_var)
854 om.add_command(opt, label=opt)
857 creater = Button(frame, text=
"Create", command=self.
create_robot)
858 deleter = Button(frame, text=
"Delete", command=self.
delete_robot)
860 om.pack(side=TOP, fill=X)
861 creater.pack(side=TOP, fill=X)
862 deleter.pack(side=TOP, fill=X)
867 f = Frame(frame, width=self.
wd, height=200)
868 f.pack(side=TOP, fill=BOTH, expand=1)
869 ys = Scrollbar(f, orient = VERTICAL)
870 ys.grid(row = 0, column=1, sticky = N+S)
871 xs = Scrollbar(f, orient = HORIZONTAL)
872 xs.grid(row = 1, column=0, sticky = E+W)
875 xscrollcommand = xs.set,
876 yscrollcommand = ys.set,
877 selectmode =
'single',
880 self.
rlistbox.grid(row = 0, column = 0, sticky = N+S+E+W,)
888 index = self.
rlistbox.curselection()
890 robot_name = self.
rlistbox.get(index[0])
891 self.
robots[robot_name].property_page()
904 self.
robots[robot.get_name()] = robot
909 index = self.
rlistbox.curselection()
911 robot_name = self.
rlistbox.get(index[0])
912 r = self.
rnames.pop(robot_name)
914 r = self.
robots.pop(robot_name)
930 x_tmp = (math.cos(dt) * x - math.sin(dt) * y + dx)/self.
scale 931 y_tmp = (math.sin(dt) * x + math.cos(dt) * y + dy)/self.
scale 934 yo = -y_tmp + self.
y0 940 manager.registerFactory(profile,
941 TkMobileRobotSimulator,
948 m.master.title(
"Tk Mobile Robot Simulator")
949 mgr = OpenRTM_aist.Manager.init(sys.argv)
950 mgr.activateManager()
952 mgr.registerFactory(profile, TkMobileRobotSimulator, OpenRTM_aist.Delete)
956 if __name__ ==
'__main__':
def control(self, w1, w2)
def draw_text(self, x, y, text)
def insert(seq, elem, index)
Insert the element to the CORBA sequence.
def __init__(self, canvas, width, height)
def on_tickchange(self, val)
def get_translation(self)
def set_profile(self, name, type, description, vendor)
def real_to_canvas(self, x, y, dx, dy, dt)
def onExecute(self, ec_id)
def set_apply_input(self, func)
The Properties class represents a persistent set of properties.
def set_reset_output(self, func)
def set_wheel_radius(self, radius)
def onShutdown(self, ec_id)
def create_robotlist(self, frame)
def set_time_tick(self, tick)
def on_clickrlistbox(self, event)
def __init__(self, master=None, width=800, height=600)
def __init__(self, canvas, x0, y0, width, height, pitch, color, linewd)
def button(self, master, label, func)
def set_pitch(self, pitch)
def set_wheel_distance(self, distance)
def create_checkbutton(self, frame)
def set_apply_param(self, func)
def __init__(self, simulator, robot, name, r)
def __init__(self, canvas, text, x, y)
def __init__(self, simulator)
def addOutPort(self, name, outport)
def create_robotcreator(self, frame)
def label_entry(self, master, label0, var, label1)
def append_parameter(self, label, variable, unit)
def addInPort(self, name, inport)
def on_reset_output(self)
def set_pos(self, x, y, th)
def __init__(self, simulator, radius=2, wheeld=20, pos=(0, 0, math.pi/2))
def set_pos(self, pos=(0, 0, math.pi/2))
def create_scale(self, frame)
def append_input(self, label, variable, unit)
def set_wheel_velocity(self, wl, wr)
def label_entries(self, f, props)
def onDeactivated(self, ec_id)
def __init__(self, manager)
def __init__(self, radius, wheeld, pos=(0, 0, math.pi/2), dt=0.1)
def profile_label(self, master)
def TkMobileRobotSimulatorInit(manager)
def on_rname_toggle(self)
def set_position(self, pos)
def append_output(self, label, variable, unit)
def translate(self, x, y, dx, dy, dth)
DataFlowComponentBase class.
def reset_tickscale(self)