-
Notifications
You must be signed in to change notification settings - Fork 125
/
Copy pathcarma
executable file
·615 lines (529 loc) · 24.4 KB
/
carma
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
#!/bin/bash
# Copyright (C) 2018-2022 LEIDOS.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
# Code below largely based on template from Stack Overflow:
# https://stackoverflow.com/questions/37257551/defining-subcommands-that-take-arguments-in-bash
# Question asked by user
# DiogoSaraiva (https://stackoverflow.com/users/4465820/diogosaraiva)
# and answered by user
# Charles Duffy (https://stackoverflow.com/users/14122/charles-duffy)
# Attribution here is in line with Stack Overflow's Attribution policy cc-by-sa found here:
# https://stackoverflow.blog/2009/06/25/attribution-required/
__pull_newest_carma_base() {
if [ "$1" = "-d" ]; then
local remote_image=$(wget -q https://registry.hub.docker.com/v1/repositories/usdotfhwastoldev/carma-base/tags -O - | \
sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n' | \
awk -F: '{print "usdotfhwastoldev/carma-base:"$3}' | tail -n 1)
elif [ "$1" = "-c" ]; then
local remote_image=$(wget -q https://registry.hub.docker.com/v1/repositories/usdotfhwastolcandidate/carma-base/tags -O - | \
sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n' | \
awk -F: '{print "usdotfhwastolcandidate/carma-base:"$3}' | tail -n 1)
else
local remote_image=$(wget -q https://registry.hub.docker.com/v1/repositories/usdotfhwastol/carma-base/tags -O - | \
sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n' | \
awk -F: '{print "usdotfhwastol/carma-base:"$3}' | tail -n 1)
fi
echo "No local carma-base image found, pulling down the most recent from Dockerhub..."
docker pull $remote_image
}
##
# Helper function to print to stderr.
# This is useful for allowing bash methods to return strings while still communicating information to the user
##
echoerr() { echo "$@" 1>&2; }
##
# Method returns a fully specified docker image name and tag based on the currently set carma-config.
# The method will return the first tag that appears in the config for the possible organizations and images.
# If the config is not set or an image cannot be found the method will return a carma-base image as the default.
# The user can specify optional organizations or images as sed compatable regex lists.
# For example calling
# $(__get_image_from_config 'carma-platform:\|carma-messenger:' 'usdotfhwastol\|usdotfhwastoldev\|usdotfhwastolcandidate')
#
# If no parameters are provided the defaults will be used
##
__get_image_from_config() {
local TARGET_IMAGE="usdotfhwastol/carma-base:latest"
local SUPPORTED_ORANIZATIONS="usdotfhwastol\|usdotfhwastoldev\|usdotfhwastolcandidate"
local SUPPORTED_IMAGES="carma-platform:\|carma-messenger:"
if [ -n "$1" ]
then
local SUPPORTED_IMAGES="$1"
fi
if [ -n "$2" ]
then
local SUPPORTED_ORANIZATIONS="$2"
fi
# Check if carma-config is set. If so, use what was in the carma config
if docker container inspect carma-config > /dev/null 2>&1; then
local IMAGE_BACKUP=$TARGET_IMAGE
# sed command finds the first instance of an image which is part of the set defined in SUPPORTED_ORGANIZATIONS and SUPPORTED_IMAGES.
# then returns the name of the image.
local TARGET_IMAGE=$(docker run --rm --volumes-from carma-config:ro --entrypoint sh busybox:latest -c \
"sed -n -e '/image:\s*\($SUPPORTED_ORANIZATIONS\)\/\($SUPPORTED_IMAGES\)/ s/.*\image: *//p' /opt/carma/vehicle/config/docker-compose.yml | grep -m 1 '.*'")
# If the sed resulted in an empty string then reset the tag
if [ -z "$TARGET_IMAGE" ]; then
local TARGET_IMAGE=$IMAGE_BACKUP
echoerr "Could not identify usable image from config so defaulting to image: $TARGET_IMAGE"
fi
else
echoerr "No config detected or target image specified so using default: $TARGET_IMAGE"
fi
echo "$TARGET_IMAGE"
}
__get_most_recent_carma_base() {
if [ "$1" = "-d" ]; then
local USERNAME=usdotfhwastoldev
elif [ "$1" = "-c" ]; then
local USERNAME=usdotfhwastolcandidate
else
local USERNAME=usdotfhwastol
fi
docker image ls --format "{{.Repository}}:{{.Tag}}" "$USERNAME/carma-base" | grep -v "<none>$" | head -n 1
}
carma-config__set() {
if [ "$1" = "-d" ]; then
local USERNAME=usdotfhwastoldev
elif [ "$1" = "-c" ]; then
local USERNAME=usdotfhwastolcandidate
else
local USERNAME=usdotfhwastol
fi
if [[ -z $1 ]]; then
echo "Please specify a tag string for carma-config to set."
echo "Done."
exit 1
fi
local IMAGE_NAME="$USERNAME/carma-config:$1"
if [ ! -z "$(echo $1 | grep :)" ]; then
IMAGE_NAME=$1
fi
if docker container inspect carma-config > /dev/null 2>&1; then
echo "Clearing existing CARMA configuration instance..."
carma__stop
echo "Deleting old CARMA config..."
docker rm carma-config
fi
echo "Setting $IMAGE_NAME as current CARMA configuration instance..."
docker run --name carma-config "$IMAGE_NAME"
}
carma__attach() {
local CARMA_DOCKER_FILE="`docker run --rm --volumes-from carma-config:ro --entrypoint sh busybox:latest -c 'cat /opt/carma/vehicle/config/docker-compose.yml'`"
echo "Attaching to CARMA container STDOUT..."
echo "$CARMA_DOCKER_FILE" | docker-compose -p carma -f - logs --follow --tail=10
}
carma-config__edit() {
if ! docker container inspect carma-config > /dev/null 2>&1; then
echo "No existing CARMA configuration found, nothing to edit. Please set a config."
echo "Done."
exit 1
fi
echo "Opening shell inside carma-config container with read/write privileges..."
local carma_base=$(__get_image_from_config carma-base:)
if [[ -z $carma_base ]]; then
__pull_newest_carma_base
carma_base=$(__get_most_recent_carma_base)
fi
docker run -it --rm --volumes-from carma-config $carma_base bash
}
carma-config__inspect() {
if ! docker container inspect carma-config > /dev/null 2>&1; then
echo "No existing CARMA configuration found, nothing to inspect. Please set a config."
echo "Done."
exit 1
fi
echo "Opening shell inside carma-config container with read-only privileges..."
local carma_base=$(__get_most_recent_carma_base)
if [[ -z $carma_base ]]; then
__pull_newest_carma_base
carma_base=$(__get_most_recent_carma_base)
fi
docker run -it --rm --volumes-from carma-config:ro $carma_base bash
}
carma-config__reset() {
if ! docker container inspect carma-config > /dev/null 2>&1; then
echo "No existing CARMA configuration found, nothing to reset. Please set a config."
echo "Done."
exit 1
fi
local CURRENT_IMAGE=`docker container inspect --format='{{.Config.Image}}' carma-config`
echo "Found current config: $CURRENT_IMAGE, resetting to base state"
carma-config__set $CURRENT_IMAGE
}
carma-config__list_local() {
echo "Locally installed images: "
echo ""
echo "usdotfhwastol images:"
docker images usdotfhwastol/carma-config
echo ""
echo "usdotfhwastoldev images:"
docker images usdotfhwastoldev/carma-config
echo ""
echo "usdotfhwastolcandidate images:"
docker images usdotfwhastolcandidate/carma-config
}
carma-config__list_remote() {
if [ "$1" = "-d" ]; then
wget -q https://registry.hub.docker.com/v1/repositories/usdotfhwastoldev/carma-config/tags -O - | \
sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n' | \
awk -F: 'BEGIN {print "Remotely available images from usdotfhwastoldev Dockerhub:\nIMAGE\t\t\t\tTAG"} {print "usdotfhwastoldev/carma-config\t"$3}'
elif [ "$1" = "-c" ]; then
wget -q https://registry.hub.docker.com/v1/repositories/usdotfhwastolcandidate/carma-config/tags -O - | \
sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n' | \
awk -F: 'BEGIN {print "Remotely available images from usdotfhwastolcandidate Dockerhub:\nIMAGE\t\t\t\tTAG"} {print "usdotfhwastolcandidate/carma-config\t"$3}'
else
wget -q https://registry.hub.docker.com/v1/repositories/usdotfhwastol/carma-config/tags -O - | \
sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n' | \
awk -F: 'BEGIN {print "Remotely available images from usdotfhwastol Dockerhub:\nIMAGE\t\t\t\tTAG"} {print "usdotfhwastol/carma-config\t"$3}'
fi
}
carma-config__install() {
if [ "$1" = "-d" ]; then
local USERNAME=usdotfhwastoldev
shift
elif [ "$1" = "-c" ]; then
local USERNAME=usdotfhwastolcandidate
shift
else
local USERNAME=usdotfhwastol
fi
local IMAGE_NAME="$USERNAME/carma-config:$1"
if [ ! -z "$(echo $1 | grep :)" ]; then
IMAGE_NAME=$1
fi
echo "Downloading $IMAGE_NAME..."
docker pull $IMAGE_NAME
echo "Building temporary container of $IMAGE_NAME to read dependency data..."
if docker container inspect carma-config-tmp > /dev/null 2>&1; then
echo "Cleaning up temporary containers from previous install..."
docker rm carma-config-tmp
fi
docker run --name carma-config-tmp $IMAGE_NAME
local CARMA_DOCKER_FILE="`docker run --rm --volumes-from carma-config-tmp:ro --entrypoint sh busybox:latest -c 'cat /opt/carma/vehicle/config/docker-compose.yml' | sed s/carma-config/carma-config-tmp/g`"
local CARMA_BACKGROUND_DOCKER_FILE="`docker run --rm --volumes-from carma-config-tmp:ro --entrypoint sh busybox:latest -c 'cat /opt/carma/vehicle/config/docker-compose-background.yml' | sed s/carma-config/carma-config-tmp/g`"
echo "Downloading $IMAGE_NAME dependencies..."
echo "$CARMA_DOCKER_FILE" | docker-compose -f - pull
echo "$CARMA_BACKGROUND_DOCKER_FILE" | docker-compose -f - pull
echo "Cleaning up temporary container..."
docker rm carma-config-tmp
}
carma__fix_bag() {
# following script finds the most recently modified .bag.active or .bag file in /opt/carma/logs directory
last_modified_file="$(find "/opt/carma/logs" -type f \( -name \*.bag.active -o -name \*.bag \) -printf "%T@ %p\0" | awk 'BEGIN {RS="\0";} {if (NR==1){minmtime=$1; $1=""; lastmodified=$0;} else if (minmtime<$1){minmtime=$1; $1=""; lastmodified=$0;}} END{print substr(lastmodified,2)}')"
if [[ ${last_modified_file} == *.bag ]]; then
printf "The last modified file is named %s\n" "${last_modified_file}"
printf "Since it is not .bag.active, there is nothing to fix. Nothing changed.\n"
elif [[ ${last_modified_file} == *.bag.active ]]; then
printf "The last modified file is named %s\n" "${last_modified_file}"
rosbag reindex ${last_modified_file}
rosbag_name="$(basename -s .bag.active ${last_modified_file})"
if test -f "/opt/carma/logs/${rosbag_name}.bag.orig.active"; then
rm "/opt/carma/logs/${rosbag_name}.bag.orig.active"
fi
mv ${last_modified_file} "/opt/carma/logs/${rosbag_name}.bag"
printf "Created a rosbag named %s\n" "/opt/carma/logs/${rosbag_name}.bag"
elif [[ ${last_modified_file} == "" ]]; then
printf "There is no .bag.active or .bag files in /opt/carma/logs directory. Nothing changed.\n"
fi
}
carma__start() {
if ! docker container inspect carma-config > /dev/null 2>&1; then
echo "No existing CARMA configuration found, nothing to start. Please set a config."
echo "Done."
exit 1
fi
echo "Starting CARMA background processes..."
docker run --rm --volumes-from carma-config:ro --entrypoint sh busybox:latest -c \
'cat /opt/carma/vehicle/config/docker-compose-background.yml' | \
docker-compose -f - -p carma-background up -d
if [ "$1" = "all" ]; then
shift
echo "Starting CARMA Platform foreground processes..."
docker run --rm --volumes-from carma-config:ro --entrypoint sh busybox:latest -c \
'cat /opt/carma/vehicle/config/docker-compose.yml' | \
docker-compose -f - -p carma up $@
elif [ ! -z "$1" ]; then
echo "Unrecognized argument \"start $1\""
fi
}
carma__stop() {
if ! docker container inspect carma-config > /dev/null 2>&1; then
echo "No existing CARMA configuration found, nothing to stop. Please set a config."
echo "Done."
exit 1
fi
echo "Shutting down CARMA processes..."
docker run --rm --volumes-from carma-config:ro --entrypoint sh busybox:latest -c \
'cat /opt/carma/vehicle/config/docker-compose.yml' | \
docker-compose -f - -p carma down
if [ "$1" = "all" ]; then
echo "Shutting down CARMA background processes..."
docker run --rm --volumes-from carma-config:ro --entrypoint sh busybox:latest -c \
'cat /opt/carma/vehicle/config/docker-compose-background.yml' | \
docker-compose -f - -p carma-background down
if [ "$2" = "fix_bag" ]; then
echo "Trying to fix the last rosbag file..."
carma__fix_bag
elif [ ! -z "$2" ]; then
echo "Unrecognized argument \"stop all $2\""
fi
elif [ "$1" = "fix_bag" ]; then
echo "Trying to fix the last rosbag file..."
carma__fix_bag
elif [ ! -z "$1" ]; then
echo "Unrecognized argument \"stop $1\""
fi
}
carma__ps() {
if ! docker container inspect carma-config > /dev/null 2>&1; then
echo "No existing CARMA configuration found, nothing to report. Please set a config."
echo "Done."
exit 1
fi
echo "CARMA Background Processes:"
docker run --rm --volumes-from carma-config:ro --entrypoint sh busybox:latest -c \
'cat /opt/carma/vehicle/config/docker-compose-background.yml' | \
docker-compose -f - -p carma-background ps
echo "CARMA Foreground Processes:"
docker run --rm --volumes-from carma-config:ro --entrypoint sh busybox:latest -c \
'cat /opt/carma/vehicle/config/docker-compose.yml' | \
docker-compose -f - -p carma ps
}
carma-config__status() {
if ! docker container inspect carma-config > /dev/null 2>&1; then
echo "No existing CARMA configuration found, nothing to report. Please set a config."
echo "Done."
exit 1
fi
if [ -z "$1" ]; then
local CURRENT_IMAGE=`docker container inspect --format='{{.Config.Image}}' carma-config`
echo "Current configuration is loaded from image: $CURRENT_IMAGE"
echo ""
echo " -- docker-compose.yml:"
docker run --rm --volumes-from carma-config:ro --entrypoint sh busybox:latest -c \
'cat /opt/carma/vehicle/config/docker-compose.yml'
echo " -- docker-compose-background.yml:"
docker run --rm --volumes-from carma-config:ro --entrypoint sh busybox:latest -c \
'cat /opt/carma/vehicle/config/docker-compose-background.yml'
echo " -- carma.launch:"
docker run --rm --volumes-from carma-config:ro --entrypoint sh busybox:latest -c \
'cat /opt/carma/vehicle/config/carma.launch'
echo " -- carma.config.js:"
docker run --rm --volumes-from carma-config:ro --entrypoint sh busybox:latest -c \
'cat /opt/carma/vehicle/config/carma.config.js'
echo " -- carma.urdf:"
docker run --rm --volumes-from carma-config:ro --entrypoint sh busybox:latest -c \
'cat /opt/carma/vehicle/config/carma.urdf'
else
docker run --rm --volumes-from carma-config:ro --entrypoint sh busybox:latest -c \
"cat /opt/carma/vehicle/config/$1"
fi
}
carma__exec() {
local USERNAME=usdotfhwastol
local TAG=latest
local TARGET_IMAGE="$USERNAME/carma-platform:$TAG"
# Check if the -i argument was provided
# If the image was specified then use that
if [ "$1" = "--gui" ]; then
local RUNTIME=nvidia
echo "setting docker runtime to $RUNTIME"
shift
fi
if [ "$1" = "-i" ]; then
if [ -z "$2" ]; then
echo " When -i is specified you must enter a carma docker image and tag."
exit 1
fi
local TARGET_IMAGE="$2"
shift
shift
# If the image was not specified try to use what was in the carma config
else
local TARGET_IMAGE=$(__get_image_from_config 'carma-platform:\|carma-messenger:')
fi
# Verify target image exists
if [ -z "$(docker images -q $TARGET_IMAGE 2> /dev/null)" ]; then
echo "Specified image could not be found. carma exec attempted to use image $TARGET_IMAGE but it was not found."
echo "If an alternative image is available, please specify it using the -i option."
exit 1
fi
# Docker setup here is based on Pierre Killy's docker-ros-box https://github.com/pierrekilly/docker-ros-box located here.
# Docker ROS Box is licensed under the MIT licesne a copy of which can be found in the carma-platform repository here https://github.com/usdot-fhwa-stol/carma-platform/blob/develop/docs/License.md
local XSOCK=/tmp/.X11-unix
local XAUTH=/tmp/.docker.xauth
touch $XAUTH
xauth nlist $DISPLAY | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge -
echo "Trying to open shell inside image: $TARGET_IMAGE"
# If a command was specified then assign it otherwise use bash
local entrypoint="/bin/bash"
local INIT_FILE="/home/carma/.base-image/init-env.sh"
if [ -n "$1" ]; then
local COMMAND="source $INIT_FILE && ${@}"
docker run \
-e DISPLAY=$DISPLAY \
--runtime=$RUNTIME \
--group-add video \
--volume=$XSOCK:$XSOCK:rw \
--volume=$XAUTH:$XAUTH:rw \
--volume=/opt/carma/logs:/opt/carma/logs \
--volume=/opt/carma/.ros:/opt/carma/.ros \
--volume=/opt/carma/vehicle/calibration:/opt/carma/vehicle/calibration \
--volume=/opt/carma/yolo:/opt/carma/yolo \
--volume=/opt/carma/maps:/opt/carma/maps \
--volume=/opt/carma/routes:/opt/carma/routes \
--env="XAUTHORITY=${XAUTH}" \
--env QT_X11_NO_MITSHM=1 \
--device=/dev/dri:/dev/dri \
--network=host \
--entrypoint="$entrypoint" \
-it $TARGET_IMAGE -c "$COMMAND"
else
docker run \
-e DISPLAY=$DISPLAY \
--group-add video \
--volume=$XSOCK:$XSOCK:rw \
--volume=$XAUTH:$XAUTH:rw \
--volume=/opt/carma/logs:/opt/carma/logs \
--volume=/opt/carma/.ros:/opt/carma/.ros \
--volume=/opt/carma/vehicle/calibration:/opt/carma/vehicle/calibration \
--volume=/opt/carma/yolo:/opt/carma/yolo \
--volume=/opt/carma/maps:/opt/carma/maps \
--volume=/opt/carma/routes:/opt/carma/routes \
--env="XAUTHORITY=${XAUTH}" \
--device=/dev/dri:/dev/dri \
--network=host \
--entrypoint="$entrypoint" \
-it $TARGET_IMAGE --init-file "$INIT_FILE"
fi
}
carma__help() {
cat <<HELP
-------------------------------------------------------------------------------
| USDOT FHWA STOL CARMA Platform |
-------------------------------------------------------------------------------
Please enter one of the following commands:
config:
status (filename)
- Report the current configuration status in total or for the
specified file
list_local
- List available usdotfhwastol configurations on the host machine
-d
- List available usdotfhwastoldev configurations on the host machine
-c
- List available usdotfhwastolcandidate configurations on the host machine
list_remote
- List available usdotfhwastol configurations on Dockerhub
-d
- List available usdotfhwastoldev configurations on Dockerhub
-c
- List available usdotfhwastolcandidate configurations on Dockerhub
install <tag/image>
- Install a configuration identified by <tag> and download
dependencies. If <tag> is bare (no :), it is assumed to be a
usdotfhwastol/carma-config tag.
-d
- tag organization is assumed to be usdotfhwastoldev
-c
- tag organization is assumed to be usdotfhwastolcandidate
set <tag/image>
- Set the configuration to the version identified by <tag>. If
<tag> is bare (no :), it is assumed to be a
usdotfhwastol/carma-config tag.
edit
- Open a shell inside the current configuration storage with r/w
permissions
inspect
- Open a shell inside the current configuration storage with r/o
permissions
-d
- uses a usdotfhwastoldev/carma-base image
-c
- uses a usdotfhwastolcandidate/carma-base image
reset
- Restore a configuration to its default state
start (all (docker-compose up args))
- Start the CARMA platform's background processes. If all, start
everything.
- Accepts the same flags as "docker-compose up"
stop (all (docker-compose down args))
- Stop the CARMA platform's foreground processes. If all, stop
everything.
- Accepts the same flags as "docker-compose down"
- fix_bag
- After stopping carma, checks if the last run's rosbag has been correctly saved. If not, fixes it to be replayable.
exec <optional bash command>
- Opens a new container with GUI support from the carma-platform or carma-messenger image with the version specified in docker compose. If no version is found it will use latest.
This container can be used to interact with CARMA using ROS tooling such as Rviz and RQT.
- If --gui argument is provided it will start docker using nvidia runtime. this flag should be provided as the first flag to work.
- If the -i <image> argument is provided then the target image will be used instead
-d
- uses a usdotfhwastoldev image
-c
- uses a usdotfwhastolcandidate image
ps
- List all running CARMA docker containers
attach
- View STDOUT from all running CARMA foreground processes
list_extensions
- List the locally available script extensions
<script extension>
- Script extensions can be added by placing a file in ~/.carma_script_extensions/ with the name of the new subcommand and no file extension.
The file should contain a matching carma__<script extension>() function to recieve the commands.
help
- Display this information"
HELP
}
carma__config() {
local cmdname=$1; shift
if type "carma-config__$cmdname" >/dev/null 2>&1; then
"carma-config__$cmdname" "$@"
else
carma__help
exit 1
fi
}
carma__list_extensions() {
# List all executable files in the extensions directory
find "${CARMA_SCRIPT_EXTENSIONS_DIR}/" -executable -type f | sed "s|${CARMA_SCRIPT_EXTENSIONS_DIR}/||"
}
carma() {
local cmdname=$1; shift
if type "carma__$cmdname" >/dev/null 2>&1; then
"carma__$cmdname" "$@"
else
carma__help
exit 1
fi
}
# if the functions above are sourced into an interactive interpreter, the user can
# just call "carma-config set" or "carma-config reset" with no further code needed.
# if invoked as a script rather than sourced, call function named on argv via the below;
# note that this must be the first operation other than a function definition
# for $_ to successfully distinguish between sourcing and invocation:
[[ $_ != $0 ]] && return
# Check if a matching script extension is available to be checked
CARMA_SCRIPT_EXTENSIONS_DIR="/home/$USER/.carma_script_extensions"
CARMA_SCRIPT_EXTENSIONS_FILE="${CARMA_SCRIPT_EXTENSIONS_DIR}/$1"
if [ -f "$CARMA_SCRIPT_EXTENSIONS_FILE" ]; then
source ${CARMA_SCRIPT_EXTENSIONS_FILE}
fi
# make sure we actually *did* get passed a valid function name
if declare -f "carma__$1" >/dev/null 2>&1; then
# invoke that function, passing arguments through
"carma__$@" # same as "$1" "$2" "$3" ... for full argument list
else
carma__help
exit 1
fi