generated from ijnek/ros2_template_repo
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ros-sports/add_map_generator
Move map generator
- Loading branch information
Showing
15 changed files
with
1,537 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
__pycache__/ | ||
.vscode/* | ||
log/* | ||
|
||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,45 @@ | ||
# Template Repo | ||
# Soccer Field Map Generator | ||
|
||
[![Build and Test (humble)](../../actions/workflows/build_and_test_humble.yaml/badge.svg?branch=rolling)](../../actions/workflows/build_and_test_humble.yaml?query=branch:rolling) | ||
[![Build and Test (iron)](../../actions/workflows/build_and_test_iron.yaml/badge.svg?branch=rolling)](../../actions/workflows/build_and_test_iron.yaml?query=branch:rolling) | ||
[![Build and Test (rolling)](../../actions/workflows/build_and_test_rolling.yaml/badge.svg?branch=rolling)](../../actions/workflows/build_and_test_rolling.yaml?query=branch:rolling) | ||
|
||
This repository contains a tool for generating soccer field maps. It includes a GUI for interactively creating and editing maps, as well as a command-line interface for scripted map generation. | ||
|
||
## Installation | ||
|
||
To install the tool, run the following commands in your colcon workspace: | ||
|
||
```bash | ||
git clone [email protected]:ros-sports/soccer_field_map_generator.git src/soccer_field_map_generator | ||
rosdep install --from-paths src --ignore-src -r -y | ||
colcon build | ||
``` | ||
|
||
Don't forget to source your workspace after building: | ||
|
||
```bash | ||
source install/setup.bash | ||
``` | ||
|
||
## Usage | ||
|
||
### GUI | ||
|
||
To launch the GUI, run the following command: | ||
|
||
```bash | ||
ros2 run soccer_field_map_generator gui | ||
``` | ||
|
||
You should see a window like this: | ||
|
||
![GUI](gui.png) | ||
|
||
### CLI | ||
|
||
To generate a map using the command-line interface, run the following command: | ||
|
||
```bash | ||
ros2 run soccer_field_map_generator cli [output_file] [config_file] [options] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0"?> | ||
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> | ||
<package format="3"> | ||
<name>soccer_field_map_generator</name> | ||
<version>0.0.0</version> | ||
<description>A package to generate a soccer field map using a gui or cli</description> | ||
<maintainer email="[email protected]">Florian Vahl</maintainer> | ||
<license>Apache License 2.0</license> | ||
|
||
<depend>python3-opencv</depend> | ||
<depend>python3-numpy</depend> | ||
<depend>python3-tk</depend> | ||
<depend>python3-yaml</depend> | ||
<depend>python3-pil</depend> | ||
<depend>python3-scipy</depend> | ||
|
||
<test_depend>ament_copyright</test_depend> | ||
<test_depend>ament_flake8</test_depend> | ||
<test_depend>ament_pep257</test_depend> | ||
<test_depend>python3-pytest</test_depend> | ||
|
||
<export> | ||
<build_type>ament_python</build_type> | ||
</export> | ||
</package> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[develop] | ||
script_dir=$base/lib/soccer_field_map_generator | ||
[install] | ||
install_scripts=$base/lib/soccer_field_map_generator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from setuptools import find_packages, setup | ||
|
||
package_name = 'soccer_field_map_generator' | ||
|
||
setup( | ||
name=package_name, | ||
version='0.0.0', | ||
packages=find_packages(exclude=['test']), | ||
data_files=[ | ||
('share/ament_index/resource_index/packages', | ||
['resource/' + package_name]), | ||
('share/' + package_name, ['package.xml']), | ||
], | ||
install_requires=['setuptools'], | ||
zip_safe=True, | ||
maintainer='florian', | ||
maintainer_email='[email protected]', | ||
description='A package to generate a soccer field map using a gui or cli', | ||
license='Apache License 2.0', | ||
tests_require=['pytest'], | ||
entry_points={ | ||
'console_scripts': [ | ||
'gui = soccer_field_map_generator.gui:main', | ||
'cli = soccer_field_map_generator.cli:main', | ||
], | ||
}, | ||
) |
Empty file.
82 changes: 82 additions & 0 deletions
82
soccer_field_map_generator/soccer_field_map_generator/cli.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Copyright (c) 2023 Hamburg Bit-Bots | ||
# | ||
# 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 argparse | ||
import os | ||
import sys | ||
|
||
import cv2 | ||
from soccer_field_map_generator.generator import ( | ||
generate_map_image, | ||
generate_metadata, | ||
load_config_file, | ||
) | ||
import yaml | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description='Generate maps for localization') | ||
parser.add_argument('output', help='Output file name') | ||
parser.add_argument( | ||
'config', | ||
help='Config file for the generator that specifies the parameters for the map generation', | ||
) | ||
parser.add_argument( | ||
'--metadata', | ||
help="Also generates a 'map_server.yaml' file with the metadata for the map", | ||
action='store_true', | ||
) | ||
args = parser.parse_args() | ||
|
||
# Check if the config file exists | ||
if not os.path.isfile(args.config): | ||
print('Config file does not exist') | ||
sys.exit(1) | ||
|
||
# Load config file | ||
with open(args.config, 'r') as config_file: | ||
parameters = load_config_file(config_file) | ||
|
||
# Check if the config file is valid | ||
if parameters is None: | ||
print('Invalid config file') | ||
sys.exit(1) | ||
|
||
# Generate the map image | ||
image = generate_map_image(parameters) | ||
|
||
# Make output folder full path | ||
output_path = os.path.abspath(args.output) | ||
|
||
# Check if the output folder exists | ||
if not os.path.isdir(os.path.dirname(output_path)): | ||
print('Output folder does not exist') | ||
sys.exit(1) | ||
|
||
# Save the image | ||
cv2.imwrite(output_path, image) | ||
|
||
# Generate the metadata | ||
if args.metadata: | ||
metadata = generate_metadata(parameters, os.path.basename(output_path)) | ||
metadata_file_name = os.path.join( | ||
os.path.dirname(output_path), 'map_server.yaml' | ||
) | ||
with open(metadata_file_name, 'w') as metadata_file: | ||
yaml.dump(metadata, metadata_file, sort_keys=False) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Oops, something went wrong.