WUT Velma robot API
reachability_range.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 
6 
7 # Copyright (c) 2017, Robot Control and Pattern Recognition Group,
8 # Institute of Control and Computation Engineering
9 # Warsaw University of Technology
10 #
11 # All rights reserved.
12 #
13 # Redistribution and use in source and binary forms, with or without
14 # modification, are permitted provided that the following conditions are met:
15 # * Redistributions of source code must retain the above copyright
16 # notice, this list of conditions and the following disclaimer.
17 # * Redistributions in binary form must reproduce the above copyright
18 # notice, this list of conditions and the following disclaimer in the
19 # documentation and/or other materials provided with the distribution.
20 # * Neither the name of the Warsaw University of Technology nor the
21 # names of its contributors may be used to endorse or promote products
22 # derived from this software without specific prior written permission.
23 #
24 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 # DISCLAIMED. IN NO EVENT SHALL <COPYright HOLDER> BE LIABLE FOR ANY
28 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #
35 # Author: Dawid Seredynski
36 #
37 
38 import roslib; roslib.load_manifest('rcprg_ros_utils')
39 
40 import rospy
41 import math
42 import numpy as np
43 import PyKDL
44 from geometry_msgs.msg import *
45 from visualization_msgs.msg import *
46 from rcprg_ros_utils import marker_publisher
47 
48 def spherePoints(R, step):
49  points = []
50  u_steps = max(1, int(math.pi*R/step))
51  for u in np.linspace(-math.pi/2, math.pi/2, u_steps):
52  # calculate radius of circle
53  r = R * math.cos(u)
54  L = 2*math.pi*r
55  v_steps = max(1, int(L/step))
56  y = R * math.sin(u)
57  for v in np.linspace(-math.pi, math.pi, v_steps):
58  x = math.cos(v) * r
59  z = math.sin(v) * r
60  points.append(PyKDL.Vector(x,y,z))
61  return points
62 
64  edges = [(30, 26), (20, 25), (28, 41), (0, 1), (18, 19), (28, 26), (2, 5), (37, 35),
65  (6, 7), (20, 35), (11, 22), (27, 28), (7, 19), (17, 23), (40, 38), (35, 36),
66  (17, 36), (37, 41), (29, 30), (8, 21), (6, 0), (19, 24), (11, 21), (27, 40),
67  (8, 38), (33, 34), (34, 41), (3, 1), (24, 36), (15, 16), (6, 16), (39, 35),
68  (41, 40), (14, 33), (36, 34), (23, 12), (10, 3), (14, 22), (21, 27), (12, 13),
69  (34, 32), (17, 24), (1, 10), (33, 29), (37, 34), (8, 25), (16, 17), (11, 9),
70  (24, 15), (11, 26), (16, 23), (36, 32), (8, 3), (38, 39), (34, 31), (27, 38),
71  (14, 12), (23, 33), (13, 9), (32, 23), (22, 30), (13, 22), (4, 8), (36, 37),
72  (5, 13), (39, 37), (30, 31), (17, 15), (32, 33), (29, 22), (2, 13), (5, 0),
73  (14, 23), (35, 24), (6, 19), (31, 29), (11, 30), (25, 18), (1, 4), (38, 25),
74  (14, 29), (7, 0), (5, 16), (20, 24), (39, 40), (22, 9), (28, 40), (18, 7),
75  (6, 15), (33, 31), (4, 7), (10, 11), (5, 6), (4, 18), (19, 15), (10, 21),
76  (40, 37), (1, 2), (2, 9), (5, 12), (25, 39), (30, 28), (20, 39), (20, 18),
77  (26, 21), (17, 32), (2, 10), (9, 10), (4, 25), (19, 20), (16, 12), (31, 28),
78  (1, 7), (26, 27), (31, 41), (13, 14), (21, 3), (2, 0), (4, 3), (8, 27)]
79 
80  points = [(0.0, 0.0, -0.5), (0.212661, -0.154506, -0.425327), (-0.081228, -0.249998, -0.425327),
81  (0.361804, -0.262863, -0.22361), (0.425324, 0.0, -0.262868), (-0.262865, 0.0, -0.425326),
82  (-0.081228, 0.249998, -0.425327), (0.212661, 0.154506, -0.425327), (0.475529, -0.154506, 0.0),
83  (-0.138194, -0.425325, -0.22361), (0.131434, -0.404506, -0.262869), (0.0, -0.5, 0.0),
84  (-0.447213, 0.0, -0.223608), (-0.344095, -0.249998, -0.262868), (-0.475529, -0.154506, 0.0),
85  (-0.138194, 0.425325, -0.22361), (-0.344095, 0.249998, -0.262868), (-0.293893, 0.404508, 0.0),
86  (0.361804, 0.262863, -0.22361), (0.131434, 0.404506, -0.262869), (0.293893, 0.404508, 0.0),
87  (0.293893, -0.404508, 0.0), (-0.293893, -0.404508, 0.0), (-0.475529, 0.154506, 0.0),
88  (0.0, 0.5, 0.0), (0.475529, 0.154506, 0.0), (0.138194, -0.425325, 0.22361),
89  (0.344095, -0.249998, 0.262868), (0.081228, -0.249998, 0.425327), (-0.361804, -0.262863, 0.22361),
90  (-0.131434, -0.404506, 0.262869), (-0.212661, -0.154506, 0.425327), (-0.361804, 0.262863, 0.22361),
91  (-0.425324, 0.0, 0.262868), (-0.212661, 0.154506, 0.425327), (0.138194, 0.425325, 0.22361),
92  (-0.131434, 0.404506, 0.262869), (0.081228, 0.249998, 0.425327), (0.447213, 0.0, 0.223608),
93  (0.344095, 0.249998, 0.262868), (0.262865, 0.0, 0.425326), (0.0, 0.0, 0.5)]
94 
95  points_kdl = []
96  for e in edges:
97  pt0 = points[e[0]]
98  pt1 = points[e[1]]
99  points_kdl.append(R*PyKDL.Vector(pt0[0], pt0[1], pt0[2]))
100  points_kdl.append(R*PyKDL.Vector(pt1[0], pt1[1], pt1[2]))
101  return points_kdl
102 
103 if __name__ == "__main__":
104  rospy.init_node('reachability_range', anonymous=False)
105 
106  visualization_mode = rospy.get_param('~visualization_mode', 'icosphere')
107  assert visualization_mode == 'solid_sphere' or visualization_mode == 'uvsphere' or visualization_mode == 'icosphere'
108 
109  inner_size = float(rospy.get_param('~inner_size'))
110  outer_size = float(rospy.get_param('~outer_size'))
111  marker_namespace = rospy.get_param('~marker_namespace')
112  frame_id = rospy.get_param('~frame_id')
113  cr = rospy.get_param('~color_r')
114  cg = rospy.get_param('~color_g')
115  cb = rospy.get_param('~color_b')
116 
117  rospy.sleep(0.5)
118 
119  pub = marker_publisher.MarkerPublisher('/reachability_range')
120 
121  if visualization_mode == 'solid_sphere' or visualization_mode == 'uvsphere':
122  inner_pts = spherePoints(inner_size*0.5, 0.2)
123  outer_pts = spherePoints(outer_size*0.5, 0.2)
124  elif visualization_mode == 'icosphere':
125  inner_pts = icosphereEdges(inner_size)
126  outer_pts = icosphereEdges(outer_size)
127 
128  while not rospy.is_shutdown():
129  m_id = 0
130  if visualization_mode == 'solid_sphere':
131  # visualize as solid spheres with alpha=0.5
132  m_id = pub.publishSinglePointMarker(PyKDL.Vector(), m_id, r=cr*0.7, g=cg*0.7, b=cb*0.7, a=0.5, namespace=marker_namespace,
133  frame_id=frame_id, m_type=Marker.SPHERE, scale=Vector3(inner_size, inner_size, inner_size), T=None)
134  m_id = pub.publishSinglePointMarker(PyKDL.Vector(), m_id, r=cr, g=cg, b=cb, a=0.5, namespace=marker_namespace,
135  frame_id=frame_id, m_type=Marker.SPHERE, scale=Vector3(outer_size, outer_size, outer_size), T=None)
136  elif visualization_mode == 'uvsphere':
137  # visualize as lines of uv sphere
138  m_id = pub.publishLineStripMarker(inner_pts, m_id, r=cr*0.7, g=cg*0.7, b=cb*0.7, a=1, namespace=marker_namespace, frame_id=frame_id, width=0.01, T=None)
139  m_id = pub.publishLineStripMarker(outer_pts, m_id, r=cr, g=cg, b=cb, a=1, namespace=marker_namespace, frame_id=frame_id, width=0.01, T=None)
140  elif visualization_mode == 'icosphere':
141  # visualize as lines of icosphere
142  m_id = pub.publishLineListMarker(inner_pts, m_id, r=cr*0.7, g=cg*0.7, b=cb*0.7, a=1, namespace=marker_namespace, frame_id=frame_id, width=0.01, T=None)
143  m_id = pub.publishLineListMarker(outer_pts, m_id, r=cr, g=cg, b=cb, a=1, namespace=marker_namespace, frame_id=frame_id, width=0.01, T=None)
144 
145  try:
146  rospy.sleep(0.1)
147  except:
148  break
149