scale_interaction.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import rospy
4 from geometry_msgs.msg import Polygon, Point32, PolygonStamped
5 from std_msgs.msg import Float32
6 from threading import Lock
7 
8 width_scale = None
9 height_scale = None
10 pending_polygon = None
11 lock = Lock()
12 
14  global width_scale
15  with lock:
16  if msg.data == 0:
17  rospy.logdebug("scale is 0!, we skip it")
18  else:
19  width_scale = msg.data
21 
23  global height_scale
24  with lock:
25  if msg.data == 0:
26  rospy.logdebug("scale is 0!, we skip it")
27  else:
28  height_scale = msg.data
30 
31 def polygonCallback(msg):
32  global pending_polygon
33  with lock:
34  if width_scale and height_scale:
36  else:
37  pending_polygon = msg
38 
40  global pending_polygon, width_scale, height_scale
41  if (pending_polygon and width_scale and height_scale
42  and width_scale != 0 and height_scale != 0):
43  publishResizedPolygon(pending_polygon)
44  pending_polygon = None
45 
46 def publishResizedPolygon(poly_msg):
47  global width_scale, height_scale, inverse, pub
48  if inverse:
49  Rw = 1.0 / width_scale
50  Rh = 1.0 / height_scale
51  else:
52  Rw = width_scale
53  Rh = height_scale
54  for point in poly_msg.polygon.points:
55  point.x = Rw * point.x
56  point.y = Rh * point.y
57  pub.publish(poly_msg)
58 
59 rospy.init_node("scale_interaction")
60 
61 inverse = rospy.get_param("~inverse", False)
62 pub = rospy.Publisher("~output", PolygonStamped)
63 sub_polygon = rospy.Subscriber("~input", PolygonStamped, polygonCallback)
64 sub_width = rospy.Subscriber("~input/width_scale", Float32, widthScallCallback)
65 sub_height = rospy.Subscriber("~input/height_scale", Float32, heightScallCallback)
66 
67 rospy.spin()
def publishResizedPolygon(poly_msg)
def heightScallCallback(msg)


image_view2
Author(s): Kei Okada
autogenerated on Tue Feb 6 2018 03:45:03