|Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.|
Simplifying Integration of ROS Actions with SimpleStateBaseDescription: Demonstrates a simpler method to create state editor for actions.
Tutorial Level: INTERMEDIATE
Next Tutorial: Creating Editors for SMACH States That Has Inputs and Outputs
Creating a state editor can be a cumbersome affair requiring the creation of three separate states: smach.State, rcommander.tool_utils.StateBase, and rcommander.tool_utils.ToolBase. However, it is possible to simplify this to two when using RCommander, as with SMACH, on ROS actions. The key here is to eliminate the extra class which inherits from SMACH with the RCommander convenience class SimpleStateBase. For example, let's say we want to call the PR2 action torso_controller/position_joint_action the code for that using SimpleStateBase is simply:
1 import rcommander.tool_utils as tu 2 import pr2_controllers_msgs.msg as pm 3 4 class SpineState(tu.SimpleStateBase): 5 6 def __init__(self, name, position): 7 tu.SimpleStateBase.__init__(self, name, \ 8 'torso_controller/position_joint_action', 9 pm.SingleJointPositionAction, 10 goal_cb_str = 'ros_goal') 11 self.position = position 12 13 def ros_goal(self, userdata, default_goal): 14 return pm.SingleJointPositionGoal(position = self.position)
In the above call, we inherit from SimpleStateBase and in the initializer we pass in the name of the node, the action to call, the action message to use, and a string representing the function to call on our inherited class. The only remaining item to make happen is to implement a class that inherits from rcommander.tool_utils.ToolBase.
Next, we'll learn out to create editors for Smach states that passes data to each other!