Problem while Running SMACH program
Hi,
I am trying out the tutorials on SMACH in ros-indigo.
I am trying to run this following SMACH program state_machine_simple.py
#!/usr/bin/env python
import roslib; roslib.load_manifest('smach_tutorials')
import rospy
import smach
import smach_ros
# define state Foo
class Foo(smach.State):
def __init__(self):
smach.State.__init__(self, outcomes=['outcome1','outcome2'])
self.counter = 0
def execute(self, userdata):
rospy.loginfo('Executing state FOO')
if self.counter < 3:
self.counter += 1
return 'outcome1'
else:
return 'outcome2'
# define state Bar
class Bar(smach.State):
def __init__(self):
smach.State.__init__(self, outcomes=['outcome2'])
def execute(self, userdata):
rospy.loginfo('Executing state BAR')
return 'outcome2'
# main
def main():
rospy.init_node('smach_example_state_machine')
# Create a SMACH state machine
sm = smach.StateMachine(outcomes=['outcome4', 'outcome5'])
# Open the container
with sm:
# Add states to the container
smach.StateMachine.add('FOO', Foo(),
transitions={'outcome1':'BAR',
'outcome2':'outcome4'})
smach.StateMachine.add('BAR', Bar(),
transitions={'outcome2':'FOO'})
# Execute SMACH plan
outcome = sm.execute()
if __name__ == '__main__':
main()
But when I execute it I am getting this error
Traceback (most recent call last):
File "state_machine_simple.py", line 9, in <module>
class Foo(smach.State):
AttributeError: 'module' object has no attribute 'State'
I don't know how to solve this error... kindly help me out....
In a terminal, type
python
and then try:from smach import State
Does that result in an error too?Hi, I tried that its not showing error.... So I tried including
from smach import State
statement in the program... now its working fine.. thank you..