fake_cart_joint_state_publisher.py
Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 # Copyright (c) 2008, Willow Garage, Inc.
00003 # All rights reserved.
00004 #
00005 # Redistribution and use in source and binary forms, with or without
00006 # modification, are permitted provided that the following conditions are met:
00007 #
00008 #         * Redistributions of source code must retain the above copyright
00009 #             notice, this list of conditions and the following disclaimer.
00010 #         * Redistributions in binary form must reproduce the above copyright
00011 #             notice, this list of conditions and the following disclaimer in the
00012 #             documentation and/or other materials provided with the distribution.
00013 #         * Neither the name of the Willow Garage, Inc. nor the names of its
00014 #             contributors may be used to endorse or promote products derived from
00015 #             this software without specific prior written permission.
00016 #
00017 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027 # POSSIBILITY OF SUCH DAMAGE.
00028 
00029 # Author: Jon Scholz
00030 
00031 PKG="pr2_gazebo_cartworld"
00032 import roslib; roslib.load_manifest(PKG)
00033 import rospy
00034 import time
00035 import sys
00036 import threading
00037 
00038 import tf
00039 from sensor_msgs.msg import *
00040 from geometry_msgs.msg import *
00041 
00042 class cart_joint_state_publisher:
00043     def __init__(self):
00044         """Fake publisher for cart joint states
00045         
00046         Arguments:
00047         - `self`:
00048         """
00049         self._joint_state_pub = rospy.Publisher("cart_joint_states", JointState)
00050 
00051         self.tb = tf.TransformBroadcaster()
00052 
00053         # Make the message just once since nothing is changing...
00054         self.jointstate = JointState()
00055         self.jointstate.header.stamp = rospy.Time.now()
00056         self.jointstate.name = ["base_top_joint", "handle_joint","front_right_caster", 
00057                                 "front_left_caster", "front_right_wheel", "front_left_wheel",
00058                                 "back_right_caster", "back_left_caster", "back_right_wheel",
00059                                 "back_left_wheel"]
00060         self.jointstate.position = [0.0] * len(self.jointstate.name)
00061         self.jointstate.velocity = [0.0] * len(self.jointstate.name)
00062         self.jointstate.effort = [0.0] * len(self.jointstate.name)
00063 
00064         # Set a transform from the "base" link in the cart urdf to the "cart" frame
00065         self.base_pose = PoseStamped(pose=Pose(position=Point(0.0, 0.0, 0.0),
00066                                                orientation=Quaternion(0.0, 0.0, 0.0, 1.0)))
00067         self.base_pose.header.stamp = rospy.Time.now()
00068         self.base_pose_tup = self.pose_msg_to_tuple(self.base_pose.pose)
00069 
00070         # set up thread
00071         self.thread = threading.Thread(target=self._pub_thread, args = (10,))
00072         self.thread.setDaemon(1)
00073         self.alive = threading.Event()
00074         self.alive.set()
00075         self.thread.start()
00076     
00077     def pose_msg_to_tuple(self, Pose):
00078       """Returns a list representation of Pose [[vector],[euler angles]]"""
00079       return ((Pose.position.x,
00080                Pose.position.y,
00081                Pose.position.z),
00082                (Pose.orientation.x,
00083                 Pose.orientation.y,
00084                 Pose.orientation.z,
00085                 Pose.orientation.w))
00086 
00087     def _pub_thread(self, rate):
00088         """
00089         """
00090         r=rospy.Rate(rate)
00091         while not rospy.is_shutdown() and self.alive.isSet():
00092             self.jointstate.header.stamp = rospy.Time.now()
00093             self.publish_cart_joint_states()
00094             self.tb.sendTransform(self.base_pose_tup[0],
00095                                   self.base_pose_tup[1], 
00096                                   rospy.get_rostime(),
00097                                   "base", "cart")
00098             r.sleep()
00099     
00100     def publish_cart_joint_states(self):
00101         """Publish dummy values
00102         """
00103         self._joint_state_pub.publish(self.jointstate)
00104 
00105 if __name__ == '__main__':
00106     #from optparse import OptionParser
00107     #parser = OptionParser(usage="")
00108     #parser.add_option("-x", dest="cart_pose_x", default=0.0,
00109     #                  help="x displacement of cart model from \"cart\" frame in tf")
00110     #(options, args) = parser.parse_args()
00111     rospy.init_node("cart_joint_state_publisher")
00112     c=cart_joint_state_publisher()
00113     rospy.spin()
00114     


pr2_gazebo_cartworld
Author(s): Jonathan Scholz
autogenerated on Tue Jan 7 2014 11:09:31