Main Page
Namespaces
Classes
Files
File List
scripts
clean_motor_toggler.py
Go to the documentation of this file.
1
#!/usr/bin/env python
2
3
import
rospy
4
from
sensor_msgs.msg
import
Joy
5
from
create_node.srv
import
SetCleanMotors
6
7
class
CleanMotorToggler
:
8
def
__init__
(self):
9
self.
button_state
=
False
10
self.
clean_state
=
False
11
12
self.
service_name
= rospy.get_param(
13
'clean_motors_service'
,
'turtlebot_node/set_clean_motors'
)
14
self.
clean_button
= rospy.get_param(
'clean_button_id'
, 0)
15
self.
sub
= rospy.Subscriber(
'joy'
, Joy, self.
callback
)
16
rospy.wait_for_service(self.
service_name
)
17
try
:
18
self.
set_clean_motors
= rospy.ServiceProxy(
19
self.
service_name
, SetCleanMotors)
20
except
rospy.ServiceException, e:
21
print
"Service call failed: %s"
% e
22
23
def
callback
(self, msg):
24
if
msg.buttons[self.
clean_button
]:
25
if
not
self.
button_state
:
26
self.
button_state
=
True
27
return
28
if
self.
button_state
:
29
self.
button_state
=
False
30
self.
clean_state
=
not
self.
clean_state
31
self.
set_clean_motors
(
False
, self.
clean_state
, self.
clean_state
)
32
33
if
__name__ ==
'__main__'
:
34
rospy.init_node(
'clean_motor_toggler'
)
35
node =
CleanMotorToggler
()
36
rospy.on_shutdown(
lambda
: node.set_clean_motors(
False
,
False
,
False
))
37
rospy.spin()
38
clean_motor_toggler.CleanMotorToggler.clean_state
clean_state
Definition:
clean_motor_toggler.py:10
clean_motor_toggler.CleanMotorToggler.callback
def callback(self, msg)
Definition:
clean_motor_toggler.py:23
clean_motor_toggler.CleanMotorToggler
Definition:
clean_motor_toggler.py:7
clean_motor_toggler.CleanMotorToggler.service_name
service_name
Definition:
clean_motor_toggler.py:12
clean_motor_toggler.CleanMotorToggler.set_clean_motors
set_clean_motors
Definition:
clean_motor_toggler.py:18
clean_motor_toggler.CleanMotorToggler.button_state
button_state
Definition:
clean_motor_toggler.py:9
clean_motor_toggler.CleanMotorToggler.clean_button
clean_button
Definition:
clean_motor_toggler.py:14
clean_motor_toggler.CleanMotorToggler.__init__
def __init__(self)
Definition:
clean_motor_toggler.py:8
clean_motor_toggler.CleanMotorToggler.sub
sub
Definition:
clean_motor_toggler.py:15
roomblock_bringup
Author(s): Ryosuke Tajima
autogenerated on Mon Jun 10 2019 14:49:23