OpenRTM_aist
examples
Slider_and_Motor
tkmotor.py
Go to the documentation of this file.
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
# -*- Python -*-
4
5
from
Tkinter
import
*
6
import
thread
7
import
time
8
import
math
9
10
class
TkMotor
(Frame):
11
def
__init__
(self, num, radius, master=None):
12
Frame.__init__(self, master)
13
self.
num
= num
14
self.
r
= radius
15
self.
init
()
16
self.pack()
17
18
19
20
def
init
(self):
21
self.
space
= 4
22
canwidth = self.
r
* self.
space
* self.
num
23
canheight = self.
r
* self.
space
24
self.
can
= Canvas(self, bg=
"white"
,
25
width=canwidth, height=canheight)
26
self.
can
.pack()
27
self.
circ
= []
28
self.
line
= []
29
self.
x
= []
30
self.
y
= []
31
self.
x1
= []
32
self.
y1
= []
33
self.
x2
= []
34
self.
y2
= []
35
self.
sx1
= []
36
self.
sy1
= []
37
self.
sx2
= []
38
self.
sy2
= []
39
40
for
i
in
xrange(self.
num
):
41
self.
x
.
append
(self.
r
* self.
space
/ 2 * (i+0.5) * 2)
42
self.
y
.
append
(self.
r
* self.
space
/ 2)
43
self.
x1
.
append
(self.
x
[i] - self.
r
)
44
self.
y1
.
append
(self.
y
[i] - self.
r
)
45
self.
x2
.
append
(self.
x
[i] + self.
r
)
46
self.
y2
.
append
(self.
y
[i] + self.
r
)
47
self.
sx1
.
append
(self.
x
[i] - self.
r
* 0.1)
48
self.
sy1
.
append
(self.
y
[i] - self.
r
* 0.1)
49
self.
sx2
.
append
(self.
x
[i] + self.
r
* 0.1)
50
self.
sy2
.
append
(self.
y
[i] + self.
r
* 0.1)
51
self.
circ
.
append
(self.
can
.create_oval(self.
x1
[i], self.
y1
[i],
52
self.
x2
[i], self.
y2
[i],
53
outline=
"#aaaaaa"
,
54
fill=
"#dddddd"
))
55
self.
circ
.
append
(self.
can
.create_oval(self.
sx1
[i], self.
sy1
[i],
56
self.
sx2
[i], self.
sy2
[i],
57
outline=
"#000000"
,
58
fill=
"#000000"
))
59
self.
line
.
append
(self.
can
.create_line(self.
x
[i], self.
y
[i],
60
self.
x
[i],
61
self.
y
[i] - self.
r
,
62
fill=
"#700040"
, width=5))
63
64
65
def
set_angle
(self, angle):
66
if
len(angle) != self.
num
:
return
67
i = 0
68
for
a
in
angle:
69
a = a * math.pi / 180
70
self.
can
.delete(self.
line
[i])
71
self.
line
[i] = self.
can
.create_line(self.
x
[i], self.
y
[i],
72
self.
x
[i] + self.
r
* math.cos(a),
73
self.
y
[i] + self.
r
* math.sin(a),
74
fill=
"#700040"
, width=5)
75
i = i + 1
76
77
78
79
def
test
():
80
m =
TkMotor
(6, 40, Toplevel())
81
n =
TkMotor
(6, 40, Toplevel())
82
thread.start_new_thread(m.mainloop, ())
83
thread.start_new_thread(n.mainloop, ())
84
cnt = 0
85
while(1):
86
angle = [cnt % 360, - cnt % 360, cnt % 360, - cnt % 360, cnt % 360, - cnt % 360]
87
m.set_angle(angle)
88
time.sleep(0.001)
89
cnt = cnt + 1
90
91
92
if
__name__ ==
'__main__'
:
test
()
OpenRTM_aist.examples.Slider_and_Motor.tkmotor.TkMotor.num
num
Definition:
tkmotor.py:13
OpenRTM_aist.examples.Slider_and_Motor.tkmotor.TkMotor.line
line
Definition:
tkmotor.py:28
OpenRTM_aist.examples.Slider_and_Motor.tkmotor.TkMotor
Definition:
tkmotor.py:10
OpenRTM_aist.examples.Slider_and_Motor.tkmotor.TkMotor.init
def init(self)
Definition:
tkmotor.py:20
OpenRTM_aist.examples.Slider_and_Motor.tkmotor.TkMotor.space
space
Definition:
tkmotor.py:21
OpenRTM_aist.examples.Slider_and_Motor.tkmotor.TkMotor.circ
circ
Definition:
tkmotor.py:27
OpenRTM_aist.examples.Slider_and_Motor.tkmotor.TkMotor.y1
y1
Definition:
tkmotor.py:32
OpenRTM_aist.examples.Slider_and_Motor.tkmotor.TkMotor.y2
y2
Definition:
tkmotor.py:34
OpenRTM_aist.examples.Slider_and_Motor.tkmotor.TkMotor.x1
x1
Definition:
tkmotor.py:31
OpenRTM_aist.examples.Slider_and_Motor.tkmotor.TkMotor.__init__
def __init__(self, num, radius, master=None)
Definition:
tkmotor.py:11
OpenRTM_aist.examples.Slider_and_Motor.tkmotor.TkMotor.x2
x2
Definition:
tkmotor.py:33
OpenRTM_aist.examples.Slider_and_Motor.tkmotor.TkMotor.sx2
sx2
Definition:
tkmotor.py:37
OpenRTM_aist.examples.Slider_and_Motor.tkmotor.TkMotor.sy1
sy1
Definition:
tkmotor.py:36
OpenRTM_aist.examples.Slider_and_Motor.tkmotor.TkMotor.can
can
Definition:
tkmotor.py:24
OpenRTM_aist.examples.Slider_and_Motor.tkmotor.TkMotor.sy2
sy2
Definition:
tkmotor.py:38
OpenRTM_aist.examples.Slider_and_Motor.tkmotor.TkMotor.x
x
Definition:
tkmotor.py:29
OpenRTM_aist.examples.Slider_and_Motor.tkmotor.test
def test()
Definition:
tkmotor.py:79
OpenRTM_aist.examples.Slider_and_Motor.tkmotor.TkMotor.set_angle
def set_angle(self, angle)
Definition:
tkmotor.py:65
OpenRTM_aist.examples.Slider_and_Motor.tkmotor.TkMotor.r
r
Definition:
tkmotor.py:14
OpenRTM_aist.examples.Slider_and_Motor.tkmotor.TkMotor.y
y
Definition:
tkmotor.py:30
OpenRTM_aist.examples.Slider_and_Motor.tkmotor.TkMotor.sx1
sx1
Definition:
tkmotor.py:35
OpenRTM_aist.NVUtil.append
def append(dest, src)
Definition:
NVUtil.py:386
openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Mon Feb 28 2022 23:01:07