#!/usr/bin/env python # Copyright (C) 2018 Copter Express Technologies # # Author: Oleg Kalachev # # Distributed under MIT License (available at https://opensource.org/licenses/MIT). # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. """Markers map generator Generate map file for aruco_map nodelet. Usage: genmap.py [] [] [] [--top-left | --bottom-left] [-o ] genmap.py (-h | --help) Options: Marker side length Marker count along X axis Marker count along Y axis Distance between markers along X axis Distance between markers along Y axis First marker ID [default: 0] X coordinate for the first marker [default: 0] Y coordinate for the first marker [default: 0] --top-left First marker is on top-left (default) --bottom-left First marker is on bottom-left -o Output map file name in the 'map' subdirectory of aruco_pose package Example: rosrun aruco_pose genmap.py 0.33 2 4 1 1 0 > $(catkin_find aruco_pose map)/test_map.txt """ from __future__ import print_function import sys from os import path from docopt import docopt arguments = docopt(__doc__) length = float(arguments['']) first = int(arguments[''] if arguments[''] is not None else 0) x0 = float(arguments[''] if arguments[''] is not None else 0) y0 = float(arguments[''] if arguments[''] is not None else 0) markers_x = int(arguments['']) markers_y = int(arguments['']) dist_x = float(arguments['']) dist_y = float(arguments['']) bottom_left = arguments['--bottom-left'] if arguments['-o'] is None: output = sys.stdout else: output = open(path.join(path.dirname(__file__), '..', 'map', arguments['-o']), 'w') max_y = y0 + (markers_y - 1) * dist_y output.write('# id\tlength\tx\ty\tz\trot_z\trot_y\trot_x\n') for y in range(markers_y): for x in range(markers_x): pos_x = x0 + x * dist_x pos_y = y0 + y * dist_y if not bottom_left: pos_y = max_y - pos_y output.write('{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\n'.format(first, length, pos_x, pos_y, 0, 0, 0, 0)) first += 1