button_test.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 """ Example code of how to access button state. """
00004 
00005 # We always import roslib, and load the manifest to handle dependencies
00006 import roslib; roslib.load_manifest('mini_max_tutorials')
00007 import rospy
00008 
00009 # arbotix_msgs defines the Digital message, which tells us the state
00010 #  of the button (a digital pin)
00011 from arbotix_msgs.msg import *
00012 
00013 class ButtonTest:
00014     
00015     def buttonCb(self, msg):
00016         # msg is arbotix_msgs.Digital, value == state of the button
00017         if msg.value == 0:
00018             print "Button pressed!"
00019 
00020     def __init__(self):
00021         # we have to initialize the node, with a name in the ROS graph
00022         rospy.init_node('button_test')
00023 
00024         # subscribe to the green_button value. 
00025         rospy.Subscriber('/arbotix/green_button',Digital,self.buttonCb)
00026 
00027         # everything will be handled in the callback, just spin
00028         rospy.spin()
00029 
00030 # this quick check means that the following code runs ONLY if this is 
00031 #  in the main file -- if we "import button_test" in another file, 
00032 #  this code will not execute
00033 if __name__ == "__main__":
00034     bt = ButtonTest()


mini_max_tutorials
Author(s): Michael Ferguson
autogenerated on Mon Oct 6 2014 02:23:05