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

call a class method inside callback for CBState

asked 2017-09-06 00:51:02 -0600

amarbanerjee23 gravatar image

Hi all, I wish to call a class method inside the callback method for CBState. However, the callback method does not have a self parameter. When I call a class method from inside the callback I get the exception "User data key 'class_method_name' not available. Available keys :[]". Is there any specific way to do this ?

Any hint or help would be a great help !!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-09-07 02:05:15 -0600

amarbanerjee23 gravatar image

updated 2019-04-11 18:40:59 -0600

jayess gravatar image

Hi all, I found the answer. We need to pass the methods in the cb_args[]. E.g.

smach.StateMachine.add('STATE1',CBState(
    self.my_call_back,cn_args=[self.class_method_tobe_called_inside_call_back]))

Then in the part of @smach.cb_interface(), we need to pass a function name in the input_keys[] E.g.

@smach.cb_interface(input_keys['class_method_to_call_inside_callback'])

Then inside the callback simply call the method with the same name as passed in the input keys e.g

@smach.cb_interface(input_keys['**method_to_call'**])
def my_call_back(self,method_to_call):
    method_to_call()
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2017-09-06 00:51:02 -0600

Seen: 284 times

Last updated: Apr 11 '19