autoverse-cli 0.4.1__py3-none-any.whl → 0.6.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
avrs/simconfig_util.py ADDED
@@ -0,0 +1,70 @@
1
+ import os
2
+ import json
3
+
4
+ class SimConfigFiles():
5
+ def __init__(self, saved_dir):
6
+
7
+ self.required_files = {
8
+ 'main': os.path.join(saved_dir, 'simconfig.json'),
9
+ 'eav24': os.path.join(saved_dir, 'Objects', 'Eav24_default.json'),
10
+ 'yas': os.path.join(saved_dir, 'Environments', 'yasmarina_env.json')
11
+ }
12
+ self.files = {}
13
+
14
+ ok, status = self.valdiate()
15
+ if ok:
16
+ for name, path in self.required_files.items():
17
+ with open(path, 'r', encoding='utf-8') as f:
18
+ self.files[name] = json.load(f)
19
+
20
+ def valdiate(self):
21
+ for name, path in self.required_files.items():
22
+ if not os.path.exists(path):
23
+ return (False, '{} not found'.format(path))
24
+ return (True, '')
25
+
26
+ def save(self):
27
+ for name, path in self.required_files.items():
28
+ with open(path, 'w', encoding='utf-8') as f:
29
+ json.dump(self.files[name], f, ensure_ascii=False, indent=4)
30
+
31
+ def apply_simconfig_preset(sim_saved_dir, preset_name):
32
+ cfg_files = SimConfigFiles(sim_saved_dir)
33
+ ok, status = cfg_files.valdiate()
34
+ if not ok:
35
+ print(status)
36
+ return
37
+
38
+ presets = {
39
+ 'default': apply_default_simconfig_preset,
40
+ 'lightweight': apply_lightweight_simconfig_preset,
41
+ 'a2rl': apply_a2rl_simconfig_preset
42
+ }
43
+ presets[preset_name](cfg_files)
44
+
45
+ def apply_default_simconfig_preset(cfg_files):
46
+ files = cfg_files.files
47
+
48
+ print('globally enabling ROS2 and CAN')
49
+ files['main']['interfaces']['bEnableRos2'] = True
50
+ files['main']['interfaces']['bEnableCan'] = True
51
+
52
+ print('ensuring default eav24 and yasmarina are reference in main config')
53
+ if not 'Environments/yasmarina_env.json' in files['main']['environmentPaths']:
54
+ print('missing yas environment. adding')
55
+ print('{}'.format(files['main']['environmentPaths']))
56
+ if not 'Objects/Eav24_default.json' in files['main']['objectTemplatePaths']:
57
+ print('missing eav24. adding')
58
+
59
+ cfg_files.save()
60
+
61
+
62
+ def apply_lightweight_simconfig_preset(cfg_files):
63
+ files = cfg_files.files
64
+
65
+ cfg_files.save()
66
+
67
+ def apply_a2rl_simconfig_preset(cfg_files):
68
+ files = cfg_files.files
69
+
70
+ cfg_files.save()
@@ -1,28 +0,0 @@
1
- avrs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- avrs/app_version.py,sha256=Ko9gSD_3pTimSupH_9L-pJ4Mi__5bhfLe7AbEmiATVA,855
3
- avrs/argparse_help.py,sha256=EoEaohGXZXqJvs1dFEzbo9vh47CYdHdSY2Im2Ps2iFo,945
4
- avrs/avrs.py,sha256=3dP6YE8aB2IGN0wu_FUcRW4fch6h-b97sFcUeF0vfC0,1953
5
- avrs/cfg.py,sha256=9NBtPrJjVN7gj_vxlvO4wOEx3OFw4d2qQgLIVLiccD0,701
6
- avrs/launcher.py,sha256=OWwIQDgeIwGLgmLnCxv7RbzVfRNLxSbg3eaZLJ2K64s,7467
7
- avrs/launcher_util.py,sha256=X60Jd2JUXr1MmdEF0lwjUBC5gHZte9uLlSgLWOLofXc,5121
8
- avrs/tests.py,sha256=3JeYBjn0tRqHXERDROfzmYuW1KXeCcKur5Bw-EIegto,153
9
- avrs/requests/can.py,sha256=iL2Dsk-V4tm37D-F1QoauaxeQtLAbg5br7zJcoR9h0o,5295
10
- avrs/requests/code_booz.py,sha256=5bzT8Ra6EIwI19TqXMxkHG_llnyFgqSzTSo7yLNV9Vc,2274
11
- avrs/requests/demo.py,sha256=TksvKX5YmL8-FQ4h7MWwjyIwcaZQrF9vCQ20PdfgS3Q,1138
12
- avrs/requests/edit_environment.py,sha256=iITvLHJ4N6m-RE8dC_KnFxoTNKSjQu7ydERfQvVtb58,828
13
- avrs/requests/input.py,sha256=SkfVjk3LsOhYNXEwn0rcSS6kZK3g8DXoMPX8Zc9LnCo,1855
14
- avrs/requests/log_path.py,sha256=Ur24C9VqPVx78MfpicgQu2uOEe-0dXbGoWF_7dzMtZE,1326
15
- avrs/requests/move_to_landmark.py,sha256=cLRBKu9XEDsmCoftBJ8JwoBLqzb0IZsxFMBnus4T-kc,702
16
- avrs/requests/npc.py,sha256=Y_WovbcLomCCcOLAMMO_DHZtc1crAzWo97qEIGS3SvU,9691
17
- avrs/requests/request.py,sha256=3hbBAt_Kd9n-HuggIbziJ3xs-VcRfLBc2GEFSOQ-LJ4,1512
18
- avrs/requests/reserve_mv_slot.py,sha256=p_jiTV7rcoyJU6u3UR9sqPBpSaq8-PWMEs0Ckm2Hf8w,3843
19
- avrs/requests/reset_to_track.py,sha256=lSd2YavBxDV_hQMhVoi08_TpTFEq7G2MA18xosFYa1g,450
20
- avrs/requests/restart.py,sha256=ih5mnWiU34q3-xhOth45CtOUXxKI0PoMDCnFJV0JbwE,415
21
- avrs/requests/teleport.py,sha256=WpnB2-Ii0FGI11EXTAHlaF5zqZIsgEyJnJ2j_w4rDFY,824
22
- avrs/requests/vd.py,sha256=at6oUAGY2h0OxYU6MLOi1gnxyUn6i24vL9DUAj0L880,1600
23
- autoverse_cli-0.4.1.dist-info/LICENSE,sha256=d4eWXho-u18HkBsX4K21uHX_bBb2UXZSrJdsb7Z_JlM,2647
24
- autoverse_cli-0.4.1.dist-info/METADATA,sha256=bH_SXpVXI7_MIGg6qVxJZ26pEBNDVBLRdh0xFh_Oe5U,3317
25
- autoverse_cli-0.4.1.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
26
- autoverse_cli-0.4.1.dist-info/entry_points.txt,sha256=Cb9qsUyU5AKkklehCcvtfT0-N3SXbUEqvjze4iEU5kE,40
27
- autoverse_cli-0.4.1.dist-info/top_level.txt,sha256=-AJO2e4MCVej6hY0U84pu5NfMeMW5qaAPSMisDT5rmA,5
28
- autoverse_cli-0.4.1.dist-info/RECORD,,
avrs/requests/can.py DELETED
@@ -1,131 +0,0 @@
1
- from avrs.requests.request import AvrsApiRequest
2
- import can
3
- import cantools
4
- import time
5
- import os
6
- import pandas as pd
7
- import datetime
8
-
9
- # class Can():
10
- # def __init__(self, parser, cfg):
11
- # psr = parser.add_parser('can', help='Peforms a variety of CAN commands')
12
- # sps = psr.add_subparsers(required= True, help='sub-command of NPC')
13
- # SendCan(sps, dbc)
14
- # #TestCanRates(sps, cfg)
15
- # LogCan(sps, dbc)
16
-
17
-
18
- # class SendCan(AvrsApiRequest):
19
- # def __init__(self, parser, dbc):
20
- # psr = parser.add_parser('send', help='sends CAN data for given duration (seconds) with given throttle and steer percent values')
21
- # psr.add_argument('duration', type=float, help='Length of time to send Can data')
22
- # psr.add_argument('hertz', type=float, help = 'Frequency of Can Messages')
23
- # psr.add_argument('throttle', type=float, help='throttle (in percent)')
24
- # psr.add_argument('steer', type=float, help='steer (in percent)')
25
- # self.dbc = dbc
26
- # psr.set_defaults(func=self.send_can_values)
27
-
28
-
29
- # def send_can_values(self, args):
30
- # with can.interface.Bus('vcan0', bustype='socketcan') as bus:
31
- # message_1 = self.dbc.get_message_by_name("HL_Msg_01")
32
- # message_2 = self.dbc.get_message_by_name("HL_Msg_02")
33
- # signals_1 = {
34
- # "HL_TargetThrottle": args.throttle,
35
- # "HL_TargetGear": 1,
36
- # "HL_TargetPressure_RR": 0,
37
- # "HL_TargetPressure_RL": 0,
38
- # "HL_TargetPressure_FR": 0,
39
- # "HL_TargetPressure_FL": 0,
40
- # "HL_Alive_01": 0,
41
- # }
42
-
43
- # signals_2 = {
44
- # "HL_Alive_02": 0,
45
- # "HL_PSA_Profile_Vel_rad_s": 0,
46
- # "HL_PSA_Profile_Dec_rad_s2": 0,
47
- # "HL_PSA_Profile_Acc_rad_s2": 0,
48
- # "HL_TargetPSAControl": args.steer,
49
- # "HL_PSA_ModeOfOperation": 0,
50
- # }
51
-
52
- # start_time = time.time()
53
-
54
- # print('sending can data...')
55
- # while time.time() - start_time < args.duration:
56
- # data = message_1.encode(signals_1)
57
- # msg = can.Message(arbitration_id=message_1.frame_id, data=data, is_extended_id=False)
58
- # bus.send(msg)
59
-
60
- # data = message_2.encode(signals_2)
61
- # msg = can.Message(arbitration_id=message_2.frame_id, data=data, is_extended_id=False)
62
- # bus.send(msg)
63
- # time.sleep(args.hertz)
64
- # print('done')
65
-
66
-
67
- # # class TestCanRates(AvrsApiRequest):
68
- # # def __init__(self, parser, cfg):
69
- # # AvrsApiRequest.__init__(self, parser, cfg, 'TestCanRates')
70
- # # psr = parser.add_parser('test-rates', help='get average can message rates over given duration for all can messages on vcan0')
71
- # # psr.add_argument('duration', type=float, help='Length of time to test Can rates')
72
- # # psr.set_defaults(func=self.send_request)
73
-
74
-
75
- # # def get_request_body(self, args):
76
- # # return {
77
- # # 'Duration': args.duration,
78
- # # }
79
-
80
- # class LogCan(AvrsApiRequest):
81
- # def __init__(self, parser, dbc):
82
- # psr = parser.add_parser('log', help='logs csv CAN data for given duration (seconds) to the given absolute file path. Will append numbers to colliding file names')
83
- # psr.add_argument('duration', type=float, help='length of time to log Can data')
84
- # psr.add_argument('path', help='absoulte file path')
85
- # psr.set_defaults(func=self.log_can)
86
- # self.dbc = dbc
87
-
88
- # def log_can(self, args):
89
- # start_time = time.time()
90
-
91
- # # Check and remove the existing 'messages.csv' file
92
- # file_no = 1
93
- # tmp_file_path = args.path
94
- # print(tmp_file_path)
95
- # while os.path.exists(tmp_file_path):
96
- # tmp_file_path = args.path.replace('.csv', '{}.csv'.format(file_no))
97
- # file_no += 1
98
- # args.path = tmp_file_path
99
-
100
- # messages_list = []
101
- # databases = [self.dbc]
102
- # print('logging can data...')
103
-
104
- # with can.interface.Bus('vcan0', bustype='socketcan') as bus:
105
- # while time.time() - start_time < args.duration:
106
- # message = bus.recv()
107
- # # If a message was received
108
- # if message is not None:
109
- # for db in databases:
110
- # decoded = self.decode_message(message)
111
- # if decoded:
112
- # messages_list.append(decoded)
113
- # break
114
- # df = pd.DataFrame(messages_list)
115
- # df.to_csv(args.path, index=False)
116
- # print('done')
117
-
118
-
119
- # def decode_message(self, message):
120
- # try:
121
- # decoded_message = self.dbc.decode_message(message.arbitration_id, message.data)
122
- # message_name = self.dbc.get_message_by_frame_id(message.arbitration_id).name
123
- # timestamp = datetime.datetime.now().isoformat()
124
- # return {'timestamp': timestamp, 'name': message_name, 'data': decoded_message}
125
- # except KeyError:
126
- # # Return None if decoding fails
127
- # return None
128
-
129
-
130
-
131
-
avrs/requests/input.py DELETED
@@ -1,46 +0,0 @@
1
- from avrs.requests.request import AvrsApiRequest
2
-
3
- class InputRequest(AvrsApiRequest):
4
- def __init__(self, parser, cfg):
5
- psr = parser.add_parser('user-input', help='Commands related to controlling the vehicles with controllers')
6
- sps = psr.add_subparsers(required= True, help='sub-command of Input')
7
- EnableInput(sps, cfg)
8
- DisableInput(sps, cfg)
9
- ChangeInput(sps, cfg)
10
-
11
- class EnableInput(AvrsApiRequest):
12
- def __init__(self, parser, cfg):
13
- AvrsApiRequest.__init__(self, parser, cfg, 'EnableInput', 'Ego')
14
- psr = parser.add_parser('enable', help='Enable user input on car')
15
- psr.add_argument('controller', help='type of way to control the actor', nargs = 1,
16
- choices=('keyboard', 'xbox', 'wheel', 'can'))
17
- psr.set_defaults(func=self.send_request)
18
-
19
- def get_request_body(self, args):
20
- return {
21
- 'Controller': args.controller
22
- }
23
-
24
- class DisableInput(AvrsApiRequest):
25
- def __init__(self, parser, cfg):
26
- AvrsApiRequest.__init__(self, parser, cfg, 'DisableInput', 'Ego')
27
- psr = parser.add_parser('disable', help='disable user input on car')
28
- psr.set_defaults(func=self.send_request)
29
-
30
- def get_request_body(self, args):
31
- return {
32
- }
33
-
34
- class ChangeInput(AvrsApiRequest):
35
- def __init__(self, parser, cfg):
36
- AvrsApiRequest.__init__(self, parser, cfg, 'ChangeInput', 'Ego')
37
- psr = parser.add_parser('change', help='change the input type if input is already enabled')
38
- psr.add_argument('controller', help='type of way to control the actor', nargs = 1,
39
- choices=('keyboard', 'xbox', 'wheel'))
40
- psr.set_defaults(func=self.send_request)
41
-
42
- def get_request_body(self, args):
43
- return {
44
- 'Controller': args.controller
45
- }
46
-