autoverse-cli 0.28.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- autoverse_cli-0.28.1.dist-info/METADATA +91 -0
- autoverse_cli-0.28.1.dist-info/RECORD +51 -0
- autoverse_cli-0.28.1.dist-info/WHEEL +5 -0
- autoverse_cli-0.28.1.dist-info/entry_points.txt +2 -0
- autoverse_cli-0.28.1.dist-info/licenses/LICENSE +33 -0
- autoverse_cli-0.28.1.dist-info/top_level.txt +1 -0
- avrs/__init__.py +0 -0
- avrs/app_version.py +24 -0
- avrs/argparse_help.py +30 -0
- avrs/avrs.py +183 -0
- avrs/can_tool.py +192 -0
- avrs/can_tool_util.py +190 -0
- avrs/cfg.py +78 -0
- avrs/launcher.py +256 -0
- avrs/launcher_util.py +203 -0
- avrs/race_cloud.py +506 -0
- avrs/race_cloud_bridge_can.py +100 -0
- avrs/race_cloud_cfg_util.py +310 -0
- avrs/race_cloud_fwd_api.py +49 -0
- avrs/race_cloud_util.py +384 -0
- avrs/requests/change_camera.py +24 -0
- avrs/requests/code_booz.py +69 -0
- avrs/requests/demo.py +19 -0
- avrs/requests/dump_sim_config.py +14 -0
- avrs/requests/environment.py +46 -0
- avrs/requests/fault_injection.py +186 -0
- avrs/requests/get_object_config.py +18 -0
- avrs/requests/get_web_viz_meta.py +11 -0
- avrs/requests/leaderboard.py +74 -0
- avrs/requests/list_sim_objects.py +26 -0
- avrs/requests/log_path.py +28 -0
- avrs/requests/misc.py +70 -0
- avrs/requests/move_to_landmark.py +16 -0
- avrs/requests/npc.py +289 -0
- avrs/requests/race_control.py +48 -0
- avrs/requests/request.py +61 -0
- avrs/requests/reset_to_track.py +21 -0
- avrs/requests/rest_request.py +45 -0
- avrs/requests/restart.py +12 -0
- avrs/requests/scenario_control.py +43 -0
- avrs/requests/spawn_object.py +44 -0
- avrs/requests/teleport.py +40 -0
- avrs/requests/toggle_hud.py +11 -0
- avrs/requests/vd.py +64 -0
- avrs/requests/vehicle_input.py +21 -0
- avrs/requests/vehicle_replay.py +454 -0
- avrs/shell_completion.py +121 -0
- avrs/simconfig.py +75 -0
- avrs/simconfig_util.py +170 -0
- avrs/tests.py +9 -0
- avrs/util.py +13 -0
avrs/requests/npc.py
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
from avrs.requests.request import AvrsApiRequest
|
|
2
|
+
from argparse import RawDescriptionHelpFormatter
|
|
3
|
+
from argparse import RawTextHelpFormatter
|
|
4
|
+
|
|
5
|
+
class Npc():
|
|
6
|
+
def __init__(self, parser, cfg):
|
|
7
|
+
psr = parser.add_parser('npc', help='Peforms a variety of NPC control commands')
|
|
8
|
+
sps = psr.add_subparsers(required= True, help='sub-command of NPC')
|
|
9
|
+
NpcSpawn(sps, cfg)
|
|
10
|
+
NpcDespawn(sps, cfg)
|
|
11
|
+
NpcChangeDifficulty(sps, cfg)
|
|
12
|
+
NpcStart(sps, cfg)
|
|
13
|
+
NpcStop(sps, cfg)
|
|
14
|
+
NpcSetSpeed(sps, cfg)
|
|
15
|
+
NpcChangeProfile(sps, cfg)
|
|
16
|
+
NpcTeleport(sps, cfg)
|
|
17
|
+
|
|
18
|
+
NPC_SPAWN_POSITION_HELP = '''
|
|
19
|
+
spawn the NPC in a relative position or absoulte position
|
|
20
|
+
'''
|
|
21
|
+
|
|
22
|
+
NPC_SPAWN_PROFILE_HELP = '''
|
|
23
|
+
Sets the profile of which the npc follows. Note: the profiles provided are ones Provided by Autonoma.
|
|
24
|
+
If you wish to use your own you have two options. If your custom profile
|
|
25
|
+
is located in the saved folder of the simulator you can just enter the filename.
|
|
26
|
+
However if this is not the case you must enter the absolute path of the file
|
|
27
|
+
Provided Profiles:
|
|
28
|
+
middleRouteYas
|
|
29
|
+
leftRouteYas
|
|
30
|
+
rightRouteYas
|
|
31
|
+
backMiddleRouteYas
|
|
32
|
+
backLeftRouteYas
|
|
33
|
+
'''
|
|
34
|
+
|
|
35
|
+
NPC_ROUTE_CHOICES = [
|
|
36
|
+
'middleRouteYas',
|
|
37
|
+
'leftRouteYas',
|
|
38
|
+
'rightRouteYas',
|
|
39
|
+
'backMiddleRouteYas',
|
|
40
|
+
'backLeftRouteYas',
|
|
41
|
+
'atlNpc1',
|
|
42
|
+
'atlNpc2',
|
|
43
|
+
'atlNpc3',
|
|
44
|
+
'atlNpc4',
|
|
45
|
+
'atlNpc5'
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
class NpcSpawn(AvrsApiRequest):
|
|
49
|
+
def __init__(self, parser, cfg):
|
|
50
|
+
AvrsApiRequest.__init__(self, parser, cfg, 'SpawnObject', '')
|
|
51
|
+
psr = parser.add_parser(
|
|
52
|
+
'spawn', help='spawn an NPC', formatter_class=RawTextHelpFormatter)
|
|
53
|
+
|
|
54
|
+
psr.add_argument(
|
|
55
|
+
'--name',
|
|
56
|
+
default='npc0',
|
|
57
|
+
help='name of the npc to spawn')
|
|
58
|
+
|
|
59
|
+
psr.add_argument(
|
|
60
|
+
'--vehicle-type',
|
|
61
|
+
default='HondaOdyssey',
|
|
62
|
+
help='what type of vehicle to spawn as an NPC')
|
|
63
|
+
|
|
64
|
+
psr.add_argument(
|
|
65
|
+
'--position',
|
|
66
|
+
choices=('relative', 'absolute'),
|
|
67
|
+
default='absolute',
|
|
68
|
+
help=NPC_SPAWN_POSITION_HELP)
|
|
69
|
+
|
|
70
|
+
psr.add_argument(
|
|
71
|
+
'--profile',
|
|
72
|
+
default='leftRouteYas',
|
|
73
|
+
help=NPC_SPAWN_PROFILE_HELP)
|
|
74
|
+
|
|
75
|
+
psr.add_argument(
|
|
76
|
+
'--velocity-type',
|
|
77
|
+
default='constant',
|
|
78
|
+
help='the path the NPC follows is a constant velocity or speed')
|
|
79
|
+
|
|
80
|
+
psr.add_argument(
|
|
81
|
+
'--speed',
|
|
82
|
+
type=float,
|
|
83
|
+
default=20,
|
|
84
|
+
help='the speed of the npc is m/s')
|
|
85
|
+
|
|
86
|
+
psr.add_argument(
|
|
87
|
+
'--difficulty',
|
|
88
|
+
type=float,
|
|
89
|
+
default=1.0,
|
|
90
|
+
help='the playback speed of the velocity profile, 1.0 is normal')
|
|
91
|
+
|
|
92
|
+
psr.add_argument(
|
|
93
|
+
'--enable-sensors',
|
|
94
|
+
type=bool,
|
|
95
|
+
default=False,
|
|
96
|
+
help='whether to enable sensors on the NPC')
|
|
97
|
+
|
|
98
|
+
psr.add_argument(
|
|
99
|
+
'--with-view-cameras',
|
|
100
|
+
type=bool,
|
|
101
|
+
default=False,
|
|
102
|
+
help='whether to attach viewing cameras to the NPC')
|
|
103
|
+
|
|
104
|
+
psr.set_defaults(func=self.send_request)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def get_request_body(self, args):
|
|
108
|
+
if args.profile not in NPC_ROUTE_CHOICES:
|
|
109
|
+
print(f"Warning: '{args.profile}' is not a default option, procceeding with custom file")
|
|
110
|
+
|
|
111
|
+
npc_init_pld = {
|
|
112
|
+
'Name': args.name,
|
|
113
|
+
'Position': args.position,
|
|
114
|
+
'Profile': args.profile,
|
|
115
|
+
'Velocity' : args.velocity_type,
|
|
116
|
+
'Speed' : args.speed,
|
|
117
|
+
'Difficulty' : args.difficulty,
|
|
118
|
+
'bEnableSensors': args.enable_sensors
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
eav_init_pld = {
|
|
122
|
+
'VehicleCanName': 'can0'
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
plds = [
|
|
126
|
+
{
|
|
127
|
+
'TypeName': 'NpcInitializer',
|
|
128
|
+
'Body': npc_init_pld
|
|
129
|
+
}
|
|
130
|
+
]
|
|
131
|
+
|
|
132
|
+
if args.with_view_cameras:
|
|
133
|
+
plds.append(
|
|
134
|
+
{
|
|
135
|
+
'TypeName': 'InitializerTemplates',
|
|
136
|
+
'Body': {
|
|
137
|
+
'Templates': [
|
|
138
|
+
{
|
|
139
|
+
'PayloadType': 'SimViewTargetIpd',
|
|
140
|
+
'PayloadSpec': 'DefaultCarCams'
|
|
141
|
+
}
|
|
142
|
+
]
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
return {
|
|
147
|
+
'Name': args.name,
|
|
148
|
+
'Type': args.vehicle_type,
|
|
149
|
+
'Location': {},
|
|
150
|
+
'Rotation': {},
|
|
151
|
+
'Payloads': plds
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
class NpcDespawn(AvrsApiRequest):
|
|
155
|
+
def __init__(self, parser, cfg):
|
|
156
|
+
AvrsApiRequest.__init__(self, parser, cfg, 'NpcDespawn', 'Npc')
|
|
157
|
+
psr = parser.add_parser('despawn', help='despawn an NPC')
|
|
158
|
+
psr.add_argument('name', help = 'name of the npc to despawn')
|
|
159
|
+
psr.set_defaults(func=self.send_request)
|
|
160
|
+
|
|
161
|
+
def get_request_body(self, args):
|
|
162
|
+
return {
|
|
163
|
+
'Name': args.name
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
class NpcTeleport(AvrsApiRequest):
|
|
168
|
+
def __init__(self, parser, cfg):
|
|
169
|
+
AvrsApiRequest.__init__(self, parser, cfg, 'NpcTeleport', 'Npc')
|
|
170
|
+
psr = parser.add_parser('teleport', help = 'telport an active NPC to new x,y,z location,'
|
|
171
|
+
+ 'a location on the path will be selected closeset to this value')
|
|
172
|
+
psr.add_argument('name', help='name of npc to teleport')
|
|
173
|
+
subparsers = psr.add_subparsers(dest = "action", help='sub-command of NPC teleport')
|
|
174
|
+
|
|
175
|
+
# Define the parser for the 'vehicle' option
|
|
176
|
+
vehicle_parser = subparsers.add_parser('vehicle', help='Teleport to the vehicle to an existing car')
|
|
177
|
+
|
|
178
|
+
# Defines the parser for the 'custom' option
|
|
179
|
+
custom_parser = subparsers.add_parser('custom', help='Teleport to custom coordinates')
|
|
180
|
+
custom_parser.add_argument('x', type=float, help='X coordinate.')
|
|
181
|
+
custom_parser.add_argument('y', type=float, help='Y coordinate.')
|
|
182
|
+
custom_parser.add_argument('z', type=float, help='Y coordinate.')
|
|
183
|
+
|
|
184
|
+
psr.set_defaults(func = self.send_request)
|
|
185
|
+
|
|
186
|
+
def get_request_body(self, args):
|
|
187
|
+
if args.action == 'vehicle':
|
|
188
|
+
print("Correct")
|
|
189
|
+
return {
|
|
190
|
+
'Name': args.name,
|
|
191
|
+
'Type': args.action,
|
|
192
|
+
'X': 0,
|
|
193
|
+
'Y': 0,
|
|
194
|
+
'Z': 0
|
|
195
|
+
}
|
|
196
|
+
else:
|
|
197
|
+
return {
|
|
198
|
+
'Name': args.name,
|
|
199
|
+
'Type': args.action,
|
|
200
|
+
'X': args.x,
|
|
201
|
+
'Y': args.y,
|
|
202
|
+
'Z ': args.z
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
class NpcChangeProfile(AvrsApiRequest):
|
|
206
|
+
def __init__(self, parser, cfg):
|
|
207
|
+
AvrsApiRequest.__init__(self, parser, cfg, 'NpcChangeProfile', 'Npc')
|
|
208
|
+
psr = parser.add_parser('change-path', help = 'changes the raceline of an active NPC')
|
|
209
|
+
psr.add_argument('name', help='name of npc to change the path for')
|
|
210
|
+
psr.add_argument('profile', type=str, help = 'change the profile of the NPC, the same profile constraints apply as the spawn command')
|
|
211
|
+
psr.set_defaults(func=self.send_request)
|
|
212
|
+
|
|
213
|
+
def get_request_body(self, args):
|
|
214
|
+
choices = ['middleRouteYas', 'leftRouteYas', 'rightRouteYas', 'backMiddleRouteYas', 'backLeftRouteYas', 'atlNpc1', 'atlNpc2', 'atlNpc3', 'atlNpc4', 'atlNpc5']
|
|
215
|
+
if args.profile not in choices:
|
|
216
|
+
print(f"Warning: '{args.profile}' is not a default option, procceeding with custom file")
|
|
217
|
+
return {
|
|
218
|
+
'Name': args.name,
|
|
219
|
+
'NewProfile': args.profile
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
class NpcChangeDifficulty(AvrsApiRequest):
|
|
223
|
+
def __init__(self, parser, cfg):
|
|
224
|
+
AvrsApiRequest.__init__(self, parser, cfg, 'NpcChangeDifficulty', 'Npc')
|
|
225
|
+
psr = parser.add_parser('change-difficulty', help = 'changes the difficulty or the the playback speed '
|
|
226
|
+
+ 'of an npc with a non-constant velocity')
|
|
227
|
+
psr.add_argument('name', help='name of npc to change the path for')
|
|
228
|
+
psr.add_argument('difficulty', type = float, help='name of npc to change the path for')
|
|
229
|
+
psr.set_defaults(func=self.send_request)
|
|
230
|
+
|
|
231
|
+
def get_request_body(self, args):
|
|
232
|
+
return {
|
|
233
|
+
'Name': args.name,
|
|
234
|
+
'NewDifficulty': args.difficulty
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
class NpcStart(AvrsApiRequest):
|
|
239
|
+
def __init__(self, parser, cfg):
|
|
240
|
+
AvrsApiRequest.__init__(self, parser, cfg, 'NpcStart', 'Npc')
|
|
241
|
+
psr = parser.add_parser('start', help = 'start an NPC')
|
|
242
|
+
psr.add_argument('name', help='name of npc to start')
|
|
243
|
+
psr.set_defaults(func=self.send_request)
|
|
244
|
+
|
|
245
|
+
def get_request_body(self, args):
|
|
246
|
+
return {
|
|
247
|
+
'Name' : args.name
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
class NpcStop(AvrsApiRequest):
|
|
251
|
+
def __init__(self, parser, cfg):
|
|
252
|
+
AvrsApiRequest.__init__(self, parser, cfg, 'NpcStop', 'Npc')
|
|
253
|
+
psr = parser.add_parser('stop', help = 'stop an NPC')
|
|
254
|
+
psr.add_argument('name', help='name of npc to stop')
|
|
255
|
+
psr.set_defaults(func=self.send_request)
|
|
256
|
+
|
|
257
|
+
def get_request_body(self, args):
|
|
258
|
+
return {
|
|
259
|
+
'Name' : args.name
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
class NpcSetSpeed(AvrsApiRequest):
|
|
264
|
+
def __init__(self, parser, cfg):
|
|
265
|
+
AvrsApiRequest.__init__(self, parser, cfg, 'NpcSetSpeed', 'Npc')
|
|
266
|
+
psr = parser.add_parser('set-speed', help = 'sets the speed of an Anctive NPC')
|
|
267
|
+
psr.add_argument('name', help='name of npc to change the speed for')
|
|
268
|
+
psr.add_argument('speed', type = float, help='speed of the NPC')
|
|
269
|
+
psr.set_defaults(func=self.send_request)
|
|
270
|
+
|
|
271
|
+
def get_request_body(self, args):
|
|
272
|
+
return {
|
|
273
|
+
'Name': args.name,
|
|
274
|
+
'Speed': args.speed
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
from avrs.requests.request import AvrsApiRequest
|
|
2
|
+
class AvrsRaceControlRequest(AvrsApiRequest):
|
|
3
|
+
def __init__(self, parser, cfg):
|
|
4
|
+
AvrsApiRequest.__init__(self, parser, cfg, 'RaceControl', 'Ego')
|
|
5
|
+
psr = parser.add_parser('race-control', help='send different flags to the race control')
|
|
6
|
+
self.sector_number = 3 # Assuming there are 3 sectors; adjust as necessary, constant for now
|
|
7
|
+
|
|
8
|
+
psr.add_argument(
|
|
9
|
+
'--session-type',
|
|
10
|
+
type=int,
|
|
11
|
+
default=-1,
|
|
12
|
+
help='the id of the session type to set')
|
|
13
|
+
|
|
14
|
+
psr.add_argument(
|
|
15
|
+
'--track-flag',
|
|
16
|
+
type=int,
|
|
17
|
+
default=-1,
|
|
18
|
+
help='the id of the track flag to set')
|
|
19
|
+
|
|
20
|
+
psr.add_argument(
|
|
21
|
+
'--car-flag',
|
|
22
|
+
type=int,
|
|
23
|
+
default=-1,
|
|
24
|
+
help='the id of the car flag to set')
|
|
25
|
+
|
|
26
|
+
psr.add_argument(
|
|
27
|
+
'--sector-flag',
|
|
28
|
+
nargs=self.sector_number,
|
|
29
|
+
type=int,
|
|
30
|
+
default=[-1, -1, -1],
|
|
31
|
+
help='the ids of the sector flags to set, provide 3 values for sector 1, sector 2 and sector 3 in that order')
|
|
32
|
+
|
|
33
|
+
psr.add_argument(
|
|
34
|
+
'--object-name',
|
|
35
|
+
default='Ego',
|
|
36
|
+
help='the name of the car to set flags on')
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
psr.set_defaults(func=self.send_request)
|
|
40
|
+
|
|
41
|
+
def get_request_body(self, args):
|
|
42
|
+
self.target_object_id = args.object_name
|
|
43
|
+
return {
|
|
44
|
+
'sessionType': args.session_type,
|
|
45
|
+
'trackFlag': args.track_flag,
|
|
46
|
+
'carFlag': args.car_flag,
|
|
47
|
+
'sectorFlag': args.sector_flag
|
|
48
|
+
}
|
avrs/requests/request.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import socket
|
|
2
|
+
import json
|
|
3
|
+
import os
|
|
4
|
+
import os.path
|
|
5
|
+
import multiprocessing
|
|
6
|
+
import time
|
|
7
|
+
import sys
|
|
8
|
+
import http.client
|
|
9
|
+
|
|
10
|
+
class AvrsApiRequest:
|
|
11
|
+
def __init__(self, parser, cfg, request_type, target_id):
|
|
12
|
+
self.target_object_id = target_id
|
|
13
|
+
self.request_type = request_type
|
|
14
|
+
self.verbose = False
|
|
15
|
+
self.cfg = cfg
|
|
16
|
+
|
|
17
|
+
def get_request(self, args):
|
|
18
|
+
body = self.get_request_body(args)
|
|
19
|
+
return {
|
|
20
|
+
'TargetObjectId': self.target_object_id,
|
|
21
|
+
'RequestType': self.request_type,
|
|
22
|
+
'bVerboseResponse': args.verbose or self.verbose,
|
|
23
|
+
'RequestBody': body
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
def get_request_body(self, args):
|
|
27
|
+
return '{}'
|
|
28
|
+
|
|
29
|
+
def send_request(self, args):
|
|
30
|
+
#self.send_tcp_request(args)
|
|
31
|
+
self.send_http_request(args)
|
|
32
|
+
|
|
33
|
+
def send_tcp_request(self, args):
|
|
34
|
+
pass
|
|
35
|
+
# s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
36
|
+
# s.connect((self.ip, self.port))
|
|
37
|
+
# s.send(json.dumps(self.get_request(args)).encode('utf-8'))
|
|
38
|
+
# response = s.recv(self.buffer_size).decode('utf-8')
|
|
39
|
+
# print('{}'.format(response))
|
|
40
|
+
|
|
41
|
+
def send_http_request(self, args):
|
|
42
|
+
|
|
43
|
+
sim_address = 'localhost'
|
|
44
|
+
if 'sim_address' in self.cfg:
|
|
45
|
+
sim_address = self.cfg['sim_address']
|
|
46
|
+
connection_addr = os.environ.get('AVRS_SIM_ADDRESS', sim_address)
|
|
47
|
+
|
|
48
|
+
sim_port = 30313
|
|
49
|
+
if 'sim_api_port' in self.cfg:
|
|
50
|
+
sim_port = self.cfg['sim_api_port']
|
|
51
|
+
|
|
52
|
+
if args.verbose:
|
|
53
|
+
print('sending request to: {}:{}'.format(connection_addr, sim_port))
|
|
54
|
+
connection = http.client.HTTPConnection(connection_addr, sim_port, timeout=10)
|
|
55
|
+
headers = {'Content-type': 'application/json'}
|
|
56
|
+
body = json.dumps(self.get_request(args)).encode('utf-8')
|
|
57
|
+
connection.request('POST', '/post', body, headers)
|
|
58
|
+
response = connection.getresponse()
|
|
59
|
+
if response.status != 200:
|
|
60
|
+
print('response had status code {}'.format(response))
|
|
61
|
+
print('{}'.format(response.read().decode('utf-8')))
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from avrs.requests.request import AvrsApiRequest
|
|
2
|
+
|
|
3
|
+
class ResetToTrack(AvrsApiRequest):
|
|
4
|
+
def __init__(self, parser, cfg):
|
|
5
|
+
AvrsApiRequest.__init__(self, parser, cfg, 'ResetToTrack', 'Ego')
|
|
6
|
+
psr = parser.add_parser(
|
|
7
|
+
'reset-to-track',
|
|
8
|
+
help='moves the car to the closest point on track pointing down track')
|
|
9
|
+
|
|
10
|
+
psr.add_argument(
|
|
11
|
+
'--object-name',
|
|
12
|
+
default='ego',
|
|
13
|
+
help='the simulated object to reset to track')
|
|
14
|
+
|
|
15
|
+
psr.set_defaults(func=self.send_request)
|
|
16
|
+
|
|
17
|
+
def get_request_body(self, args):
|
|
18
|
+
self.target_object_id = args.object_name
|
|
19
|
+
return {
|
|
20
|
+
|
|
21
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import socket
|
|
2
|
+
import json
|
|
3
|
+
import os
|
|
4
|
+
import os.path
|
|
5
|
+
import multiprocessing
|
|
6
|
+
import time
|
|
7
|
+
import sys
|
|
8
|
+
import http.client
|
|
9
|
+
|
|
10
|
+
# the new API request
|
|
11
|
+
|
|
12
|
+
class AvrsRestApiRequest:
|
|
13
|
+
def __init__(self, parser, cfg, endpoint, method):
|
|
14
|
+
self.endpoint = endpoint
|
|
15
|
+
self.method = method
|
|
16
|
+
self.verbose = False
|
|
17
|
+
self.cfg = cfg
|
|
18
|
+
|
|
19
|
+
def get_request_body(self, args):
|
|
20
|
+
return {}
|
|
21
|
+
|
|
22
|
+
def get_request_params(self, args):
|
|
23
|
+
return {}
|
|
24
|
+
|
|
25
|
+
def send_request(self, args):
|
|
26
|
+
|
|
27
|
+
sim_address = '0.0.0.0'
|
|
28
|
+
# if 'sim_address' in self.cfg:
|
|
29
|
+
# sim_address = self.cfg['sim_address']
|
|
30
|
+
# connection_addr = os.environ.get('AVRS_SIM_ADDRESS', sim_address)
|
|
31
|
+
|
|
32
|
+
sim_port = 51111
|
|
33
|
+
# if 'sim_api_port' in self.cfg:
|
|
34
|
+
# sim_port = self.cfg['sim_api_port']
|
|
35
|
+
|
|
36
|
+
if args.verbose:
|
|
37
|
+
print('sending request to: {}:{}'.format(sim_address, sim_port))
|
|
38
|
+
connection = http.client.HTTPConnection(sim_address, sim_port, timeout=10)
|
|
39
|
+
headers = {'Content-type': 'application/json'}
|
|
40
|
+
body = json.dumps(self.get_request_body(args)).encode('utf-8')
|
|
41
|
+
connection.request(self.method, self.endpoint, body, headers)
|
|
42
|
+
response = connection.getresponse()
|
|
43
|
+
if response.status != 200:
|
|
44
|
+
print('response had status code {}'.format(response.status))
|
|
45
|
+
print('{}'.format(response.read().decode('utf-8')))
|
avrs/requests/restart.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from avrs.requests.request import AvrsApiRequest
|
|
2
|
+
|
|
3
|
+
class Restart(AvrsApiRequest):
|
|
4
|
+
def __init__(self, parser, cfg):
|
|
5
|
+
AvrsApiRequest.__init__(self, parser, cfg, 'RestartSimulation', 0)
|
|
6
|
+
psr = parser.add_parser('restart', help='command to restart the entire simulator')
|
|
7
|
+
psr.set_defaults(func=self.send_request)
|
|
8
|
+
|
|
9
|
+
def get_request_body(self, args):
|
|
10
|
+
return {
|
|
11
|
+
|
|
12
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from avrs.requests.request import AvrsApiRequest
|
|
2
|
+
from argparse import RawDescriptionHelpFormatter
|
|
3
|
+
from argparse import RawTextHelpFormatter
|
|
4
|
+
|
|
5
|
+
class AvrsScenarioRequests():
|
|
6
|
+
def __init__(self, parser, cfg):
|
|
7
|
+
psr = parser.add_parser('scenario', help='commands related to scenarios in the simulator')
|
|
8
|
+
sps = psr.add_subparsers(required= True, help='sub-command scenario')
|
|
9
|
+
StartScenarioRequest(sps, cfg)
|
|
10
|
+
StopScenarioRequest(sps, cfg)
|
|
11
|
+
|
|
12
|
+
class StartScenarioRequest(AvrsApiRequest):
|
|
13
|
+
def __init__(self, parser, cfg):
|
|
14
|
+
AvrsApiRequest.__init__(self, parser, cfg, 'ScenarioControl', '')
|
|
15
|
+
psr = parser.add_parser(
|
|
16
|
+
'start', help='start a scenario', formatter_class=RawTextHelpFormatter)
|
|
17
|
+
|
|
18
|
+
psr.add_argument(
|
|
19
|
+
'scenario_name',
|
|
20
|
+
default='',
|
|
21
|
+
help='the name of the scenario to start')
|
|
22
|
+
|
|
23
|
+
psr.set_defaults(func=self.send_request)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def get_request_body(self, args):
|
|
27
|
+
return {
|
|
28
|
+
'scenarioName': args.scenario_name,
|
|
29
|
+
'action': 'start'
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
class StopScenarioRequest(AvrsApiRequest):
|
|
33
|
+
def __init__(self, parser, cfg):
|
|
34
|
+
AvrsApiRequest.__init__(self, parser, cfg, 'ScenarioControl', '')
|
|
35
|
+
psr = parser.add_parser(
|
|
36
|
+
'stop', help='stop any active scenarios', formatter_class=RawTextHelpFormatter)
|
|
37
|
+
|
|
38
|
+
psr.set_defaults(func=self.send_request)
|
|
39
|
+
|
|
40
|
+
def get_request_body(self, args):
|
|
41
|
+
return {
|
|
42
|
+
'action': 'stop'
|
|
43
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
from avrs.requests.request import AvrsApiRequest
|
|
2
|
+
from argparse import RawTextHelpFormatter
|
|
3
|
+
|
|
4
|
+
SPAWN_OBJECT_HELP = '''
|
|
5
|
+
spawn an object with the specified configuration, optionally overriding its name
|
|
6
|
+
'''
|
|
7
|
+
|
|
8
|
+
class AvrsSpawnObjectRequest(AvrsApiRequest):
|
|
9
|
+
def __init__(self, parser, cfg):
|
|
10
|
+
AvrsApiRequest.__init__(self, parser, cfg, 'SpawnObject', 0)
|
|
11
|
+
psr = parser.add_parser('spawn-object', help=SPAWN_OBJECT_HELP, formatter_class=RawTextHelpFormatter)
|
|
12
|
+
|
|
13
|
+
psr.add_argument(
|
|
14
|
+
'--object-type',
|
|
15
|
+
default='Eav24',
|
|
16
|
+
help='the type of object to spawn')
|
|
17
|
+
|
|
18
|
+
psr.add_argument(
|
|
19
|
+
'spec',
|
|
20
|
+
help='the specialization of the object (eg eav24_mv0)')
|
|
21
|
+
|
|
22
|
+
psr.add_argument(
|
|
23
|
+
'--name-override',
|
|
24
|
+
default='',
|
|
25
|
+
help='if not empty, will override the name given to the spawned object')
|
|
26
|
+
|
|
27
|
+
psr.add_argument(
|
|
28
|
+
'spawn_landmark',
|
|
29
|
+
help='what landmark to spawn at (eg MvStart0, MvStart1, MvStart2, or MvStart3)')
|
|
30
|
+
|
|
31
|
+
psr.set_defaults(func=self.send_request)
|
|
32
|
+
|
|
33
|
+
def get_request_body(self, args):
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
'name': args.name_override,
|
|
37
|
+
'type': args.object_type,
|
|
38
|
+
'spec': args.spec,
|
|
39
|
+
'bUseStoredInitializer': True,
|
|
40
|
+
'location': {},
|
|
41
|
+
'rotation': {},
|
|
42
|
+
'landmark': args.spawn_landmark,
|
|
43
|
+
'payloads': []
|
|
44
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from avrs.requests.request import AvrsApiRequest
|
|
2
|
+
|
|
3
|
+
class Teleport(AvrsApiRequest):
|
|
4
|
+
def __init__(self, parser, cfg):
|
|
5
|
+
AvrsApiRequest.__init__(self, parser, cfg, 'Teleport', "Ego")
|
|
6
|
+
|
|
7
|
+
psr = parser.add_parser('teleport',
|
|
8
|
+
help='Teleports the car to the given x,y,z in either NED or LLA.')
|
|
9
|
+
|
|
10
|
+
psr.add_argument('x', type=float,
|
|
11
|
+
help='new x position (NED meters) or latitude (if frame is set to LLA)')
|
|
12
|
+
|
|
13
|
+
psr.add_argument('y', type=float,
|
|
14
|
+
help='new y position (NED meters) or longitude (if frame is set to LLA)')
|
|
15
|
+
|
|
16
|
+
psr.add_argument('z', type=float,
|
|
17
|
+
help='new z position (NED meters) or altitude (if frame is set to LLA)')
|
|
18
|
+
|
|
19
|
+
psr.add_argument('--yaw', type=float, default=0.0,
|
|
20
|
+
help='the yaw in degrees (0 north, + CW) to apply post teleport')
|
|
21
|
+
|
|
22
|
+
psr.add_argument('--frame', choices=['LLA', 'ned'], default='ned', help='LLA or NED coordinate system.')
|
|
23
|
+
|
|
24
|
+
psr.add_argument(
|
|
25
|
+
'--object-name',
|
|
26
|
+
default='ego',
|
|
27
|
+
help='the simulated object to teleport')
|
|
28
|
+
|
|
29
|
+
psr.set_defaults(func=self.send_request)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def get_request_body(self, args):
|
|
33
|
+
self.target_object_id = args.object_name
|
|
34
|
+
return {
|
|
35
|
+
"X": args.x,
|
|
36
|
+
"Y": args.y,
|
|
37
|
+
"Z": args.z,
|
|
38
|
+
"yaw": args.yaw,
|
|
39
|
+
"NavFrame": args.frame
|
|
40
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from avrs.requests.request import AvrsApiRequest
|
|
2
|
+
|
|
3
|
+
class AvrsToggleHudRequest(AvrsApiRequest):
|
|
4
|
+
def __init__(self, parser, cfg):
|
|
5
|
+
AvrsApiRequest.__init__(self, parser, cfg, 'ToggleHud', 'Ego')
|
|
6
|
+
psr = parser.add_parser('toggle-hud', help='toggles the HUD on or off')
|
|
7
|
+
psr.set_defaults(func=self.send_request)
|
|
8
|
+
|
|
9
|
+
def get_request_body(self, args):
|
|
10
|
+
return {
|
|
11
|
+
}
|
avrs/requests/vd.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
from avrs.requests.request import AvrsApiRequest
|
|
2
|
+
|
|
3
|
+
class Vd():
|
|
4
|
+
def __init__(self, parser, cfg):
|
|
5
|
+
psr = parser.add_parser('vd', help='Vehicle dynamic options')
|
|
6
|
+
sps = psr.add_subparsers(required= True, help='sub-command of vd')
|
|
7
|
+
SetFrictionModifier(sps, cfg)
|
|
8
|
+
GetFrictionModifier(sps, cfg)
|
|
9
|
+
#SlipModel(sps, cfg)
|
|
10
|
+
|
|
11
|
+
class SetFrictionModifier(AvrsApiRequest):
|
|
12
|
+
def __init__(self, parser, cfg):
|
|
13
|
+
AvrsApiRequest.__init__(self, parser, cfg, 'SetFrictionModifiers', 'Ego')
|
|
14
|
+
psr = parser.add_parser('set-friction-modifier', help='Change the amount of grip the car has.'
|
|
15
|
+
+ '0 is no grip and higher values will prevent spinning')
|
|
16
|
+
psr.add_argument('modifier', type = float, help = "Modified grip value")
|
|
17
|
+
psr.add_argument('tires', help = "Tires to apply the modifier to",
|
|
18
|
+
choices=("FL", "FR", "RL", "RR", "F", "R", "All"))
|
|
19
|
+
|
|
20
|
+
psr.add_argument(
|
|
21
|
+
'--object-name',
|
|
22
|
+
default='ego',
|
|
23
|
+
help='the simulated object to modify the friction for')
|
|
24
|
+
|
|
25
|
+
psr.set_defaults(func=self.send_request)
|
|
26
|
+
|
|
27
|
+
def get_request_body(self, args):
|
|
28
|
+
self.target_object_id = args.object_name
|
|
29
|
+
return {
|
|
30
|
+
'NewModifier': args.modifier,
|
|
31
|
+
'Tires': args.tires
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
class GetFrictionModifier(AvrsApiRequest):
|
|
35
|
+
def __init__(self, parser, cfg):
|
|
36
|
+
AvrsApiRequest.__init__(self, parser, cfg, 'GetFrictionModifiers', 'Ego')
|
|
37
|
+
psr = parser.add_parser('get-friction-modifier', help='Get the amount of grip the car has.')
|
|
38
|
+
psr.add_argument('tires', help = "Tires to get the grip value from",
|
|
39
|
+
choices=("FL", "FR", "RL", "RR", "F", "R", "All"))
|
|
40
|
+
|
|
41
|
+
psr.add_argument(
|
|
42
|
+
'--object-name',
|
|
43
|
+
default='ego',
|
|
44
|
+
help='the simulated object to get the friction from')
|
|
45
|
+
|
|
46
|
+
psr.set_defaults(func=self.send_request)
|
|
47
|
+
|
|
48
|
+
def get_request_body(self, args):
|
|
49
|
+
self.target_object_id = args.object_name
|
|
50
|
+
return {
|
|
51
|
+
'Tires': args.tires
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
# class SlipModel(AvrsApiRequest):
|
|
55
|
+
# def __init__(self, parser, cfg):
|
|
56
|
+
# AvrsApiRequest.__init__(self, parser, cfg, 'SlipModel', 'Ego')
|
|
57
|
+
# psr = parser.add_parser('slip-model', help='Change the tire slip model to be pure slip only or combined slip')
|
|
58
|
+
# psr.add_argument('slip', choices = ['pure-slip, combined-slip'], help = 'type of slip')
|
|
59
|
+
# psr.set_defaults(func=self.send_request)
|
|
60
|
+
|
|
61
|
+
# def get_request_body(self, args):
|
|
62
|
+
# return {
|
|
63
|
+
# 'Modifier Value': args.slip
|
|
64
|
+
# }
|