This repository has been archived by the owner on May 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.py
executable file
·195 lines (172 loc) · 6.95 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/usr/bin/env python
"""RRdT* Research
Usage:
main.py (rrdt|rrt|birrt|informedrrt|prm|particle|likelihood|nearby|mouse) <MAP>
[options] [-v|-vv|-vvv]
main.py (rrdt|rrt|birrt|informedrrt|prm|particle|likelihood|nearby|mouse) <MAP>
start <sx> <sy> goal <gx> <gy> [options] [-v|-vv|-vvv]
main.py (-h | --help)
main.py --version
Arguments:
(rrdt|...|...) Set the sampler to be used by the RRT*.
<MAP> An image file that represent the map.
General Options:
-h --help Show this screen.
--version Show version.
-v --verbose Display debug message.
Display Options:
--always-refresh Set if the display should refresh on every ticks.
-s --scaling=SCALING Set scaling for display (ratio will be maintained).
[default: 1.5]
--hide-sampled-points Do not display sampled point as red dot on screen.
--disable-pygame Disable pygame display (to enhance performance).
General Sampler Options:
--epsilon=EPSILON Set epsilon value.
[default: 10.0]
--radius=RADIUS Set radius that will connect two nodes together.
[default: 15]
--max-number-nodes=MAX_NODES
Set maximum number of nodes
[default: 30000]
--ignore-step-size Ignore step size (i.e. epsilon) when sampling.
--goal-bias=BIAS Probability of biasing goal position.
[default: 0.02]
Random Sampler Options:
--random-method=METHOD
Set a random method used to generate the random
numbers. This enables the use of different
quasi-random generators.
Supported methods are:
- pseudo_random (random from numpy)
- saltelli (Saltelli's extension of Sobol sequence)
- sobol_sequence (Sobol sequence generator)
- latin_hypercube (Latin hypercube sampling)
- finite_differences (Derivative-based global
sensitivity measure)
- fast (Fourier Amplitude Sensitivity Test)
[default: pseudo_random]
Disjoint Sampler Options:
--no-restart-when-merge
This flag denotes if the local sampler from disjoint-
tree sampler should restart at a new location when
the disjointed tree branches jointed to an existing
one. The default behaviour is restart as soon as merged
to another existing tree (to encourage exploration).
When this flag is set, it will remain until its energy
is exhausted.
Likelihood/Nearby Sampler Options:
--prob-block-size=SIZE
Set the dimension of the discretized block.
[default: 5]
"""
import os
import sys
import logging
from docopt import docopt
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = '1' # hide pygame prompt
import env
from helpers import MagicDict
LOGGER = logging.getLogger()
def main():
args = docopt(__doc__, version='RRT* Research v1.0')
if args['--verbose'] > 2:
LOGGER.setLevel(logging.DEBUG)
elif args['--verbose'] > 1:
LOGGER.setLevel(logging.INFO)
elif args['--verbose'] > 0:
LOGGER.setLevel(logging.WARNING)
else:
LOGGER.setLevel(logging.ERROR)
# INFO includes only loading
# DEBUG includes all outputs
ch = logging.StreamHandler(sys.stdout)
ch.setFormatter(logging.Formatter('%(message)s'))
# ch.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
LOGGER.addHandler(ch)
LOGGER.debug("commandline args: {}".format(args))
from planners.rrtPlanner import RRTPlanner
planner_type = RRTPlanner # default planner type
if args['rrt']:
from planners.randomPolicySampler import RandomPolicySampler
sampler = RandomPolicySampler(random_method=args['--random-method'])
elif args['birrt']:
from planners.birrtPlanner import BiRRTSampler, BiRRTPlanner
sampler = BiRRTSampler()
planner_type = BiRRTPlanner
elif args['rrdt']:
from planners.rrdtPlanner import RRdTSampler, RRdTPlanner
sampler = RRdTSampler(
restart_when_merge=not args['--no-restart-when-merge'])
planner_type = RRdTPlanner
elif args['informedrrt']:
from planners.informedrrtSampler import InformedRRTSampler
sampler = InformedRRTSampler()
elif args['prm']:
from planners.prmPlanner import PRMSampler, PRMPlanner
sampler = PRMSampler()
planner_type = PRMPlanner
elif args['particle']:
from planners.particleFilterSampler import ParticleFilterSampler
sampler = ParticleFilterSampler()
elif args['likelihood']:
from planners.likelihoodPolicySampler import LikelihoodPolicySampler
sampler = LikelihoodPolicySampler(
prob_block_size=int(args['--prob-block-size']))
elif args['nearby']:
from planners.nearbyPolicySampler import NearbyPolicySampler
sampler = NearbyPolicySampler(
prob_block_size=int(args['--prob-block-size']))
elif args['mouse']:
from planners.mouseSampler import MouseSampler
sampler = MouseSampler()
rrt_options = MagicDict({
'showSampledPoint':
not args['--hide-sampled-points'],
'scaling':
float(args['--scaling']),
'goalBias':
float(args['--goal-bias']),
'image':
args['<MAP>'],
'epsilon':
float(args['--epsilon']),
'max_number_nodes':
int(args['--max-number-nodes']),
'radius':
float(args['--radius']),
'goal_radius':
2 / 3 * float(args['--radius']),
'ignore_step_size':
args['--ignore-step-size'],
'always_refresh':
args['--always-refresh'],
'enable_pygame':
not args['--disable-pygame'],
'sampler':
sampler,
})
rrtplanner = planner_type(**rrt_options)
rrt_options.update({
'planner': rrtplanner,
})
if args['start'] and args['goal']:
rrt_options.update({
'startPt': (float(args['<sx>']), float(args['<sy>'])),
'goalPt': (float(args['<gx>']), float(args['<gy>']))
})
rrt = env.Env(**rrt_options)
return rrt
if __name__ == '__main__':
# run if run from commandline
rrt = main()
try:
rrt.run()
except Exception as e:
LOGGER.error("==============================")
LOGGER.exception("Exception occured: {}".format(e))
LOGGER.error("==============================")
LOGGER.error("Waiting to be exit...")
try:
rrt.wait_for_exit()
except KeyboardInterrupt:
pass