autoverse-cli 0.4.1__py3-none-any.whl → 0.6.0__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.
@@ -1,10 +1,11 @@
1
1
  from avrs.requests.request import AvrsApiRequest
2
2
 
3
- class AvrsEditEnvironmentRequests():
3
+ class AvrsEnvironmentRequests():
4
4
  def __init__(self, parser, cfg):
5
- psr = parser.add_parser('edit-environment', help='Edits the environment')
5
+ psr = parser.add_parser('environment', help='Edits the environment')
6
6
  sps = psr.add_subparsers(required= True, help='')
7
7
  AvrsSetTimeOfDayRequest(sps, cfg)
8
+ AvrsGetEnvironmentMetaRequets(sps, cfg)
8
9
 
9
10
 
10
11
  class AvrsSetTimeOfDayRequest(AvrsApiRequest):
@@ -18,4 +19,15 @@ class AvrsSetTimeOfDayRequest(AvrsApiRequest):
18
19
  self.target_object_id = ''
19
20
  return {
20
21
  'TimeOfDay': args.tod
21
- }
22
+ }
23
+
24
+ class AvrsGetEnvironmentMetaRequets(AvrsApiRequest):
25
+ def __init__(self, parser, cfg):
26
+ AvrsApiRequest.__init__(self, parser, cfg, 'GetEnvironmentMeta', '')
27
+ psr = parser.add_parser('get-meta', help='get metadata about the currently loaded environment')
28
+ psr.set_defaults(func=self.send_request)
29
+
30
+ def get_request_body(self, args):
31
+ self.target_object_id = ''
32
+ return {
33
+ }
@@ -0,0 +1,186 @@
1
+ from avrs.requests.request import AvrsApiRequest
2
+ from argparse import RawDescriptionHelpFormatter
3
+ from argparse import RawTextHelpFormatter
4
+
5
+ class AvrsFaultInjectionRequests():
6
+ def __init__(self, parser, cfg):
7
+ psr = parser.add_parser('inject-fault', help='utilty to inject faults into components (sensors, actuators, etc)')
8
+ sps = psr.add_subparsers(required= True, help='sub-command inject-fault')
9
+ AvrsGnssFaultRequest(sps, cfg)
10
+ AvrsLidarFaultRequest(sps, cfg)
11
+ AvrsImuFaultRequest(sps, cfg)
12
+ AvrsCanFaultRequest(sps, cfg)
13
+
14
+ def add_base_injection_args(psr):
15
+
16
+ psr.add_argument(
17
+ '--target',
18
+ default='ego',
19
+ help='the simulated object to apply the fault to')
20
+
21
+ psr.add_argument(
22
+ '--duration',
23
+ type=float,
24
+ default=1.0,
25
+ help='how long to apply the fault (0.0 is infinite)')
26
+
27
+ psr.add_argument(
28
+ '--dropout',
29
+ action='store_true',
30
+ help='if specified, will apply a complete dropout fault')
31
+
32
+ psr.add_argument(
33
+ '--freeze',
34
+ action='store_true',
35
+ help='if specified, will freeze the data (values will not change)')
36
+
37
+ class AvrsGnssFaultRequest(AvrsApiRequest):
38
+ def __init__(self, parser, cfg):
39
+ AvrsApiRequest.__init__(self, parser, cfg, 'FaultInjection', '')
40
+
41
+ psr = parser.add_parser(
42
+ 'gnss',
43
+ help='inject a gnss fault',
44
+ formatter_class=RawTextHelpFormatter)
45
+
46
+ psr.add_argument(
47
+ '--horizontal-bias',
48
+ type=float,
49
+ default=0.0,
50
+ help='horizontal bias to apply to the sensor as a fault')
51
+
52
+ psr.add_argument(
53
+ '--vertical-bias',
54
+ type=float,
55
+ default=0.0,
56
+ help='vertical bias to apply to the sensor as a fault')
57
+
58
+ psr.add_argument(
59
+ '--horizontal-stdev',
60
+ type=float,
61
+ default=0.0,
62
+ help='horizontal standard deviation to apply to the sensor')
63
+
64
+ psr.add_argument(
65
+ '--vertical-stdev',
66
+ type=float,
67
+ default=0.0,
68
+ help='vertical standard deviation to apply to the sensor')
69
+
70
+ add_base_injection_args(psr)
71
+ psr.set_defaults(func=self.send_request)
72
+
73
+ def get_request_body(self, args):
74
+ self.target_object_id = args.target
75
+ self.verbose = args.verbose
76
+ return {
77
+ 'faultType': 'GnssFault',
78
+ 'duration': args.duration,
79
+ 'bIsDropout': args.dropout,
80
+ 'bIsFreeze': args.freeze,
81
+ 'JsonBody': {
82
+ 'verticalBias': args.vertical_bias,
83
+ 'verticalStdev': args.vertical_stdev,
84
+ 'horizontalBias': args.horizontal_bias,
85
+ 'horizontalStdev': args.horizontal_stdev
86
+ }
87
+ }
88
+
89
+ class AvrsImuFaultRequest(AvrsApiRequest):
90
+ def __init__(self, parser, cfg):
91
+ AvrsApiRequest.__init__(self, parser, cfg, 'FaultInjection', '')
92
+
93
+ psr = parser.add_parser(
94
+ 'imu',
95
+ help='inject an imu fault',
96
+ formatter_class=RawTextHelpFormatter)
97
+
98
+ psr.add_argument(
99
+ '--bias',
100
+ type=float,
101
+ default=0.0,
102
+ help='horizontal bias to apply to the sensor as a fault')
103
+
104
+ psr.add_argument(
105
+ '--stdev',
106
+ type=float,
107
+ default=0.0,
108
+ help='horizontal standard deviation to apply to the sensor')
109
+
110
+ add_base_injection_args(psr)
111
+ psr.set_defaults(func=self.send_request)
112
+
113
+ def get_request_body(self, args):
114
+ self.target_object_id = args.target
115
+ self.verbose = args.verbose
116
+ return {
117
+ 'faultType': 'ImuFault',
118
+ 'duration': args.duration,
119
+ 'bIsDropout': args.dropout,
120
+ 'bIsFreeze': args.freeze,
121
+ 'JsonBody': {
122
+ 'bias': args.bias,
123
+ 'stdev': args.stdev
124
+ }
125
+ }
126
+
127
+ class AvrsLidarFaultRequest(AvrsApiRequest):
128
+ def __init__(self, parser, cfg):
129
+ AvrsApiRequest.__init__(self, parser, cfg, 'FaultInjection', '')
130
+
131
+ psr = parser.add_parser(
132
+ 'lidar',
133
+ help='inject a lidar fault',
134
+ formatter_class=RawTextHelpFormatter)
135
+
136
+ psr.add_argument(
137
+ '--point-density-reduction',
138
+ type=float,
139
+ default=0.5,
140
+ help='the percent of point density reduction, where 1.0 drops all points')
141
+
142
+ add_base_injection_args(psr)
143
+ psr.set_defaults(func=self.send_request)
144
+
145
+ def get_request_body(self, args):
146
+ self.target_object_id = args.target
147
+ self.verbose = args.verbose
148
+ return {
149
+ 'faultType': 'LidarFault',
150
+ 'duration': args.duration,
151
+ 'bIsDropout': args.dropout,
152
+ 'bIsFreeze': args.freeze,
153
+ 'JsonBody': {
154
+ 'pointDensityReduction': args.point_density_reduction
155
+ }
156
+ }
157
+
158
+ class AvrsCanFaultRequest(AvrsApiRequest):
159
+ def __init__(self, parser, cfg):
160
+ AvrsApiRequest.__init__(self, parser, cfg, 'FaultInjection', '')
161
+
162
+ psr = parser.add_parser(
163
+ 'can',
164
+ help='inject a can',
165
+ formatter_class=RawTextHelpFormatter)
166
+
167
+ psr.add_argument(
168
+ 'can_type',
169
+ choices = ['bsu', 'badenia', 'kistler', 'all'],
170
+ help='what type of the can interface you wish to apply the fault to')
171
+
172
+ add_base_injection_args(psr)
173
+ psr.set_defaults(func=self.send_request)
174
+
175
+ def get_request_body(self, args):
176
+ self.target_object_id = args.target
177
+ self.verbose = args.verbose
178
+ return {
179
+ 'faultType': 'CanFault',
180
+ 'duration': args.duration,
181
+ 'bIsDropout': True,
182
+ 'bIsFreeze': args.freeze,
183
+ 'JsonBody': {
184
+ 'canType': args.can_type
185
+ }
186
+ }
@@ -0,0 +1,26 @@
1
+ from avrs.requests.request import AvrsApiRequest
2
+
3
+ class AvrsListSimObjectsRequest(AvrsApiRequest):
4
+ def __init__(self, parser, cfg):
5
+ AvrsApiRequest.__init__(self, parser, cfg, 'ListSimObjects', 0)
6
+ psr = parser.add_parser('list-sim-objects', help='list all the sim objects that currently exist in the simulator')
7
+ psr.add_argument(
8
+ '-v',
9
+ action='store_true',
10
+ help='request verbose output')
11
+ psr.add_argument(
12
+ '--components',
13
+ action='store_true',
14
+ help='also print information about the object components')
15
+ psr.add_argument(
16
+ '--isolate',
17
+ default='',
18
+ help='indicate a specific object of interest')
19
+ psr.set_defaults(func=self.send_request)
20
+
21
+ def get_request_body(self, args):
22
+ return {
23
+ "bVerbose": args.v,
24
+ 'bListComponents': args.components,
25
+ 'isolate': args.isolate
26
+ }
avrs/requests/request.py CHANGED
@@ -11,12 +11,15 @@ class AvrsApiRequest:
11
11
  def __init__(self, parser, cfg, request_type, target_id):
