pubGoalSlagpotDown.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. x = 30.0
  46. y = 207.0
  47. yaw = -1.57
  48. p0 = geometry_msgs.msg.PoseStamped()
  49. p0.pose.position.x = x
  50. p0.pose.position.y = y
  51. # q = quaternion_from_euler(0.0 , 0.0 , yaw)
  52. # p0.pose.orientation.x = q[0]
  53. # p0.pose.orientation.y = q[1]
  54. # p0.pose.orientation.z = q[2]
  55. # p0.pose.orientation.w = q[3]
  56. # 定义欧拉角
  57. roll, pitch = 0.0, 0.0 # 用实际值替换
  58. q = quaternion_from_euler(roll, pitch, yaw)
  59. # 创建geometry_msgs/Quaternion类型的四元数
  60. quaternion_msg = geometry_msgs.msg.Quaternion(*q)
  61. p0.pose.orientation = quaternion_msg
  62. print("before client connected")
  63. client.wait_for_server()
  64. print("client connected")
  65. goal = hinge_car_nav_msgs.msg.HingeCarNavGoal()
  66. path = hinge_car_nav_msgs.msg.HingeCarPath()
  67. goal.goal_type = goal.UNLOAD_SLAGPOT
  68. # goal.slagpot_pose.header.frame_id = "world"
  69. # goal.slagpot_pose.header.stamp = rospy.Time.now()
  70. # goal.slagpot_pose.pose.orientation = p0.pose.orientation
  71. # goal.slagpot_pose.pose.position = p0.pose.position
  72. path.slagpot_pose = p0
  73. goal.path = path
  74. client.send_goal(goal, done_cb, active_cb, feedback_cb)
  75. # Sends the goal to the action server.
  76. # Waits for the server to finish performing the action.
  77. client.wait_for_result()
  78. client.get_result()
  79. try:
  80. # Initializes a rospy node so that the SimpleActionClient can
  81. # publish and subscribe over ROS.
  82. result = client.get_result()
  83. except rospy.ROSInterruptException:
  84. print("program interrupted before completion")
  85. rospy.sleep(5.0)