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

Smach Userdata Input/Output keys error

asked 2016-02-12 04:20:35 -0500

MartinI gravatar image

[ERROR] [WallTime: 1455271923.018549] [44.655000] Userdata key 'error_bool' not available. Available keys are: ['parameters']

I keep getting this error... Anybody has a clue why is this happening?

This is how the definition of the states and the state machine are done:


def main(self):

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

    # Open the container
    with sm:
        # Add states to the container
        smach.StateMachine.add('Ready', ready_state.Ready(), 
                               transitions={'cartesianMotionRequest':'CartesianMotion', \
                                            'articularMotionRequest':'ArticularMotion', \
                                            'fullBodyMotionRequest':'FullBodyMotion', \
                                            'endEffectorRequest':'EndEffectorCoordination', \
                                            'trajectoryExecutionRequest':'TrajectoryExecution', \
                                            'failure':'ErrorHandling', \
                                            'recordTrajectoryRequest':'RecordTrajectory', \
                                            'changeEndEffectorRequest':'ChangeEndEffector', \
                                            'exit':'Finish'},
                               remapping={ 'error_bool':'error_bool',
                                            'parameters':'parameters' })
        smach.StateMachine.add('CartesianMotion', cartesian_motion_state.CartesianMotion(self.hiro), 
                               transitions={'success':'Ready', \
                                           'failure':'ErrorHandling'},                                           
                               remapping={'parameters':'parameters',
                                          'error_bool':'error_bool'})

________________________________________________________________________________________-

class Ready(smach.State):
def __init__(self):
    smach.State.__init__(self,                     
outcomes=['cartesianMotionRequest', \
                                   'articularMotionRequest', \
                                   'fullBodyMotionRequest', \
                                   'endEffectorRequest', \
                                   'trajectoryExecutionRequest', \
                                   'failure', 'recordTrajectoryRequest', \
                                   'changeEndEffectorRequest', 'exit'], \
                         output_keys=['parameters'],
                         input_keys=['error_bool']
                         )

    class CartesianMotion(smach.State): 
    def __init__(self, robot):
    smach.State.__init__(self, outcomes=['success', 'failure'],
                         input_keys=['parameters'], 
                         output_keys=['error_bool']
                        )
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-04-06 13:20:04 -0500

ski11io gravatar image

You should init the userdata key before you call it:

i.e.

    sm.userdata.error_bool = False

i copy pasted your code and applied some simplification (you can ignore the introspection/threading stuff at the bottom). Try below to test it:


#!/usr/bin/env python
# This Python file uses the following encoding: utf-8

import roslib
import rospy
import threading

import smach
from smach import StateMachine

import smach_ros
from smach_ros import IntrospectionServer, SimpleActionState

class Ready(smach.State):
    def __init__(self):
        smach.State.__init__(self,                     
                         outcomes=['test'],
                         output_keys=['parameters'],
                         input_keys=['error_bool']
                         )

    def execute(self, userdata):
        rospy.loginfo("ready state key error_bool: "+str(userdata.error_bool))
        rospy.sleep(1)
        userdata.parameters = ['some param'];
        return 'test'   



class CartesianMotion(smach.State): 
    def __init__(self):
        smach.State.__init__(self, outcomes=['success', 'failure'],
                         input_keys=['parameters','error_bool'], 
                         output_keys=['error_bool'])
    def execute(self, userdata):
        rospy.loginfo("cartesian state key parameters: "+str(userdata.parameters))  
        rospy.sleep(1)  

        return 'success'             


def main():
    rospy.init_node('test')#, log_level=rospy.DEBUG)

    # Create a SMACH state machine
    sm = smach.StateMachine(outcomes=['succeeded','aborted','preempted'])
    sm.userdata.parameters = []
    sm.userdata.error_bool = False

    # Open the container
    with sm:
        # Add states to the container
        smach.StateMachine.add('Ready', Ready(), 
                               transitions={'test':'CartesianMotion'})

        smach.StateMachine.add('CartesianMotion', CartesianMotion(), 
                               transitions={'success':'succeeded', 'failure':'aborted'})

    #setup introspection  
    sis = IntrospectionServer('server_name', sm, '/Test')
    sis.start()

    #set preemption handler
    smach_ros.set_preempt_handler(sm)

    # Create a thread to execute the smach container
    smach_thread = threading.Thread(target = sm.execute)
    smach_thread.start()

    # Wait for ctrl-c
    rospy.spin()

    # Request the container to preempt
    sm.request_preempt()

    # Block until everything is preempted 
    # (you could do something more complicated to get the execution outcome if you want it)
    smach_thread.join()

    #stop introspection
    sis.stop()



if __name__ == '__main__':
    main()



With the introspectionserver you can also use smach_viewer to check the states of your userdata keys / check your state machine:

image description

Hope this helps :)

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2016-02-12 04:20:35 -0500

Seen: 1,450 times

Last updated: Feb 12 '16