pubGoalSlagpotUp.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. import rospy
  4. # from std_msgs.msg import String
  5. # from hinge_car_nav_msgs.msg import HingeCarNavActionGoal
  6. from hinge_car_nav_msgs.msg import hinge_car_nav_msgs
  7. import geometry_msgs.msg
  8. # import sys
  9. # import tf
  10. from tf.transformations import quaternion_from_euler
  11. # import numpy as np
  12. # import sys
  13. # Brings in the SimpleActionClient
  14. # import yaml
  15. import actionlib
  16. # Brings in the messages used by the fibonacci action, including the
  17. # goal message and the result message.
  18. # from tf.transformations import quaternion_from_euler
  19. def callback(data):
  20. # rospy.loginfo(rospy.get_caller_id() + 'I heard %s', )
  21. rospy.loginfo('received move base action goal')
  22. # rospy.loginfo(data.goal_id)
  23. def done_cb(data, data1):
  24. print("action done cb:%d,%s" % (data, data1))
  25. def active_cb():
  26. print("active_cb")
  27. def feedback_cb(data):
  28. pass
  29. # print("feedback_cb x:%f,y%f", data.pose.position.x,data.pose.position.y)
  30. # print("feedback_cb ", data.base_position.pose.position.x )
  31. if __name__ == '__main__':
  32. # In ROS, nodes are uniquely named. If two nodes with the same
  33. # name are launched, the previous one is kicked off. The
  34. # anonymous=True flag means that rospy will choose a unique
  35. # name for our 'listener' node so that multiple listeners can
  36. # run simultaneously.
  37. rospy.init_node('action_client', anonymous=True)
  38. # rospy.Subscriber('/move_base/goal',MoveBaseActionGoal, callback)
  39. # goal_pub = rospy.Publisher('/move_base/goal',MoveBaseActionGoal)
  40. # (FibonacciAction) to the constructor.
  41. client = actionlib.SimpleActionClient(
  42. 'hinge_car_nav', hinge_car_nav_msgs.msg.HingeCarNavAction)
  43. # Waits until the action server has started up and started
  44. # listening for goals.
  45. # 192.653706,205.496984
  46. p0 = geometry_msgs.msg.PoseStamped()
  47. #p0.pose.position.x = 165.79 # 开始点位 165.797971,196.436970
  48. #p0.pose.position.y = 96.436
  49. # x = 192.65
  50. # y = 205.49
  51. # yaw = -1.526
  52. #1.537860),fork_pose:(196.880965,183.836425
  53. #虚拟包位
  54. #x = 196.88
  55. #y = 183.83
  56. #yaw = 1.537
  57. #156.042740,208.596165 -1.543 155.733523,208.609741 -1.560797
  58. #对包成功
  59. #x = 155.73304
  60. #y = 208.6096
  61. #yaw = -1.5607
  62. #178.045984,209.219726,-1.608619 N30
  63. #(78.512528,210.467081,-1.603034),
  64. x = 178.045984
  65. y = 209.219726
  66. yaw = -1.608619
  67. # q = quaternion_from_euler(0.0 , 0.0 , yaw)
  68. # p0.pose.orientation.x = q[0]
  69. # p0.pose.orientation.y = q[1]
  70. # p0.pose.orientation.z = q[2]
  71. # p0.pose.orientation.w = q[3]
  72. # 定义欧拉角
  73. roll, pitch = 0.0, 0.0 # 用实际值替换
  74. q = quaternion_from_euler(roll, pitch, yaw)
  75. # 创建geometry_msgs/Quaternion类型的四元数
  76. quaternion_msg = geometry_msgs.msg.Quaternion(*q)
  77. p0.pose.orientation = quaternion_msg
  78. p0.pose.position.x = x
  79. p0.pose.position.y = y
  80. print("before client connected")
  81. client.wait_for_server()
  82. print("client connected")
  83. goal = hinge_car_nav_msgs.msg.HingeCarNavGoal()
  84. path = hinge_car_nav_msgs.msg.HingeCarPath()
  85. goal.goal_type = goal.LOAD_SLAGPOT_IN
  86. goal.path.slagpot_pose = p0
  87. client.send_goal(goal, done_cb, active_cb, feedback_cb)
  88. # Sends the goal to the action server.
  89. # Waits for the server to finish performing the action.
  90. client.wait_for_result()
  91. client.get_result()
  92. try:
  93. # Initializes a rospy node so that the SimpleActionClient can
  94. # publish and subscribe over ROS.
  95. result = client.get_result()
  96. except rospy.ROSInterruptException:
  97. print("program interrupted before completion")
  98. rospy.sleep(5.0)