ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
You should really be using classes. But here is a hack that works
#!/usr/bin/env python
import rospy
from geometry_msgs.msg import PoseWithCovarianceStamped
from geometry_msgs.msg import TransformStamped
pub = rospy.Publisher('pose_after', TransformStamped, queue_size=40)
pose_after = TransformStamped()
def callback(data):
pose_after.header.stamp = rospy.Time.now()
pose_after.child_frame_id = 'base_footprint'
pose_after.transform.translation.x = data.pose.pose.position.x
pose_after.transform.translation.y = data.pose.pose.position.y
pose_after.transform.translation.z = data.pose.pose.position.z
pose_after.transform.rotation.x = data.pose.pose.orientation.x
pose_after.transform.rotation.y = data.pose.pose.orientation.y
pose_after.transform.rotation.z = data.pose.pose.orientation.z
pose_after.transform.rotation.w = data.pose.pose.orientation.w
print(pose_after.transform) # this prints (0,0)
pub.publish(pose_after)
def listener():
rospy.init_node('translater', anonymous=True)
rospy.loginfo("Publishing pose_after")
rospy.Subscriber('pose_before', PoseWithCovarianceStamped, callback)
rate = rospy.Rate(40)
while not rospy.is_shutdown():
rate.sleep()
if __name__ == '__main__':
try:
listener()
except rospy.ROSInterruptException:
pass
In your original callback, you are trying to populate TransformStamped() which is a msg type, not a msg. you should be able to echo the pose_after topic and listen in on the new msgs now.