input_keypoint.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #coding=utf-8
3 
4 import rospy, sys, termios, tty
5 import yaml,json
6 
7 from geometry_msgs.msg import Pose, PoseStamped
8 from visualization_msgs.msg import Marker, MarkerArray
9 from move_base_msgs.msg import MoveBaseActionResult
10 
11 
12 
13 
14 
15 class input_kp():
16  """docstring for input_kp"""
17  def __init__(self):
18  self.total_kp = input('请输入所有关键点的个数:\n')
19  # print type(self.total_kp)
20  # print self.total_kp
21  self.num_kp = 1
22  self.kp = []
23  self.marker=Marker()
24  self.marker.color.r=1.0
25  self.marker.color.g=0.0
26  self.marker.color.b=0.0
27  self.marker.color.a=1.0
28  self.marker.ns='input_kp'
29  self.marker.scale.x=1
30  self.marker.scale.y=0.1
31  self.marker.scale.z=0.1
32  self.marker.header.frame_id='map'
33  self.marker.type=Marker.ARROW
34  self.marker.action=Marker.ADD
35  self.arraymarker = MarkerArray()
36  self.markers_pub = rospy.Publisher('/kp',MarkerArray,queue_size=1)
37  self.goal_sub = rospy.Subscriber('/goal',PoseStamped, self.mark_kpCB)
38 
39 
40 
41  tip = '请在rviz当中使用鼠标点击第 ' + str(self.num_kp) +' 个目标点的位置。'
42  print tip
43  rospy.spin()
44 
45  def mark_kpCB(self, pos):
46  if self.num_kp <= self.total_kp:
47  kptmp = {"recog": False, "play_words": "大家好,这是安徽省机器人比赛服务机器人项讲解机器人子项的比赛现场,我是您的机器人讲解员小德.我们本场比赛总共设置了两个讲解点,目前我们所在的位置比赛的是第一个讲解点.", "name": "", "pose": [[pos.pose.position.x,pos.pose.position.y,pos.pose.position.z],[pos.pose.orientation.x,pos.pose.orientation.y,pos.pose.orientation.z,pos.pose.orientation.w]], "play": True, "chat": False}
48 
49  self.kp.append(kptmp)
50  print self.kp
51 
52 
53  print 'added '+str(self.num_kp)+' keypoints'
54  self.marker.header.stamp =rospy.Time.now()
55  self.marker.pose = pos.pose
56  self.marker.id = self.num_kp
57  self.arraymarker.markers.append(self.marker)
58  self.markers_pub.publish(self.arraymarker)
59  tip = '请在rviz当中使用鼠标点击第' + str(self.num_kp+1) +' 个目标点的位置。'
60  print tip
61 
62  if self.num_kp == self.total_kp:
63  with open('kp.json', 'w') as f:
64  json.dump(self.kp,f,ensure_ascii=False)
65 
66  print '您已完成所有关键点的录入,关键点文件已成功存入运行目录下的keypoint.yaml文件,请使用ctrl+c退出程序即可。'
67 
68  self.num_kp+=1
69 
70  def goal_resultCB(self, result):
71  pass
72 
73 
74 
75 
76 
77 
78 if __name__ == '__main__':
79  rospy.init_node('input_kp_serve')
80  try:
81  rospy.loginfo('office lady initialized...')
82  input_kp()
83  except rospy.ROSInterruptException:
84  rospy.loginfo('office lady initialize failed, please retry...')
def goal_resultCB(self, result)
def mark_kpCB(self, pos)


xbot_navi
Author(s):
autogenerated on Sat Oct 10 2020 03:27:50