__init__.py
Go to the documentation of this file.
1 from docopt import docopt
2 from os import path
3 from sys import stdout
4 
5 from .map_parser import parse
6 from .marker import Marker, generate_markers
7 
8 from .world import load_world, add_model, save_world
9 
10 
11 USAGE = '''
12 
13 aruco_gen - Script for ArUco map/model generation.
14  Generates ArUco models from their description and optionally
15  adds them to an existing Gazebo world.
16 
17 Usage:
18  aruco_gen [--offset-x=<m>] [--offset-y=<m>] [--offset-z=<m>]
19  [--offset-roll=<rad>] [--offset-pitch=<rad>] [--offset-yaw=<rad>]
20  [--dictionary=<id>] [--single-model]
21  [--source-world=<path>] [--inplace]
22  [--model-path=<path>]
23  <aruco_map_file>
24  aruco_gen -h | --help
25 
26 Options:
27  -h, --help Show this screen.
28  --offset-x=<m> X offset in meters [default: 0].
29  --offset-y=<m> Y offset in meters [default: 0].
30  --offset-z=<m> Z offset in meters [default: 0].
31  --offset-roll=<rad> roll offset in radians [default: 0].
32  --offset-pitch=<rad> pitch offset in radians [default: 0].
33  --offset-yaw=<rad> yaw offset in radians [default: 0].
34  --dictionary=<id> ArUco dictionary ID [default: 2].
35  --single-model Generate a single model instead of individual
36  markers.
37  --source-world=<path> Path to existing Gazebo world.
38  --inplace Modify source world.
39  --model-path=<path> Folder where generated models will be saved
40  [default: ~/.gazebo/models]
41  aruco_map_file Full path to the ArUco map file
42 
43 '''
44 
45 
46 def aruco_gen():
47  opts = docopt(USAGE)
48 
49  dictionary_id = int(opts['--dictionary'])
50  mapfile = opts['<aruco_map_file>']
51  single_model = opts['--single-model']
52  source_world = opts['--source-world']
53  inplace = opts['--inplace']
54 
55  off_x = float(opts['--offset-x'])
56  off_y = float(opts['--offset-y'])
57  off_z = float(opts['--offset-z'])
58  off_roll = float(opts['--offset-roll'])
59  off_pitch = float(opts['--offset-pitch'])
60  off_yaw = float(opts['--offset-yaw'])
61 
62  model_base_path = path.expanduser(opts['--model-path'])
63 
64  markers = parse(mapfile)
65 
66  if single_model:
67  mapname = path.split(mapfile)[-1]
68  model_path = path.join(model_base_path, 'aruco_{}'.format(mapname.replace('.', '_')))
69  generate_markers(markers, model_path, dictionary_id=dictionary_id, map_source=mapname)
70  else:
71  for marker in markers:
72  model_name = 'aruco_{}_{}'.format(dictionary_id, marker.id_)
73  model_path = path.join(model_base_path, model_name)
74  generate_markers([Marker(marker.id_, marker.size, 0, 0, 0, 0, 0, 0)],
75  model_path, dictionary_id=dictionary_id)
76 
77  if source_world is not None:
78  world_tree = load_world(source_world)
79  if single_model:
80  world_tree = add_model(world_tree, 'aruco_{}'.format(mapname.replace('.', '_')),
81  off_x, off_y, off_z,
82  off_roll, off_pitch, off_yaw)
83  else:
84  if (abs(off_roll) > 0.001) or (abs(off_pitch) > 0.001) or (abs(off_yaw) > 0.001):
85  raise NotImplementedError('Sorry, angular offsets are not currently implemented for multimodel generation')
86  for marker in markers:
87  world_tree = add_model(world_tree, 'aruco_{}_{}'.format(dictionary_id, marker.id_),
88  off_x + marker.x, off_y + marker.y, off_z + marker.z,
89  marker.roll, marker.pitch, marker.yaw)
90 
91  output = open(source_world, 'w') if inplace else stdout
92 
93  save_world(world_tree, output)
def generate_markers(markers, model_directory, dictionary_id=2, map_source='')
Definition: marker.py:97
def load_world(world_file)
Definition: world.py:14
def add_model(world, model_name, x, y, z, roll, pitch, yaw, index=0)
Definition: world.py:21
def save_world(world, file)
Definition: world.py:40


clover_simulation
Author(s): Alexey Rogachevskiy, Andrey Ryabov, Arthur Golubtsov, Oleg Kalachev, Svyatoslav Zhuravlev
autogenerated on Mon Feb 28 2022 22:08:36