ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I fixed it. I wasn't getting the values from the subscriber because it was never being called in the first place. Putting it on its own "listener()" definition meant it never being executed I guess.

class sem_wait(smach.State):
    def __init__(self):
        smach.State.__init__(self, outcomes=['finished', 'failed'])
        self.got = False
        self.subscriber = rospy.Subscriber('/button_press', Int16, self.callback)

    def callback(self, data):
        if data.data == 1:
            self.got = True
        else:
            self.got = False

    def execute(self, data):
        for i in range (0, 30):
            if self.got:
                return 'finished'
            time.sleep(.1)
        return 'failed'

This works just the way I wanted it to.