Main Page
Namespaces
Classes
Files
File List
scripts
switch.py
Go to the documentation of this file.
1
#!/usr/bin/env python
2
# license removed for brevity
3
import
rospy
4
from
geometry_msgs.msg
import
Twist
5
from
sensor_msgs.msg
import
Joy
6
7
# This script will listen for joystick button 5 being toggled and
8
# send zero speed messages to the mux to disable the follower until
9
# button 5 is pressed again.
10
11
class
BehaviorSwitch
(object):
12
def
__init__
(self):
13
self.
running
=
False
14
15
def
callback
(self, joy_msg):
16
if
joy_msg.buttons[5] == 1:
17
self.
running
=
not
self.
running
18
19
rospy.loginfo(repr(joy_msg))
20
21
def
run
(self):
22
rospy.init_node(
'behavior_switch'
, anonymous=
True
)
23
pub = rospy.Publisher(
'cmd_vel_mux/input/switch'
, Twist, queue_size=10)
24
rospy.Subscriber(
'joy'
, Joy, self.
callback
)
25
rate = rospy.Rate(10)
26
while
not
rospy.is_shutdown():
27
if
self.
running
:
28
empty_msg = Twist()
29
pub.publish(empty_msg)
30
rate.sleep()
31
32
if
__name__ ==
'__main__'
:
33
try
:
34
behavior_switch =
BehaviorSwitch
()
35
behavior_switch.run()
36
except
rospy.ROSInterruptException:
37
pass
switch.BehaviorSwitch.run
def run(self)
Definition:
switch.py:21
switch.BehaviorSwitch
Definition:
switch.py:11
switch.BehaviorSwitch.callback
def callback(self, joy_msg)
Definition:
switch.py:15
switch.BehaviorSwitch.__init__
def __init__(self)
Definition:
switch.py:12
switch.BehaviorSwitch.running
running
Definition:
switch.py:13
roch_follower
Author(s): Tony Pratkanis
autogenerated on Mon Jun 10 2019 14:44:24