ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

smach groovy

asked 2015-01-07 03:20:27 -0500

Hunk gravatar image


i try to run a simple example code with ros groovy

#!/usr/bin/env python

import roslib; 
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'
            return 'outcome2'

# define state Bar
class Bar(smach.State):
    def __init__(self):
        smach.State.__init__(self, outcomes=['outcome1'])

    def execute(self, userdata):
        rospy.loginfo('Executing state BAR')
        return 'outcome1'

def main():

    # Create a SMACH state machine
    sm = smach.StateMachine(outcomes=['outcome4'])

    # 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(), 

    # Execute SMACH plan
    outcome = sm.execute()

if __name__ == '__main__':

The problem is that python didn't find smach. I tried to add smach and smach_ros to my CMakelists.txt

find_package(catkin REQUIRED COMPONENTS smach_ros smach rospy)

and package.xml


but then i get following error

CMake Error at /opt/ros/groovy/share/catkin/cmake/catkinConfig.cmake:72 (find_package): Could not find a configuration file for package smach_ros.

Set smach_ros_DIR to the directory containing a CMake configuration file for smach_ros. The file will have one of the following names:


Does anyone have an idea what I forgot , or where my error is?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-01-12 08:41:28 -0500

Hunk gravatar image

I removed smach_ros and smach inside CMake

and added to my python:

import roslib; roslib.load_manifest('smach'); roslib.load_manifest('smach_ros')

I have no idea if this is the right way and why it works.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-01-07 03:20:27 -0500

Seen: 402 times

Last updated: Jan 12 '15