teleop.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #       
00003 # License: BSD
00004 #   https://raw.github.com/robotics-in-concert/concert_services/license/LICENSE
00005 #
00006 ##############################################################################
00007 # About
00008 ##############################################################################
00009 
00010 # Simple teleop for a turtlesim turtle. It relays cmd_vel's to the
00011 # turtlesim cmd_vel underneath and also publishes a fake compressed image view
00012 # (real robots would send an image stream).
00013 
00014 ##############################################################################
00015 # Imports
00016 ##############################################################################
00017 
00018 import rospy
00019 import geometry_msgs.msg as geometry_msgs
00020 import sensor_msgs.msg as sensor_msgs
00021 import rocon_python_utils
00022 
00023 ##############################################################################
00024 # Classes
00025 ##############################################################################
00026 
00027 
00028 class TurtleTeleop:
00029     '''
00030       Shepherds the turtles! This is the implementation node for the
00031       turtle_concert/teleop rapp.
00032 
00033       @todo get alised names from the concert client list if the topic is available
00034 
00035       @todo watchdog for killing turtles that are no longer connected.
00036     '''
00037     __slots__ = [
00038         'simulation_namespace',
00039         'cmd_vel_subscriber',
00040         'cmd_vel_publisher',
00041         'image_publisher',
00042     ]
00043 
00044     def __init__(self):
00045         try:
00046             self.simulation_namespace = rospy.get_param("~simulation_namespace")
00047         except KeyError:
00048             rospy.logerr("Turtle Teleop : failed to get the turtle name from the parameter server.")
00049         # Set up a simple relay here to the underlying cmd vel handle to the turtlesim engine.
00050         self.cmd_vel_subscriber = rospy.Subscriber("cmd_vel", geometry_msgs.Twist, self.ros_cmd_vel_callback)
00051         self.cmd_vel_publisher = rospy.Publisher(self.simulation_namespace + '/cmd_vel', geometry_msgs.Twist, queue_size=5)
00052         self.image_publisher = rospy.Publisher('compressed_image', sensor_msgs.CompressedImage, latch=True, queue_size=1)
00053         self.publish_teleop_image()
00054 
00055     def ros_cmd_vel_callback(self, msg):
00056         '''
00057           Just relay this to the turtlesim engine's handle.
00058         '''
00059         self.cmd_vel_publisher.publish(msg)
00060 
00061     def publish_teleop_image(self):
00062         '''
00063           Currently we only do this once as it is a static image.
00064         '''
00065         msg = sensor_msgs.CompressedImage()
00066         msg.header.stamp = rospy.Time.now()
00067         msg.format = 'png'
00068         image_filename = rocon_python_utils.ros.find_resource_from_string('rocon_bubble_icons/turtle_teleop.png')
00069         msg.data = open(image_filename, "rb").read()
00070         self.image_publisher.publish(msg)
00071 
00072 ##############################################################################
00073 # Launch point
00074 ##############################################################################
00075 
00076 if __name__ == '__main__':
00077 
00078     rospy.init_node('turtle_teleop')
00079 
00080     turtle_teleop = TurtleTeleop()
00081     rospy.spin()


turtle_concert
Author(s): Daniel Stonier , Jihoon Lee
autogenerated on Fri Feb 12 2016 02:51:42