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

smach_ros.MonitorState callback receives empty userdata

asked 2012-02-21 08:05:27 -0500

Loy gravatar image

updated 2014-01-28 17:11:26 -0500

ngrennan gravatar image

For our AMIGO robot, I'm building a very simple state machine in smach for asking questions and asking for confirmation of the answers.

After posing the question via text-to-speech, the statemachine waits for the answer from speech-to-text with a MonitorState called WAIT_ANSWER. The callback for the MonitorState simply checks if there are any options given (Yes, the robot reads mentions them when asking the question), and then if the answer given is one of the options.

Sounds simple, but somehow the userdata in the callback only contains an empty instance of smach.Remapper. The msg-parameter of the callback does get the correct value.

When running, the state machine containing the state _does_ have the userdata 'question_senstence' and 'options'. In Smach Viewer, it also looks fine.

The fact that there are no tutorials on MonitorState doesn't help, so my implementation is based on my interpretation of the source code.

Does anyone have any experience with MonitorStates?

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
1

answered 2013-10-16 00:03:03 -0500

bajo gravatar image

Hi,

I had the same problem. I use MonitorState in a Concurrence container and want to store some data in userdata.

To get it working i had to do the following:

In file monitor_state.py i changed line 29 from

self._sub = rospy.Subscriber(self._topic, self._msg_type, self._cb, callback_args=[ud])

to

self._sub = rospy.Subscriber(self._topic, self._msg_type, self._cb, callback_args=ud)

and overloaded the smach_ros.MonitorState.__init__ function to accept my desired input and output keys.

class MonitorState2(smach_ros.MonitorState):
    def __init__(self, topic, msg_type, cond_cb, max_checks=-1):
    smach.State.__init__(self,
            outcomes=['nav_error', 'pose_reached'],
            input_keys=['user_pose'],
            output_keys=['user_pose', 'robot_current_pose'])

    self._topic = topic 
    self._msg_type = msg_type 
    self._cond_cb = cond_cb 
    self._max_checks = max_checks 
    self._n_checks = 0 

    self._trigger_cond = threading.Condition()
edit flag offensive delete link more

Comments

I know it's an old thread but could you explain to me why you have to change the [ud] of the Subscriber and why it is not like this in the original implementation ? Thanks.

Maya gravatar image Maya  ( 2014-06-18 01:09:56 -0500 )edit

Otherwise the userdata would not have passed to the next state. Nowadays I use the WaitForMsgState to retrieve data from a topic. You can find it on this page http://wiki.ros.org/executive_smach/AdditionalStateTypes

bajo gravatar image bajo  ( 2014-06-22 07:20:32 -0500 )edit

Yeah so apparently callback_args in rospy.Subscriber isn't an array of arguments, but just the single additional argument passed to subscriber callbacks. I.e. this is the correct usage: https://gist.github.com/jbohren/085c5...

jbohren gravatar image jbohren  ( 2015-03-15 12:56:55 -0500 )edit
jbohren gravatar image jbohren  ( 2015-03-15 12:57:04 -0500 )edit
0

answered 2012-03-16 07:24:36 -0500

phil0stine gravatar image

I have just enough experience to have similar problems.

MonitorState, as far as i can tell, just wraps ConditionState with a ros subscriber. Once the condition from ConditionState fails, MonitorState outcome switches from valid to invalid.

This does not directly answer the question, I know. I tried to fallback to testing callbacks with ConditionState, but I still receive an empty userdata dict.

I used the examples from pr2_plugs to test the ConditionState. Maybe you will get insight from this. If so, please share :-)

edit flag offensive delete link more

Comments

In this api documentation MonitorState extends State, not ConditionState.

felix k gravatar image felix k  ( 2012-12-10 05:41:26 -0500 )edit
1

answered 2012-06-13 19:13:11 -0500

lindzey gravatar image

@phil0stine asked a question whose answer may help you out.

Also, I just updated the MonitorState documentation with an example, in case that helps.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2012-02-21 08:05:27 -0500

Seen: 1,042 times

Last updated: Oct 16 '13