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

Move map generator #1

Merged
merged 8 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
__pycache__/
.vscode/*
log/*

*.pyc
42 changes: 41 additions & 1 deletion README.md
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]
```
Binary file added gui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions soccer_field_map_generator/package.xml
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.
4 changes: 4 additions & 0 deletions soccer_field_map_generator/setup.cfg
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
27 changes: 27 additions & 0 deletions soccer_field_map_generator/setup.py
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 soccer_field_map_generator/soccer_field_map_generator/cli.py
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()
Loading