demo.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 '''This runs the "core" of the PbD backend.
00003 It handles the interactions between the GUI and the state of the world
00004 and recorded actions.
00005 It coordinates responses from the head and arms of the robot.
00006 '''
00007 
00008 # ######################################################################
00009 # Imports
00010 # ######################################################################
00011 
00012 # Core ROS imports come first.
00013 import rospy
00014 
00015 # ROS builtins
00016 from visualization_msgs.msg import MarkerArray
00017 from interactive_markers.interactive_marker_server import \
00018      InteractiveMarkerServer
00019 from tf import TransformListener
00020 import rospkg
00021 
00022 # Local
00023 from fetch_arm_control.msg import GripperState
00024 from fetch_pbd_interaction.session import Session
00025 from fetch_pbd_interaction.msg import ExecutionStatus
00026 from fetch_pbd_interaction.srv import Ping, PingResponse, GetObjectList
00027 from fetch_pbd_interaction.msg import RobotSound, WorldState
00028 from fetch_pbd_interaction.robot import Robot
00029 from std_msgs.msg import String
00030 from std_srvs.srv import Empty
00031 
00032 # ######################################################################
00033 # Module level constants
00034 # ######################################################################
00035 
00036 EXECUTION_Z_OFFSET = -0.00
00037 BASE_LINK = 'base_link'
00038 TOPIC_IM_SERVER = 'programmed_actions'
00039 
00040 
00041 # ######################################################################
00042 # Main Function
00043 # ######################################################################
00044 
00045 if __name__ == '__main__':
00046 
00047     # Register as a ROS node.
00048     rospy.init_node('fetch_session_interface_demo', anonymous=True)
00049 
00050     # Run the system
00051     tf_listener = TransformListener()
00052     robot = Robot(tf_listener)
00053     im_server = InteractiveMarkerServer(TOPIC_IM_SERVER)
00054     # Get path to example json file
00055     rospack = rospkg.RosPack()
00056     file_path = rospack.get_path('fetch_pbd_interaction') + \
00057                 "/examples/example_actions.json"
00058     session = Session(robot, tf_listener,
00059                       im_server, from_file=file_path)
00060 
00061     if session.n_actions() > 0:
00062         rospy.loginfo("There are {} actions.".format(session.n_actions()))
00063 
00064         # Select first action
00065         session.switch_to_action_by_index(0)
00066         # Execute first action
00067         rospy.loginfo("Executing action 0, " +
00068                       "with {} primitives.".format(session.n_primitives()))
00069         session.execute_current_action()
00070 
00071         # You can specify pauses between actions
00072         rospy.sleep(3)
00073 
00074         # You can also execute individual primitives
00075         if session.n_primitives() > 0:
00076             rospy.loginfo("Executing first primitive of first action")
00077             session.execute_primitive(0)
00078         else:
00079             rospy.loginfo("Action 0 has no primitives.")
00080 
00081         action_num = raw_input('Which action should we execute next? Enter 1 or 2:')
00082         action_num = int(action_num)
00083 
00084         rospy.loginfo("Executing action {}.".format(action_num))
00085         session.switch_to_action_by_index(action_num)
00086         session.execute_current_action()
00087 
00088         # You can also summon actions by name
00089         rospy.loginfo("Executing Wave action")
00090         session.switch_to_action_by_name("Wave")
00091         session.execute_current_action()
00092 
00093     else:
00094         rospy.logwarn("No actions available!")
00095 


fetch_pbd_interaction
Author(s): Sarah Elliott
autogenerated on Thu Jun 6 2019 18:27:21