Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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
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
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
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
00107
00108
00109
00110
00111 rospy.init_node("cart_joint_state_publisher")
00112 c=cart_joint_state_publisher()
00113 rospy.spin()
00114