Main Page
Namespaces
Files
File List
scripts
rtbuzzer.py
Go to the documentation of this file.
1
#!/usr/bin/env python
2
import
rospy
3
import
actionlib
4
from
std_msgs.msg
import
UInt16
5
from
raspimouse_ros.msg
import
MusicAction, MusicResult, MusicFeedback
6
7
def
put_freq
(hz):
8
try
:
9
with open(
'/dev/rtbuzzer0'
,
'w'
)
as
f:
10
print
>> f, hz
11
except
:
12
rospy.logerr(
"cannot open "
+ devfile)
13
14
def
cb
(message):
15
put_freq
(message.data)
16
17
def
exec_music
(goal):
18
r = MusicResult()
19
fb = MusicFeedback()
20
r.finished =
True
21
num = len(goal.freqs)
22
for
i, f
in
enumerate(goal.freqs):
23
fb.remaining_steps = num - i
24
ms.publish_feedback(fb)
25
26
if
ms.is_preempt_requested():
27
put_freq
(0)
28
r.finished =
False
29
ms.set_preempted(r)
30
return
31
32
put_freq
(f)
33
t = 1.0
34
if
i < len(goal.durations):
35
t = goal.durations[i]
36
37
rospy.sleep(t)
38
39
fb.remaining_steps = 0
40
ms.publish_feedback(fb)
41
ms.set_succeeded(r)
42
return
43
44
def
mute
():
45
put_freq
(0)
46
47
if
__name__ ==
'__main__'
:
48
rospy.init_node(
'rtbuzzer'
)
49
sub = rospy.Subscriber(
'buzzer'
, UInt16, cb)
50
ms = actionlib.SimpleActionServer(
'music'
, MusicAction, exec_music,
False
)
51
ms.start()
52
rospy.on_shutdown(mute)
53
rospy.spin()
rtbuzzer.put_freq
def put_freq(hz)
Definition:
rtbuzzer.py:7
rtbuzzer.exec_music
def exec_music(goal)
Definition:
rtbuzzer.py:17
rtbuzzer.mute
def mute()
Definition:
rtbuzzer.py:44
msg
rtbuzzer.cb
def cb(message)
Definition:
rtbuzzer.py:14
raspimouse_ros
Author(s):
autogenerated on Mon Jun 10 2019 14:27:02