Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simple command costmap api - first few functions #3159

Merged
merged 5 commits into from
Aug 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions nav2_simple_commander/nav2_simple_commander/costmap_2d.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#! /usr/bin/env python3
SteveMacenski marked this conversation as resolved.
Show resolved Hide resolved
# Copyright 2021 Samsung Research America
# Copyright 2022 Stevedan Ogochukwu Omodolor
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import numpy as np


class PyCostmap2D:
"""
PyCostmap2D.

Costmap Python3 API for OccupancyGrids to populate from published messages
"""

def __init__(self, occupancy_map):
self.size_x = occupancy_map.info.width
self.size_y = occupancy_map.info.height
self.resolution = occupancy_map.info.resolution
self.origin_x = occupancy_map.info.origin.position.x
self.origin_y = occupancy_map.info.origin.position.y
self.global_frame_id = occupancy_map.header.frame_id
self.costmap_timestamp = occupancy_map.header.stamp
# Extract costmap
self.costmap = np.array(occupancy_map.data, dtype=np.int8).reshape(
self.size_y, self.size_x)

def getSizeInCellsX(self):
"""Get map width in cells."""
return self.size_x

def getSizeInCellsY(self):
"""Get map height in cells."""
return self.size_y

def getSizeInMetersX(self):
"""Get x axis map size in meters."""
return (self.size_x - 1 + 0.5) * self.resolution_

def getSizeInMetersY(self):
"""Get y axis map size in meters."""
return (self.size_y - 1 + 0.5) * self.resolution_

def getOriginX(self):
"""Get the origin x axis of the map [m]."""
return self.origin_x

def getOriginY(self):
"""Get the origin y axis of the map [m]."""
return self.origin_y

def getResolution(self):
"""Get map resolution [m/cell]."""
return self.resolution

def getGlobalFrameID(self):
"""Get global frame_id."""
return self.global_frame_id

def getCostmapTimestamp(self):
"""Get costmap timestamp."""
return self.costmap_timestamp