Ask Your Question
0

smach groovy

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

Hunk gravatar image

Hello,

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'
        else:
            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():
    rospy.init_node('smach_example_state_machine')

    # 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(), 
                               transitions={'outcome1':'FOO'})

    # Execute SMACH plan
    outcome = sm.execute()

if __name__ == '__main__':
    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

  <buildtool_depend>smach</buildtool_depend>
  <buildtool_depend>smach_ros</buildtool_depend>
  <buildtool_depend>smach_msgs</buildtool_depend>
  <buildtool_depend>rospy</buildtool_depend>
  <run_depend>rospy</run_depend>
  <run_depend>smach</run_depend>
  <run_depend>smach_ros</run_depend>
  <run_depend>smach_msgs</run_depend>

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:

smach_rosConfig.cmake
smach_ros-config.cmake

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
0

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

Stats

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

Seen: 219 times

Last updated: Jan 12 '15