Skip to content

Commit 634d2e3

Browse files
simple command costmap api - first few functions (ros-navigation#3159)
* initial commit costmap_2d template Signed-off-by: Stevedan Omodolor <stevedan.o.omodolor@gmail.com> * finish task A and tested * lint * Update nav2_simple_commander/nav2_simple_commander/costmap_2d.py Co-authored-by: Steve Macenski <stevenmacenski@gmail.com> * fix trailing underscores Signed-off-by: Stevedan Omodolor <stevedan.o.omodolor@gmail.com> Co-authored-by: Steve Macenski <stevenmacenski@gmail.com>
1 parent 6d58247 commit 634d2e3

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#! /usr/bin/env python3
2+
# Copyright 2021 Samsung Research America
3+
# Copyright 2022 Stevedan Ogochukwu Omodolor
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import numpy as np
18+
19+
20+
class PyCostmap2D:
21+
"""
22+
PyCostmap2D.
23+
24+
Costmap Python3 API for OccupancyGrids to populate from published messages
25+
"""
26+
27+
def __init__(self, occupancy_map):
28+
self.size_x = occupancy_map.info.width
29+
self.size_y = occupancy_map.info.height
30+
self.resolution = occupancy_map.info.resolution
31+
self.origin_x = occupancy_map.info.origin.position.x
32+
self.origin_y = occupancy_map.info.origin.position.y
33+
self.global_frame_id = occupancy_map.header.frame_id
34+
self.costmap_timestamp = occupancy_map.header.stamp
35+
# Extract costmap
36+
self.costmap = np.array(occupancy_map.data, dtype=np.int8).reshape(
37+
self.size_y, self.size_x)
38+
39+
def getSizeInCellsX(self):
40+
"""Get map width in cells."""
41+
return self.size_x
42+
43+
def getSizeInCellsY(self):
44+
"""Get map height in cells."""
45+
return self.size_y
46+
47+
def getSizeInMetersX(self):
48+
"""Get x axis map size in meters."""
49+
return (self.size_x - 1 + 0.5) * self.resolution_
50+
51+
def getSizeInMetersY(self):
52+
"""Get y axis map size in meters."""
53+
return (self.size_y - 1 + 0.5) * self.resolution_
54+
55+
def getOriginX(self):
56+
"""Get the origin x axis of the map [m]."""
57+
return self.origin_x
58+
59+
def getOriginY(self):
60+
"""Get the origin y axis of the map [m]."""
61+
return self.origin_y
62+
63+
def getResolution(self):
64+
"""Get map resolution [m/cell]."""
65+
return self.resolution
66+
67+
def getGlobalFrameID(self):
68+
"""Get global frame_id."""
69+
return self.global_frame_id
70+
71+
def getCostmapTimestamp(self):
72+
"""Get costmap timestamp."""
73+
return self.costmap_timestamp

0 commit comments

Comments
 (0)