pubInitPose.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/usr/bin/env python
  2. import rospy
  3. from geometry_msgs.msg import PoseStamped
  4. from geometry_msgs.msg import PoseWithCovarianceStamped
  5. # Brings in the messages used by the fibonacci action, including the
  6. # goal message and the result message.
  7. from tf.transformations import quaternion_from_euler
  8. def callback(data):
  9. # rospy.loginfo(rospy.get_caller_id() + 'I heard %s', )
  10. rospy.loginfo('received move base action goal')
  11. # rospy.loginfo(data.goal_id)
  12. def done_cb(data, data1):
  13. print("action done cb:%d,%s" % (data, data1))
  14. def active_cb():
  15. print("active_cb")
  16. def feedback_cb(data):
  17. pass
  18. # print("feedback_cb x:%f,y%f", data.pose.position.x,data.pose.position.y)
  19. # print("feedback_cb ", data.base_position.pose.position.x )
  20. if __name__ == '__main__':
  21. # In ROS, nodes are uniquely named. If two nodes with the same
  22. # name are launched, the previous one is kicked off. The
  23. # anonymous=True flag means that rospy will choose a unique
  24. # name for our 'listener' node so that multiple listeners can
  25. # run simultaneously.
  26. rospy.init_node('init_pose_pub', anonymous=True)
  27. # rospy.Subscriber('/move_base/goal',MoveBaseActionGoal, callback)
  28. # rospy.Subscriber('/move_base/goal',MoveBaseActionGoal, callback)
  29. goal_pub = rospy.Publisher("/Pose", PoseStamped, queue_size=10)
  30. init_pose_pub = rospy.Publisher("/initialpose", PoseWithCovarianceStamped,
  31. queue_size=10)
  32. r = rospy.Rate(10)
  33. rospy.sleep(2.0)
  34. # while (1):
  35. # x = 45.5 # 35
  36. # y = -7.8
  37. # z = 2.287
  38. # yaw = 0.0
  39. x = 0.0 # 35
  40. y = 0.0
  41. z = 0.0
  42. yaw = 0.0
  43. pose_msg = PoseStamped()
  44. q = quaternion_from_euler(0.0, 0, yaw)
  45. initPose = PoseWithCovarianceStamped()
  46. initPose.pose.pose.orientation.x = q[0]
  47. initPose.pose.pose.orientation.y = q[1]
  48. initPose.pose.pose.orientation.z = q[2]
  49. initPose.pose.pose.orientation.w = q[3]
  50. initPose.pose.pose.position.x = x
  51. initPose.pose.pose.position.y = y
  52. initPose.pose.pose.position.z = z
  53. initPose.header.frame_id = "map"
  54. initPose.header.stamp = rospy.Time.now()
  55. init_pose_pub.publish(initPose)
  56. print("pub init pose")
  57. # rospy.spin()
  58. # pose_msg.pose.position.x = x
  59. # pose_msg.pose.position.y = y
  60. # pose_msg.pose.position.z = z
  61. # pose_msg.pose.orientation.x = q[0]
  62. # pose_msg.pose.orientation.y = q[1]
  63. # pose_msg.pose.orientation.z = q[2]
  64. # pose_msg.pose.orientation.w = q[3]
  65. # pose_msg.header.stamp = rospy.Time.now()
  66. # pose_msg.header.frame_id = "map"
  67. # goal_pub.publish(pose_msg)
  68. # print("send msg")
  69. # r.sleep()