12
12
  self.target_object_id = target_id
13
13
  self.request_type = request_type
14
+ self.verbose = False
14
15
 
15
16
  def get_request(self, args):
17
+ body = self.get_request_body(args)
16
18
  return {
17
19
  'TargetObjectId': self.target_object_id,
18
20
  'RequestType': self.request_type,
19
- 'RequestBody': json.dumps(self.get_request_body(args))
21
+ 'bVerboseResponse': self.verbose,
22
+ 'RequestBody': body
20
23
  }
21
24
 
22
25
  def get_request_body(self, args):
@@ -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,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
+ }
@@ -0,0 +1,21 @@
1
+ from avrs.requests.request import AvrsApiRequest
2
+
3
+ class AvrsConfigureVehicleInputRequest(AvrsApiRequest):
4
+ def __init__(self, parser, cfg):
5
+ AvrsApiRequest.__init__(self, parser, cfg, 'ConfigureVehicleInput', 'Ego')
6
+ psr = parser.add_parser(
7
+ 'configure-vehicle-input',
8
+ help='Allows different input modes to be set for a vehicle')
9
+
10
+ psr.add_argument(
11
+ 'input_mode',
12
+ default='None',
13
+ choices=['None', 'Keyboard', 'WheelAndPedals', 'CAN'],
14
+ help='the type of input mode to set')
15
+
16
+ psr.set_defaults(func=self.send_request)
17
+
18
+ def get_request_body(self, args):
19
+ return {
20
+ "InputMode": args.input_mode
21
+ }
@@ -0,0 +1,235 @@
1
+ import random
2
+ from avrs.requests.request import AvrsApiRequest
3
+ from argparse import RawDescriptionHelpFormatter
4
+ from argparse import RawTextHelpFormatter
5
+
6
+ class AvrsVehicleReplayRequests():
7
+ def __init__(self, parser, cfg):
8
+ psr = parser.add_parser('vehicle-replay', help='utilty for recording and replaying vehicle motion')
9
+ sps = psr.add_subparsers(required= True, help='sub-command vehicle-replay')
10
+ SpawnReplayVehicle(sps, cfg)
11
+ StartVehicleReplayRecording(sps, cfg)
12
+ StopVehicleReplayRecording(sps, cfg)
13
+ DespawnReplayVehicle(sps, cfg)
14
+
15
+ class SpawnReplayVehicle(AvrsApiRequest):
16
+ def __init__(self, parser, cfg):
17
+ AvrsApiRequest.__init__(self, parser, cfg, 'SpawnObject', '')
18
+ psr = parser.add_parser(
19
+ 'spawn', help='spawn a vehicle intended to replay motion', formatter_class=RawTextHelpFormatter)
20
+
21
+ psr.add_argument(
22
+ 'replay_file',
23
+ default='',
24
+ help='the replay file to use ("random" for a random profile)')
25
+
26
+ psr.add_argument(
27
+ '--name',
28
+ default='',
29
+ help='name of the replay vehicle to spawn')
30
+
31
+ psr.add_argument(
32
+ '--vehicle-type',
33
+ default='EAV24',
34
+ help='what type of vehicle to spawn for replay')
35
+
36
+ # psr.add_argument(
37
+ # '--position',
38
+ # choices=('relative', 'absolute'),
39
+ # default='absolute',
40
+ # help=NPC_SPAWN_POSITION_HELP)
41
+
42
+
43
+ # psr.add_argument(
44
+ # '--velocity-type',
45
+ # default='constant',
46
+ # help='the path the NPC follows is a constant velocity or speed')
47
+
48
+ # psr.add_argument(
49
+ # '--speed',
50
+ # type=float,
51
+ # default=20,
52
+ # help='the speed of the npc is m/s')
53
+
54
+ psr.add_argument(
55
+ '--rate',
56
+ type=float,
57
+ default=1.0,
58
+ help='the playback rate, 1.0 is normal')
59
+
60
+ psr.add_argument(
61
+ '--random-start',
62
+ action='store_true',
63
+ help='if set, will start at a random point in the replay')
64
+
65
+ psr.add_argument(
66
+ '--relative-dist',
67
+ type=float,
68
+ default=40.0,
69
+ help='the distance relative to ego to start the playback (-1 to start at playback start)')
70
+
71
+ psr.add_argument(
72
+ '--auto-start',
73
+ action='store_true',
74
+ help='if set, the npc will begin moving immediately')
75
+
76
+ psr.add_argument(
77
+ '--count',
78
+ type=int,
79
+ default=1,
80
+ help='the number of npcs to spawn (only works with automatic name)')
81
+
82
+ # psr.add_argument(
83
+ # '--enable-sensors',
84
+ # type=bool,
85
+ # default=False,
86
+ # help='whether to enable sensors on the replay vehicle')
87
+
88
+ psr.add_argument(
89
+ '--with-view-cameras',
90
+ action='store_true',
91
+ help='if set, will attach viewing cameras to the replay vehicle')
92
+
93
+ psr.set_defaults(func=self.send_request)
94
+
95
+ def send_request(self, args):
96
+ for i in range(args.count):
97
+ self.send_http_request(args)
98
+
99
+ def get_request_body(self, args):
100
+
101
+ replay_ipd = {
102
+ 'bEnableRecording': False,
103
+ 'bRecordOnPhysicsTick': False,
104
+ 'recordMotionMinSpeedThreshold': 0.01,
105
+ 'bEnableReplay': True,
106
+ 'bApplyInitialConfig': True,
107
+ 'initialConfig': {
108
+ 'playRate': args.rate,
109
+ 'profile': args.replay_file,
110
+ 'bUseRandomProfile': args.replay_file == 'random',
111
+ 'replayAction': 'start' if args.auto_start else '',
112
+ 'bStartReplayAtRandomTime': args.random_start,
113
+ 'relativeDistance': args.relative_dist
114
+ }
115
+ }
116
+
117
+ eav_init_pld = {
118
+ "bEnableBsuCan": False,
119
+ "bEnableKistlerCan": False,
120
+ "bEnableBadeniaCan": False,
121
+ "bHudEnabled": False,
122
+ "bLidarEnabled": False,
123
+ "bCameraEnabled": False,
124
+ "bPublishInputs": False,
125
+ "bPublishGroundTruth": False
126
+ }
127
+
128
+ plds = [
129
+ {
130
+ 'TypeName': 'WheeledVehicleReplayIpd',
131
+ 'Body': replay_ipd
132
+ },
133
+ {
134
+ 'TypeName': 'Eav24Initializer',
135
+ 'Body': eav_init_pld
136
+ }
137
+ ]
138
+
139
+ if args.with_view_cameras:
140
+ plds.append(
141
+ {
142
+ 'TypeName': 'InitializerTemplates',
143
+ 'Body': {
144
+ 'Templates': [
145
+ {
146
+ 'PayloadType': 'SimViewTargetIpd',
147
+ 'PayloadSpec': 'DefaultCarCams'
148
+ }
149
+ ]
150
+ }
151
+ })
152
+
153
+ # Create time based name if not specified
154
+ name = args.name
155
+ if name == '':
156
+ name = 'npc_{}'.format(random.randint(0, 100000))
157
+
158
+ return {
159
+ 'Name': name,
160
+ 'Type': args.vehicle_type,
161
+ 'Location': {},
162
+ 'Rotation': {},
163
+ 'Payloads': plds
164
+ }
165
+
166
+ class StartVehicleReplayRecording(AvrsApiRequest):
167
+ def __init__(self, parser, cfg):
168
+ AvrsApiRequest.__init__(self, parser, cfg, 'ConfigureVehicleReplay', 'Ego')
169
+ psr = parser.add_parser(
170
+ 'start-recording', help='begin recording vehicle motion', formatter_class=RawTextHelpFormatter)
171
+
172
+ psr.add_argument(
173
+ 'out_file',
174
+ help='the file name to use for the saved recording')
175
+
176
+ psr.add_argument(
177
+ '--rate-hz',
178
+ type=float,
179
+ default=100.0,
180
+ help='the rate to record vehicle motion. high rates will produce large files')
181
+
182
+ psr.set_defaults(func=self.send_request)
183
+
184
+
185
+ def get_request_body(self, args):
186
+ return {
187
+ 'PlayRate': -1.0,
188
+ 'profile': '',
189
+ 'replayAction': '',
190
+ #'teleportLocation': '',
191
+ 'recordAction': 'start',
192
+ 'recordFileName': args.out_file,
193
+ 'recordRateHz': args.rate_hz
194
+ }
195
+
196
+ class StopVehicleReplayRecording(AvrsApiRequest):
197
+ def __init__(self, parser, cfg):
198
+ AvrsApiRequest.__init__(self, parser, cfg, 'ConfigureVehicleReplay', 'Ego')
199
+ psr = parser.add_parser(
200
+ 'stop-recording', help='begin recording vehicle motion', formatter_class=RawTextHelpFormatter)
201
+ psr.set_defaults(func=self.send_request)
202
+
203
+
204
+ def get_request_body(self, args):
205
+ return {
206
+ 'recordAction': 'stop',
207
+ }
208
+
209
+ class DespawnReplayVehicle(AvrsApiRequest):
210
+ def __init__(self, parser, cfg):
211
+ AvrsApiRequest.__init__(self, parser, cfg, 'DespawnObject', 'Ego')
212
+ psr = parser.add_parser(
213
+ 'despawn', help='despawn a replay vehicle or all replay vehicles', formatter_class=RawTextHelpFormatter)
214
+
215
+ psr.add_argument(
216
+ '--name',
217
+ default='',
218
+ help='name of the replay vehicle to despawn')
219
+
220
+ psr.add_argument(
221
+ '--all',
222
+ action='store_true',
223
+ help='if set, will despawn all replay vehicles')
224
+
225
+ psr.set_defaults(func=self.send_request)
226
+
227
+
228
+ def get_request_body(self, args):
229
+ self.target_object_id = args.name
230
+ tags = ["Npc"] if args.all else []
231
+
232
+ return {
233
+ 'tags': tags,
234
+ 'bMatchAnyTag': True
235
+ }
avrs/simconfig.py ADDED
@@ -0,0 +1,61 @@
1
+ import os
2
+ import stat
3
+ import json
4
+ import http.client
5
+ from avrs.cfg import *
6
+ from avrs.launcher_util import *
7
+ from avrs.simconfig_util import *
8
+
9
+ class AvrsSimConfig:
10
+ def __init__(self, parent_parser, cfg):
11
+ self.cfg = cfg
12
+ sim_config_parser = parent_parser.add_parser(
13
+ 'sim-config',
14
+ help='utilities for easily configuring the simulator\n\n')
15
+
16
+ sps = sim_config_parser.add_subparsers(required=True, help='sim-config options')
17
+
18
+ apply_preset_parser = sps.add_parser(
19
+ 'apply-preset',
20
+ help='apply a preset configuration for a certain use-case')
21
+ apply_preset_parser.add_argument(
22
+ 'preset_name',
23
+ choices=['default', 'lightweight', 'a2rl'],
24
+ help='the name of the preset to apply')
25
+ apply_preset_parser.add_argument(
26
+ '--sim-path',
27
+ default='',
28
+ help='''
29
+ the path to the simulator installation having the intended config to modify, or the
30
+ index of a known installation. if there is only one known installation, it will be used as
31
+ the target
32
+ ''')
33
+ apply_preset_parser.set_defaults(func=self.apply_preset)
34
+
35
+
36
+ def apply_preset(self, args):
37
+ sim_path = args.sim_path
38
+ if sim_path == '':
39
+ if 'installs' in self.cfg and len(self.cfg['installs']) > 0:
40
+ if len(self.cfg['installs']) > 1:
41
+ print('multiple known installs. specify path or index')
42
+ for i in range(len(self.cfg['installs'])):
43
+ print('({}) {}'.format(i, self.cfg['installs'][i]))
44
+ return
45
+ else:
46
+ sim_path = self.cfg['installs'][0]
47
+ else:
48
+ print('sim_path not specified and no known existing installations')
49
+ return
50
+ try:
51
+ sim_path_index = int(sim_path)
52
+ if 'installs' in self.cfg and len(self.cfg['installs']) > sim_path_index:
53
+ sim_path = self.cfg['installs'][sim_path_index]
54
+ except Exception as e:
55
+ pass
56
+ if not is_installed_sim(sim_path):
57
+ print('{} is not a valid sim installation'.format(sim_path))
58
+ return
59
+
60
+ print('applying preset {} to sim install at {}'.format(args.preset_name, sim_path))
61
+ apply_simconfig_preset(get_sim_saved_dir(sim_path), args.preset_name)