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/race_cloud_util.py
ADDED
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import json
|
|
3
|
+
import http.client
|
|
4
|
+
import logging
|
|
5
|
+
from avrs.util import *
|
|
6
|
+
|
|
7
|
+
BASH_KILL_PROCESS_SCRIPT = '''
|
|
8
|
+
PROC_NAME={pname}
|
|
9
|
+
I=0
|
|
10
|
+
TRIES=20
|
|
11
|
+
while [ $I -le $TRIES ]; do
|
|
12
|
+
|
|
13
|
+
pkill $PROC_NAME
|
|
14
|
+
PROC_RUNNING=$(ps -A | grep $PROC_NAME)
|
|
15
|
+
if [[ ! -z $PROC_RUNNING ]]; then
|
|
16
|
+
echo process $PROC_NAME is still running
|
|
17
|
+
if [ $I == $(( TRIES - 1 )) ]; then
|
|
18
|
+
echo process is resisting. crushing its dreams with sigkill
|
|
19
|
+
pkill -SIGKILL $PROC_NAME
|
|
20
|
+
fi
|
|
21
|
+
else
|
|
22
|
+
echo process $PROC_NAME is not running
|
|
23
|
+
break
|
|
24
|
+
fi
|
|
25
|
+
I=$(( I + 1 ))
|
|
26
|
+
sleep 1
|
|
27
|
+
done
|
|
28
|
+
'''
|
|
29
|
+
|
|
30
|
+
BASH_KILL_BY_LAUNCH_SCRIPT = '''
|
|
31
|
+
ps -x | grep "{launch_phrase}" | awk '{{ print $1 }}' | xargs -L1 kill
|
|
32
|
+
'''
|
|
33
|
+
|
|
34
|
+
DEFAULT_RMW_QOS = '''
|
|
35
|
+
<?xml version="1.0" encoding="UTF-8" ?>
|
|
36
|
+
<profiles xmlns="http://www.eprosima.com/XMLSchemas/fastRTPS_Profiles">
|
|
37
|
+
<transport_descriptors>
|
|
38
|
+
<transport_descriptor>
|
|
39
|
+
<transport_id>morepeers</transport_id> <!-- string -->
|
|
40
|
+
<type>UDPv4</type> <!-- string -->
|
|
41
|
+
<maxInitialPeersRange>100</maxInitialPeersRange> <!-- uint32 -->
|
|
42
|
+
</transport_descriptor>
|
|
43
|
+
</transport_descriptors>
|
|
44
|
+
<participant profile_name="participant_profile_ros2" is_default_profile="true">
|
|
45
|
+
<rtps>
|
|
46
|
+
<builtin>
|
|
47
|
+
<metatrafficUnicastLocatorList>
|
|
48
|
+
<locator/>
|
|
49
|
+
</metatrafficUnicastLocatorList>
|
|
50
|
+
<initialPeersList>
|
|
51
|
+
<locator> <udpv4> <address>127.0.0.1</address> </udpv4> </locator>
|
|
52
|
+
<!--<locator> <udpv4> <address>PEER_0</address> </udpv4> </locator>PEER0-->
|
|
53
|
+
<!--<locator> <udpv4> <address>PEER_1</address> </udpv4> </locator>PEER1-->
|
|
54
|
+
<!--<locator> <udpv4> <address>PEER_2</address> </udpv4> </locator>PEER2-->
|
|
55
|
+
<!--<locator> <udpv4> <address>PEER_3</address> </udpv4> </locator>PEER3-->
|
|
56
|
+
<!--<locator> <udpv4> <address>PEER_4</address> </udpv4> </locator>PEER4-->
|
|
57
|
+
<!--<locator> <udpv4> <address>PEER_5</address> </udpv4> </locator>PEER5-->
|
|
58
|
+
<!--<locator> <udpv4> <address>PEER_6</address> </udpv4> </locator>PEER6-->
|
|
59
|
+
<!--<locator> <udpv4> <address>PEER_7</address> </udpv4> </locator>PEER7-->
|
|
60
|
+
<!--<locator> <udpv4> <address>PEER_8</address> </udpv4> </locator>PEER8-->
|
|
61
|
+
<!--<locator> <udpv4> <address>PEER_9</address> </udpv4> </locator>PEER9-->
|
|
62
|
+
<!--<locator> <udpv4> <address>PEER_10</address> </udpv4> </locator>PEER10-->
|
|
63
|
+
<!--<locator> <udpv4> <address>PEER_11</address> </udpv4> </locator>PEER11-->
|
|
64
|
+
<!--<locator> <udpv4> <address>PEER_12</address> </udpv4> </locator>PEER12-->
|
|
65
|
+
</initialPeersList>
|
|
66
|
+
</builtin>
|
|
67
|
+
<userTransports>
|
|
68
|
+
<transport_id>morepeers</transport_id>
|
|
69
|
+
</userTransports>
|
|
70
|
+
<useBuiltinTransports>false</useBuiltinTransports>
|
|
71
|
+
</rtps>
|
|
72
|
+
</participant>
|
|
73
|
+
</profiles>
|
|
74
|
+
'''
|
|
75
|
+
|
|
76
|
+
DEFAULT_RMW_CYCLONE = '''
|
|
77
|
+
<?xml version="1.0" encoding="UTF-8" ?>
|
|
78
|
+
<CycloneDDS>
|
|
79
|
+
<Domain id="any">
|
|
80
|
+
<Discovery>
|
|
81
|
+
<ParticipantIndex>auto</ParticipantIndex>
|
|
82
|
+
<Peers>
|
|
83
|
+
<Peer address='127.0.0.1'/>
|
|
84
|
+
<!--<Peer address='PEER_0'/>PEER0-->
|
|
85
|
+
<!--<Peer address='PEER_1'/>PEER1-->
|
|
86
|
+
<!--<Peer address='PEER_2'/>PEER2-->
|
|
87
|
+
<!--<Peer address='PEER_3'/>PEER3-->
|
|
88
|
+
<!--<Peer address='PEER_4'/>PEER4-->
|
|
89
|
+
<!--<Peer address='PEER_5'/>PEER5-->
|
|
90
|
+
<!--<Peer address='PEER_6'/>PEER6-->
|
|
91
|
+
<!--<Peer address='PEER_7'/>PEER7-->
|
|
92
|
+
<!--<Peer address='PEER_8'/>PEER8-->
|
|
93
|
+
<!--<Peer address='PEER_9'/>PEER9-->
|
|
94
|
+
<!--<Peer address='PEER_10'/>PEER10-->
|
|
95
|
+
<!--<Peer address='PEER_11'/>PEER11-->
|
|
96
|
+
<!--<Peer address='PEER_12'/>PEER12-->
|
|
97
|
+
</Peers>
|
|
98
|
+
</Discovery>
|
|
99
|
+
</Domain>
|
|
100
|
+
</CycloneDDS>
|
|
101
|
+
'''
|
|
102
|
+
|
|
103
|
+
DISABLE_PEER_QOS_SCRIPT = '''
|
|
104
|
+
QOS_FILE_PATH={qos_path}
|
|
105
|
+
CYCLONE_PATH={cyclone_path}
|
|
106
|
+
PEER_ID={peer_id}
|
|
107
|
+
|
|
108
|
+
# for the origin rmw qos file
|
|
109
|
+
sed -i -E "s,(<locator> <udpv4> <address>)(.+)(</address> </udpv4> </locator>)<!--(PEER$PEER_ID-->),<!--\\1PEER$PEER_ID\\3\\4,g" $QOS_FILE_PATH
|
|
110
|
+
|
|
111
|
+
# for the cyclone file
|
|
112
|
+
sed -i -E "s,(<Peer address=')(.+)('/>)<!--(PEER$PEER_ID-->),<!--\\1PEER$PEER_ID\\3\\4,g" $CYCLONE_PATH
|
|
113
|
+
|
|
114
|
+
VCAN_NAME=vcan$PEER_ID
|
|
115
|
+
if [[ -e $VCAN_NAME.vcanlock ]]; then
|
|
116
|
+
echo "stopping existing cannelloni connection with pid $(cat $VCAN_NAME.vcanlock)"
|
|
117
|
+
kill $(cat $VCAN_NAME.vcanlock)
|
|
118
|
+
rm $VCAN_NAME.vcanlock
|
|
119
|
+
fi
|
|
120
|
+
'''
|
|
121
|
+
|
|
122
|
+
ENABLE_PEER_QOS_SCRIPT = '''
|
|
123
|
+
QOS_FILE_PATH={qos_path}
|
|
124
|
+
CYCLONE_PATH={cyclone_path}
|
|
125
|
+
PEER_ID={peer_id}
|
|
126
|
+
PEER_ADDRESS={peer_ip}
|
|
127
|
+
|
|
128
|
+
# for the origin rmw qos file
|
|
129
|
+
sed -i -E "s,(<!--?)(<locator> <udpv4> <address>)(.+)(</address> </udpv4> </locator>)(PEER$PEER_ID-->),\\2$PEER_ADDRESS\\4<!--\\5,g" $QOS_FILE_PATH
|
|
130
|
+
|
|
131
|
+
# for the cyclone file
|
|
132
|
+
sed -i -E "s,(<!--?)(<Peer address=')(.+)('/>)(PEER$PEER_ID-->),\\2$PEER_ADDRESS\\4<!--\\5,g" $CYCLONE_PATH
|
|
133
|
+
'''
|
|
134
|
+
|
|
135
|
+
CONNECT_PEER_VCAN_SCRIPT = '''
|
|
136
|
+
PEER_ID={peer_id}
|
|
137
|
+
PEER_ADDRESS={peer_ip}
|
|
138
|
+
REMOTE_PORT={remote_port}
|
|
139
|
+
LOCAL_PORT={local_port}
|
|
140
|
+
VCAN_NAME={vcan_name}
|
|
141
|
+
LOCK_FILE="$HOME/.$VCAN_NAME.vcanlock"
|
|
142
|
+
LOG_FILE="$HOME/.$VCAN_NAME.vcanlog"
|
|
143
|
+
if [[ -z $VCAN_NAME ]]; then
|
|
144
|
+
VCAN_NAME=vcan$PEER_ID
|
|
145
|
+
fi
|
|
146
|
+
echo "connecting peer id $PEER_ID using local port $LOCAL_PORT and remote port $REMOTE_PORT and vcan name $VCAN_NAME" > "$LOG_FILE" 2>&1
|
|
147
|
+
|
|
148
|
+
if [[ -e $LOCK_FILE ]]; then
|
|
149
|
+
echo "stopping existing can_bridge connection with pid $(cat $LOCK_FILE)"
|
|
150
|
+
kill $(cat $LOCK_FILE)
|
|
151
|
+
fi
|
|
152
|
+
|
|
153
|
+
# https://stackoverflow.com/questions/29142/getting-ssh-to-execute-a-command-in-the-background-on-target-machine
|
|
154
|
+
# nohup to avoid SSH issues, send stdout to loni.log, send stderr to stdout, dont expect input, and background with "&"
|
|
155
|
+
nohup avrs race-cloud bridge-can fg $VCAN_NAME $PEER_ADDRESS $REMOTE_PORT $LOCAL_PORT >>"$LOG_FILE" 2>&1 < /dev/null &
|
|
156
|
+
echo "$!" > $LOCK_FILE
|
|
157
|
+
'''
|
|
158
|
+
|
|
159
|
+
CHECK_VCAN_EXISTS_SCRIPT = '''
|
|
160
|
+
if [[ -z $(ip addr show | grep {vcan_name}) ]]; then
|
|
161
|
+
echo -n "no"
|
|
162
|
+
else
|
|
163
|
+
echo -n "yes"
|
|
164
|
+
fi
|
|
165
|
+
'''
|
|
166
|
+
|
|
167
|
+
CREATE_VCANS_SCRIPT = '''
|
|
168
|
+
sudo modprobe vcan
|
|
169
|
+
sudo ip link add name "{a}" type vcan
|
|
170
|
+
sudo ip link set dev "{a}" up
|
|
171
|
+
sudo ip link add name "{b}" type vcan
|
|
172
|
+
sudo ip link set dev "{b}" up
|
|
173
|
+
sudo ip link add name "{c}" type vcan
|
|
174
|
+
sudo ip link set dev "{c}" up
|
|
175
|
+
'''
|
|
176
|
+
|
|
177
|
+
START_FWD_API_SCRIPT = '''
|
|
178
|
+
nohup avrs race-cloud fwd-api fg {source_port} {target_port} >> ~/fwd_api.log 2>&1 < /dev/null &
|
|
179
|
+
echo "$!" > ~/fwd_api_pid
|
|
180
|
+
'''
|
|
181
|
+
|
|
182
|
+
STOP_FWD_API_SCRIPT = '''
|
|
183
|
+
if [[ -e ~/fwd_api_pid ]]; then
|
|
184
|
+
kill $(cat ~/fwd_api_pid)
|
|
185
|
+
fi
|
|
186
|
+
rm ~/fwd_api_pid
|
|
187
|
+
'''
|
|
188
|
+
|
|
189
|
+
GET_EC2_LOCAL_IP_SCRIPT = '''
|
|
190
|
+
echo -n $(ec2metadata --local-ipv4)
|
|
191
|
+
'''
|
|
192
|
+
|
|
193
|
+
# kill a process with a given name
|
|
194
|
+
def bash_kill_process(pname):
|
|
195
|
+
return run_process(['bash', '-c',
|
|
196
|
+
BASH_KILL_PROCESS_SCRIPT.format(**{'pname': pname})])
|
|
197
|
+
|
|
198
|
+
def bash_kill_process_by_launch_command(launch_command):
|
|
199
|
+
return run_process(['bash', '-c',
|
|
200
|
+
BASH_KILL_BY_LAUNCH_SCRIPT.format(**{'launch_phrase': launch_command})])
|
|
201
|
+
|
|
202
|
+
# start an exectuable in the background, sending output to a file
|
|
203
|
+
# stored at root with its name
|
|
204
|
+
def start_exe(exe_path):
|
|
205
|
+
logger = logging.getLogger('avrs')
|
|
206
|
+
logger.info('running {} and saving under {}'.format(exe_path, os.path.basename(exe_path).replace(' ', '')))
|
|
207
|
+
return run_process(['bash', '-c',
|
|
208
|
+
'nohup {} > ~/{}_output.log 2>&1 < /dev/null &'.format(exe_path, os.path.basename(exe_path).replace(' ', ''))])
|
|
209
|
+
|
|
210
|
+
def get_sim_install_path():
|
|
211
|
+
sim_path = os.environ.get('AVRS_INSTALL_PATH',
|
|
212
|
+
os.path.join(os.environ['HOME'], 'autoverse-linux'))
|
|
213
|
+
return sim_path
|
|
214
|
+
|
|
215
|
+
def get_sim_exe_path():
|
|
216
|
+
exe_path = os.environ.get('AVRS_EXE_PATH',
|
|
217
|
+
os.path.join(os.environ['HOME'], 'autoverse-linux', 'Linux', 'utils', 'run_autoverse.sh'))
|
|
218
|
+
return exe_path
|
|
219
|
+
|
|
220
|
+
def get_rmw_qos_path():
|
|
221
|
+
return os.path.join(os.environ['HOME'], '.rmw_qos.xml')
|
|
222
|
+
|
|
223
|
+
def get_rmw_cyclone_qos_path():
|
|
224
|
+
return os.path.join(os.environ['HOME'], '.cyclone.xml')
|
|
225
|
+
|
|
226
|
+
def reset_rmw_qos():
|
|
227
|
+
with open(get_rmw_qos_path(), 'w', encoding='utf-8') as f:
|
|
228
|
+
f.write(DEFAULT_RMW_QOS)
|
|
229
|
+
|
|
230
|
+
def reset_rmw_cyclone_qos():
|
|
231
|
+
with open(get_rmw_cyclone_qos_path(), 'w', encoding='utf-8') as f:
|
|
232
|
+
f.write(DEFAULT_RMW_CYCLONE)
|
|
233
|
+
|
|
234
|
+
def disable_peer_qos(peer_id):
|
|
235
|
+
if not os.path.isfile(get_rmw_qos_path()):
|
|
236
|
+
reset_rmw_qos()
|
|
237
|
+
if not os.path.isfile(get_rmw_cyclone_qos_path()):
|
|
238
|
+
reset_rmw_cyclone_qos()
|
|
239
|
+
pargs = {
|
|
240
|
+
'qos_path': get_rmw_qos_path(),
|
|
241
|
+
'cyclone_path': get_rmw_cyclone_qos_path(),
|
|
242
|
+
'peer_id': peer_id
|
|
243
|
+
}
|
|
244
|
+
return run_process(['bash', '-c',
|
|
245
|
+
DISABLE_PEER_QOS_SCRIPT.format(**pargs)])
|
|
246
|
+
|
|
247
|
+
def enable_peer_qos(peer_id, peer_ip):
|
|
248
|
+
disable_peer_qos(peer_ip) # disable first
|
|
249
|
+
pargs = {
|
|
250
|
+
'qos_path': get_rmw_qos_path(),
|
|
251
|
+
'cyclone_path': get_rmw_cyclone_qos_path(),
|
|
252
|
+
'peer_id': peer_id,
|
|
253
|
+
'peer_ip': peer_ip
|
|
254
|
+
}
|
|
255
|
+
return run_process(['bash', '-c',
|
|
256
|
+
ENABLE_PEER_QOS_SCRIPT.format(**pargs)])
|
|
257
|
+
|
|
258
|
+
def check_vcan_exists(vcan_name):
|
|
259
|
+
pargs = {
|
|
260
|
+
'vcan_name': vcan_name
|
|
261
|
+
}
|
|
262
|
+
pres = run_process(['bash', '-c',
|
|
263
|
+
CHECK_VCAN_EXISTS_SCRIPT.format(**pargs)])
|
|
264
|
+
return pres.out == 'yes'
|
|
265
|
+
|
|
266
|
+
def setup_vcans(vcan0, vcan1, vcan2):
|
|
267
|
+
pargs = {
|
|
268
|
+
'a': vcan0,
|
|
269
|
+
'b': vcan1,
|
|
270
|
+
'c': vcan2
|
|
271
|
+
}
|
|
272
|
+
pres = run_process(['bash', '-c',
|
|
273
|
+
CREATE_VCANS_SCRIPT.format(**pargs)])
|
|
274
|
+
return pres.out + ' ' + pres.err
|
|
275
|
+
|
|
276
|
+
def start_fwd_api(source_port, target_port):
|
|
277
|
+
pargs = {
|
|
278
|
+
'source_port': source_port,
|
|
279
|
+
'target_port': target_port
|
|
280
|
+
}
|
|
281
|
+
pres = run_process(['bash', '-c', START_FWD_API_SCRIPT.format(**pargs)])
|
|
282
|
+
return pres.out
|
|
283
|
+
|
|
284
|
+
def stop_fwd_api():
|
|
285
|
+
pres = run_process(['bash', '-c', STOP_FWD_API_SCRIPT])
|
|
286
|
+
return pres.out
|
|
287
|
+
|
|
288
|
+
def start_can_bridge(args):
|
|
289
|
+
pargs = {
|
|
290
|
+
'peer_ip': args.peer_ip,
|
|
291
|
+
'peer_port': args.peer_port,
|
|
292
|
+
'local_port': args.local_port
|
|
293
|
+
}
|
|
294
|
+
pres = run_process(['bash', 'c', START_CAN_BRIDGE_SCRIPT.format(**pargs)])
|
|
295
|
+
return pres.out
|
|
296
|
+
|
|
297
|
+
def stop_can_brdige():
|
|
298
|
+
pres = run_process(['bash'], '-c', STOP_CAN_BRIDGE_SCRIPT)
|
|
299
|
+
return pres.out
|
|
300
|
+
|
|
301
|
+
def get_auto_vcan_name(peer_id, vcan_id):
|
|
302
|
+
return 'vcan{}_{}'.format(peer_id, vcan_id)
|
|
303
|
+
|
|
304
|
+
def connect_peer_vcan(peer_id, peer_ip, vcan_id, vcan_name=''):
|
|
305
|
+
logger = logging.getLogger('avrs')
|
|
306
|
+
pargs = {
|
|
307
|
+
'peer_id': peer_id,
|
|
308
|
+
'peer_ip': peer_ip,
|
|
309
|
+
'remote_port': 20000 + peer_id * 3 + vcan_id, # three ports per peer_id
|
|
310
|
+
'local_port': 20000 + peer_id * 3 + vcan_id,
|
|
311
|
+
'vcan_name': vcan_name if vcan_name != '' else get_auto_vcan_name(peer_id, vcan_id)
|
|
312
|
+
}
|
|
313
|
+
logger.info('connecting vcan with args: {}'.format(pargs))
|
|
314
|
+
return run_process(['bash', '-c',
|
|
315
|
+
CONNECT_PEER_VCAN_SCRIPT.format(**pargs)])
|
|
316
|
+
|
|
317
|
+
def get_local_instance_ip():
|
|
318
|
+
try:
|
|
319
|
+
pres = run_process(['bash', '-c', GET_EC2_LOCAL_IP_SCRIPT])
|
|
320
|
+
if pres.out == '':
|
|
321
|
+
return '127.0.0.1'
|
|
322
|
+
return pres.out
|
|
323
|
+
except:
|
|
324
|
+
return '127.0.0.1'
|
|
325
|
+
|
|
326
|
+
def reset_race_cloud_connection():
|
|
327
|
+
logger = logging.getLogger('avrs')
|
|
328
|
+
logger.info('resetting connection')
|
|
329
|
+
reset_rmw_qos()
|
|
330
|
+
reset_rmw_cyclone_qos()
|
|
331
|
+
logger.info('removing vcanlog and vcanlock files')
|
|
332
|
+
run_process(['bash', '-c', 'rm ~/.simslot*']) # remove slot reservations
|
|
333
|
+
run_process(['bash', '-c', 'rm ~/.*.vcanlog*']) # remove slot reservations
|
|
334
|
+
run_process(['bash', '-c', 'rm ~/.*.vcanlock']) # remove lock files
|
|
335
|
+
logger.info('stopping race-cloud bridge-can')
|
|
336
|
+
bash_kill_process_by_launch_command('avrs race-cloud bridge-can')
|
|
337
|
+
|
|
338
|
+
def try_get_open_slot(team_name, ip):
|
|
339
|
+
logger = logging.getLogger('avrs')
|
|
340
|
+
slot_file_dir = os.environ['HOME']
|
|
341
|
+
logger.info('finding a slot for team {}'.format(team_name))
|
|
342
|
+
for i in range(12):
|
|
343
|
+
slot_file_path = os.path.join(slot_file_dir, '.simslot_{}'.format(i))
|
|
344
|
+
|
|
345
|
+
if os.path.isfile(slot_file_path):
|
|
346
|
+
with open(slot_file_path, 'r', encoding='utf-8') as f:
|
|
347
|
+
content = f.read()
|
|
348
|
+
if content == ip:
|
|
349
|
+
logger.info('slot {} already reserved by team {}'.format(i, team_name))
|
|
350
|
+
return (True, 'slot {} is already reserved by you'.format(i), i)
|
|
351
|
+
else:
|
|
352
|
+
with open(slot_file_path, 'w', encoding='utf-8') as f:
|
|
353
|
+
f.write(ip)
|
|
354
|
+
logger.info('slot {} successfuly reserved by team {}'.format(i, team_name))
|
|
355
|
+
return (True, 'reserved slot {}'.format(i), i)
|
|
356
|
+
logger.info('no open slot found for team {}'.format(team_name))
|
|
357
|
+
return (False, 'no open slots', i)
|
|
358
|
+
|
|
359
|
+
def call_race_cloud_api(body):
|
|
360
|
+
logger = logging.getLogger('avrs')
|
|
361
|
+
logger.info('calling race-cloud api with body: {}'.format(body))
|
|
362
|
+
|
|
363
|
+
api_url = 'gitzels0l7.execute-api.us-east-1.amazonaws.com'
|
|
364
|
+
|
|
365
|
+
connection = http.client.HTTPSConnection(api_url)
|
|
366
|
+
headers = {
|
|
367
|
+
'Content-type': 'application/json',
|
|
368
|
+
'x-api-key': '7aQ83sJ89Q2DZ8NdIi9aUTBuUS2uyix5QoDwrl1j'
|
|
369
|
+
}
|
|
370
|
+
body = json.dumps(body).encode('utf-8')
|
|
371
|
+
connection.request('POST', '/beta/connect', body, headers)
|
|
372
|
+
response = connection.getresponse()
|
|
373
|
+
if response.status != 200:
|
|
374
|
+
return (False, 'response had status code {}'.format(response))
|
|
375
|
+
return (True, response.read().decode('utf-8'))
|
|
376
|
+
|
|
377
|
+
def get_api_script_response(raw):
|
|
378
|
+
decoded = json.loads(raw)['body']
|
|
379
|
+
logger = logging.getLogger('avrs')
|
|
380
|
+
logger.info('race cloud api response: {}'.format(decoded))
|
|
381
|
+
if decoded['script_response']['statusCode'] != 200:
|
|
382
|
+
return (False, 'inner response had bad status code {}'.format(decoded))
|
|
383
|
+
#print(decoded)
|
|
384
|
+
return (True, json.loads(decoded['script_response']['body']), decoded['sim_private_ip'])
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from avrs.requests.request import AvrsApiRequest
|
|
2
|
+
|
|
3
|
+
class AvrsChangeCameraRequest(AvrsApiRequest):
|
|
4
|
+
def __init__(self, parser, cfg):
|
|
5
|
+
AvrsApiRequest.__init__(self, parser, cfg, 'ChangeCamera', '')
|
|
6
|
+
psr = parser.add_parser('change-camera', help='changes the active camera on an object')
|
|
7
|
+
|
|
8
|
+
psr.add_argument(
|
|
9
|
+
'object_name',
|
|
10
|
+
metavar='object-name',
|
|
11
|
+
help='the specific object to change cameras on')
|
|
12
|
+
|
|
13
|
+
psr.add_argument(
|
|
14
|
+
'--activate-pixel-stream',
|
|
15
|
+
action="store_true",
|
|
16
|
+
help='if true, a pixel stream will be created for the object')
|
|
17
|
+
|
|
18
|
+
psr.set_defaults(func=self.send_request)
|
|
19
|
+
|
|
20
|
+
def get_request_body(self, args):
|
|
21
|
+
return {
|
|
22
|
+
"pixelStreamObjectId": args.object_name,
|
|
23
|
+
"bActivatePixelStream": args.activate_pixel_stream
|
|
24
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
from avrs.requests.request import AvrsApiRequest
|
|
2
|
+
from argparse import RawTextHelpFormatter
|
|
3
|
+
|
|
4
|
+
class AvrsCodeBoozRequest():
|
|
5
|
+
def __init__(self, parent_parser, cfg):
|
|
6
|
+
psr = parent_parser.add_parser(
|
|
7
|
+
'lwi',
|
|
8
|
+
help='light-weight interface logging options\n\n')
|
|
9
|
+
sps = psr.add_subparsers(required=True, help='light-wieght interface logging options')
|
|
10
|
+
|
|
11
|
+
AvrsCodeBoozStartLogging(sps, cfg)
|
|
12
|
+
AvrsCodeBoozStopLogging(sps, cfg)
|
|
13
|
+
AvrsCodeBoozGetTimes(sps, cfg)
|
|
14
|
+
|
|
15
|
+
class AvrsCodeBoozStartLogging(AvrsApiRequest):
|
|
16
|
+
def __init__(self, parser, cfg):
|
|
17
|
+
AvrsApiRequest.__init__(self, parser, cfg, 'CodeBoozLog', 'Ego')
|
|
18
|
+
psr = parser.add_parser(
|
|
19
|
+
'start-log', help='starts logging', formatter_class=RawTextHelpFormatter)
|
|
20
|
+
|
|
21
|
+
psr.add_argument(
|
|
22
|
+
'out_file',
|
|
23
|
+
help='the name of the log file to create (within the \"Saved\" directory)')
|
|
24
|
+
|
|
25
|
+
psr.add_argument(
|
|
26
|
+
'--format', choices=('binary', 'csv'), default='binary', help='the format to save logged data')
|
|
27
|
+
|
|
28
|
+
psr.add_argument(
|
|
29
|
+
'--rate-hz', type=float, default=100.0, help='the rate in hz to log data')
|
|
30
|
+
|
|
31
|
+
psr.add_argument(
|
|
32
|
+
'--csv-only-xyv', action='store_true', help='if true, will only record the x, y and velocity magnitude to csv')
|
|
33
|
+
|
|
34
|
+
psr.set_defaults(func=self.send_request)
|
|
35
|
+
|
|
36
|
+
def get_request_body(self, args):
|
|
37
|
+
return {
|
|
38
|
+
'Action': 'Start',
|
|
39
|
+
'FileName': args.out_file,
|
|
40
|
+
'RateHz': args.rate_hz,
|
|
41
|
+
'Format': args.format,
|
|
42
|
+
'bCsvOnlyXyv': args.csv_only_xyv
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
class AvrsCodeBoozStopLogging(AvrsApiRequest):
|
|
46
|
+
def __init__(self, parser, cfg):
|
|
47
|
+
AvrsApiRequest.__init__(self, parser, cfg, 'CodeBoozLog', 'Ego')
|
|
48
|
+
psr = parser.add_parser(
|
|
49
|
+
'stop-log', help='starts logging', formatter_class=RawTextHelpFormatter)
|
|
50
|
+
|
|
51
|
+
psr.set_defaults(func=self.send_request)
|
|
52
|
+
|
|
53
|
+
def get_request_body(self, args):
|
|
54
|
+
return {
|
|
55
|
+
'Action': 'Stop'
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
class AvrsCodeBoozGetTimes(AvrsApiRequest):
|
|
59
|
+
def __init__(self, parser, cfg):
|
|
60
|
+
AvrsApiRequest.__init__(self, parser, cfg, 'CodeBoozLog', 'Ego')
|
|
61
|
+
psr = parser.add_parser(
|
|
62
|
+
'get-times', help='starts logging', formatter_class=RawTextHelpFormatter)
|
|
63
|
+
|
|
64
|
+
psr.set_defaults(func=self.send_request)
|
|
65
|
+
|
|
66
|
+
def get_request_body(self, args):
|
|
67
|
+
return {
|
|
68
|
+
'Action': 'GetTimes'
|
|
69
|
+
}
|
avrs/requests/demo.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from avrs.requests.request import AvrsApiRequest
|
|
2
|
+
|
|
3
|
+
class AvrsDemoRequest(AvrsApiRequest):
|
|
4
|
+
def __init__(self, parser, cfg):
|
|
5
|
+
AvrsApiRequest.__init__(self, parser, cfg, 'DemoSendConfig', '')
|
|
6
|
+
psr = parser.add_parser('demo', help='Sends a request used for a demonstration')
|
|
7
|
+
psr.add_argument('--ego-type-index', type=int, default=0, help='')
|
|
8
|
+
psr.add_argument('--npc-density', type=int)
|
|
9
|
+
psr.add_argument('--env-type-index', default=0, type=int)
|
|
10
|
+
psr.add_argument('--weather-type-index', default=0, type=int)
|
|
11
|
+
psr.set_defaults(func=self.send_request)
|
|
12
|
+
|
|
13
|
+
def get_request_body(self, args):
|
|
14
|
+
return {
|
|
15
|
+
'IndexEgoType': args.ego_type_index,
|
|
16
|
+
'NpcDensity': args.npc_density,
|
|
17
|
+
'IndexEnvironmentType': args.env_type_index,
|
|
18
|
+
'indexWeatherType': args.weather_type_index
|
|
19
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from avrs.requests.request import AvrsApiRequest
|
|
2
|
+
|
|
3
|
+
class AvrsDumpSimConfigRequest(AvrsApiRequest):
|
|
4
|
+
def __init__(self, parser, cfg):
|
|
5
|
+
AvrsApiRequest.__init__(self, parser, cfg, 'DumpSimConfig', '')
|
|
6
|
+
psr = parser.add_parser(
|
|
7
|
+
'dump-sim-config',
|
|
8
|
+
help='dump all currently loaded configuration from the simulation')
|
|
9
|
+
|
|
10
|
+
psr.set_defaults(func=self.send_request)
|
|
11
|
+
|
|
12
|
+
def get_request_body(self, args):
|
|
13
|
+
return {
|
|
14
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
from avrs.requests.request import AvrsApiRequest
|
|
2
|
+
|
|
3
|
+
class AvrsEnvironmentRequests():
|
|
4
|
+
def __init__(self, parser, cfg):
|
|
5
|
+
psr = parser.add_parser('environment', help='Edits the environment')
|
|
6
|
+
sps = psr.add_subparsers(required= True, help='')
|
|
7
|
+
AvrsSetTimeOfDayRequest(sps, cfg)
|
|
8
|
+
AvrsGetEnvironmentMetaRequest(sps, cfg)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class AvrsSetTimeOfDayRequest(AvrsApiRequest):
|
|
12
|
+
def __init__(self, parser, cfg):
|
|
13
|
+
AvrsApiRequest.__init__(self, parser, cfg, 'SetTimeOfDay', '')
|
|
14
|
+
psr = parser.add_parser('set-time-of-day', help='sets the current time of day')
|
|
15
|
+
psr.add_argument('tod', type=float, help='The time of day (0-24) to set')
|
|
16
|
+
psr.set_defaults(func=self.send_request)
|
|
17
|
+
|
|
18
|
+
def get_request_body(self, args):
|
|
19
|
+
self.target_object_id = ''
|
|
20
|
+
return {
|
|
21
|
+
'TimeOfDay': args.tod
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
class AvrsGetEnvironmentMetaRequest(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
|
+
}
|
|
34
|
+
|
|
35
|
+
class AvrsSetEnvironmentRequest(AvrsApiRequest):
|
|
36
|
+
def __init__(self, parser, cfg):
|
|
37
|
+
AvrsApiRequest.__init__(self, parser, cfg, 'SetEnvironment', '')
|
|
38
|
+
psr = parser.add_parser('set-environment', help='changes to a new environment')
|
|
39
|
+
psr.add_argument('new_environment_name', help='name of desired environment')
|
|
40
|
+
psr.set_defaults(func=self.send_request)
|
|
41
|
+
|
|
42
|
+
def get_request_body(self, args):
|
|
43
|
+
self.target_object_id = ''
|
|
44
|
+
return {
|
|
45
|
+
'newEnvironmentName': args.new_environment_name
|
|
46
|
+
}
|