$search
00001 import roslib 00002 roslib.load_manifest('occupancy_grid_utils') 00003 import rospy 00004 import nav_msgs.msg as nm 00005 import geometry_msgs.msg as gm 00006 import sensor_msgs.msg as sm 00007 00008 from occupancy_grid_utils import * 00009 import math 00010 from .str import * 00011 00012 def make_pose(x, y, th): 00013 p = Pose() 00014 p.position.x = x 00015 p.position.y = y 00016 p.orientation.w = math.cos(th/2) 00017 p.orientation.z = math.sin(th/2) 00018 return p 00019 00020 ############################################################ 00021 # Python wrappers around library functions 00022 ############################################################ 00023 00024 def nav_distance(nav_fn, dest): 00025 res = sssp_distance_internal(nav_fn, dest) 00026 if res>=0: 00027 return res 00028 else: 00029 return None 00030 00031 ############################################################ 00032 # Conversion to ROS message types so we can publish them 00033 ############################################################ 00034 00035 def time_to_ros(t): 00036 return rospy.Time(t.sec, t.nsec) 00037 00038 def time_from_ros(t): 00039 t2 = Time() 00040 t2.sec = t.secs 00041 t2.nsec = t.nsecs 00042 return t2 00043 00044 Time.to_ros = time_to_ros 00045 00046 def header_to_ros(h): 00047 return rospy.Header(stamp=h.stamp.to_ros(), frame_id=h.frame_id) 00048 00049 def header_from_ros(h): 00050 h2 = Header() 00051 h2.stamp = time_from_ros(h.stamp) 00052 h2.frame_id = h.frame_id 00053 return h2 00054 00055 00056 Header.to_ros = header_to_ros 00057 00058 def point_to_ros(p): 00059 return gm.Point(x=p.x, y=p.y, z=p.z) 00060 00061 def point_from_ros(m): 00062 p = Point() 00063 p.x = float(m.x) 00064 p.y = float(m.y) 00065 p.z = float(m.z) 00066 return p 00067 00068 Point.to_ros = point_to_ros 00069 00070 def quaternion_to_ros(q): 00071 return gm.Quaternion(x=q.x, y=q.y, z=q.z, w=q.w) 00072 00073 def quaternion_from_ros(m): 00074 q = Quaternion() 00075 q.x = m.x 00076 q.y = m.y 00077 q.z = m.z 00078 q.w = m.w 00079 return q 00080 00081 Quaternion.to_ros = quaternion_to_ros 00082 00083 def pose_to_ros(p): 00084 return gm.Pose(position=p.position.to_ros(), 00085 orientation=p.orientation.to_ros()) 00086 00087 def pose_from_ros(m): 00088 p = Pose() 00089 p.position = point_from_ros(m.position) 00090 p.orientation = quaternion_from_ros(m.orientation) 00091 return p 00092 00093 Pose.to_ros = pose_to_ros 00094 00095 def point32_to_ros(p): 00096 return gm.Point32(x=p.x, y=p.y, z=p.z) 00097 00098 def point32_from_ros(m): 00099 p = Point32() 00100 p.x = float(m.x) 00101 p.y = float(m.y) 00102 p.z = float(m.z) 00103 return p 00104 00105 Point32.to_ros = point32_to_ros 00106 00107 def polygon_to_ros(p): 00108 return gm.Polygon(points=p.points) 00109 00110 def polygon_from_ros(m): 00111 poly = Polygon() 00112 poly.points[:] = [point32_from_ros(p) for p in m.points] 00113 return poly 00114 00115 def metadata_to_ros(m): 00116 return nm.MapMetaData(resolution=m.resolution, width=m.width, 00117 height=m.height, origin=m.origin.to_ros()) 00118 00119 def metadata_from_ros(m): 00120 m2 = MapMetaData() 00121 m2.resolution = m.resolution 00122 m2.height = m.height 00123 m2.width = m.width 00124 m2.origin = pose_from_ros(m.origin) 00125 return m2 00126 00127 00128 MapMetaData.to_ros = metadata_to_ros 00129 00130 00131 def grid_to_ros(g): 00132 return nm.OccupancyGrid(data=g.data, header=g.header.to_ros(), 00133 info=g.info.to_ros()) 00134 00135 def grid_from_ros(g): 00136 g2 = OccupancyGrid() 00137 g2.header = header_from_ros(g.header) 00138 g2.data = Int8Vec() 00139 g2.data[:] = g.data 00140 g2.info = metadata_from_ros(g.info) 00141 return g2 00142 00143 OccupancyGrid.to_ros = grid_to_ros 00144 00145 def scan_to_ros(s): 00146 return sm.LaserScan(header=s.header.to_ros(), angle_min=s.angle_min, 00147 angle_max=s.angle_max, 00148 angle_increment=s.angle_increment, 00149 # time_increment=s.time_increment, scan_time=s.scan_time, 00150 range_min=s.range_min, range_max=s.range_max, 00151 ranges=s.ranges, 00152 #intensities=s.intensities 00153 ) 00154 00155 # sm.LaserScan.to_ros = scan_to_ros 00156