diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a5468e6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +source_me.sh diff --git a/Dockerfile b/Dockerfile index 31e8c83..86c6b82 100644 --- a/Dockerfile +++ b/Dockerfile @@ -119,6 +119,7 @@ # X起動後にpulseaudio --start でdaemonを開始させる。 RUN apt-get update && apt-get install -y --no-install-recommends \ alsa pulseaudio libgtk2.0-0 && \ + # alsa pulseaudio && \ rm -rf /var/lib/apt/lists/* USER root @@ -139,6 +140,31 @@ libdbus-c++-1-0v5 && \ rm -rf /var/lib/apt/lists/* +# install nodejs and npm +# https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-16-04 +RUN curl -sL https://deb.nodesource.com/setup_8.x -o nodesource_setup.sh \ + && bash nodesource_setup.sh \ + && apt-get update \ + && apt-get install nodejs + +COPY control.js /simlauncher/ +COPY package.json /simlauncher/ +WORKDIR /simlauncher +RUN npm install +WORKDIR / + +RUN apt-get update && apt-get install -y --no-install-recommends \ + xdotool && \ + rm -rf /var/lib/apt/lists/* + +# setup python api +WORKDIR / +RUN git clone https://github.com/lgsvl/PythonAPI \ + && cd PythonAPI \ + && pip3 install --user -e . + +COPY test-api-move.py /api.py + # (3) Run Xorg server + x11vnc + X applications # see run.sh for details COPY run.sh /run.sh diff --git a/control.js b/control.js new file mode 100644 index 0000000..8e57963 --- /dev/null +++ b/control.js @@ -0,0 +1,52 @@ +const axios = require('axios') +const request = require('request') +const client = axios.create({ + baseURL: 'http://localhost:8082', + responseType: 'json', + withCredentials: true, +}) +const username = process.env.LG_USERNAME +const password = process.env.LG_PASSWORD + +function control_simulation (mode) { + return new Promise((resolve, reject) => { + const source = axios.CancelToken.source() + request.post({ + uri: 'https://account.lgsvlsimulator.com/users/signin', + headers: {'Content-Type': 'application/json'}, + json: { + 'username': username, + 'password': password, + } + }, (err, res, data) => { + const token = data.token + client.put(`/users/${encodeURIComponent(token)}`) + .then(res => { + const cook = res.headers['set-cookie'][0].split(';')[0] + client.request({ + method: 'post', + cancelToken: source.token, + url: mode === 'stop' ? '/simulations/5/stop' : '/simulations/5/start', + headers: { + Cookie: cook + }, + }) + .then(res => { + console.log('done', res.data) + resolve() + }) + .catch(err => { + console.log('error', err) + reject(err) + }) + }) + }) + }) +} + +control_simulation('start') + .then((res) => { console.log('kicked') }) + +module.exports = { + control_simulation, +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..8fd32f8 --- /dev/null +++ b/package.json @@ -0,0 +1,17 @@ +{ + "name": "simulator", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "axios": "^0.19.0", + "axios-cookiejar-support": "^0.5.0", + "express": "^4.17.1", + "request": "^2.88.0" + } +} diff --git a/run.sh b/run.sh index 0f3b27e..42cf007 100644 --- a/run.sh +++ b/run.sh @@ -1,4 +1,5 @@ # inside docker script +trap 'sudo kill $(jobs -p)' EXIT # 0. generate xorg.conf if not copied # [ ! -e /etc/X11/xorg.conf ] && nvidia-xconfig -a --virtual=$SCREEN_RESOLUTION --allow-empty-initial-configuration --enable-all-gpus --busid $BUSID @@ -12,7 +13,8 @@ sleep 1 # wait for the server gets ready # 2. start x11 and vnc connection -sudo x11vnc -display :0 -passwd pass -forever -rfbport 5900 --verbose & +# --verbose +sudo x11vnc -display :0 -passwd pass -forever -rfbport 5900 & sleep 2 # wait for the server gets ready # 2.5 start audio @@ -24,16 +26,52 @@ sudo /noVNC-1.1.0/utils/launch.sh --vnc localhost:5900 --listen 8081 & sleep 2 +# remove sudo group +# gpasswd -d miyazaki unyo + echo 'running noVNC at http://localhost:8081/vnc.html?host=localhost&port=8081' # 3. start simulator export DISPLAY=:0 -# ./lg/simulator -screen-height 480 -screen-width 640 -screen-quality Beautiful -screen-fullscreen 0 -# ./lg/simulator -p 8082 # # xeyes # glxgears # glxinfo # vulkan # firefox # xterm -openbox +# openbox & + +# launch lgsim and its api server +cd /lg +# ./simulator -p 8082 -screen-height 480 -screen-width 640 -screen-quality Beautiful -screen-fullscreen 0 & +./simulator -p 8082 & +sleep 3 +xdotool key Tab +xdotool key Tab +xdotool key Tab +xdotool key Tab +xdotool key Tab +xdotool key Return +sleep 3 + +# kick api mode +node /simlauncher/control.js + +# launch autoware +cd ~/Autoware +. install/setup.bash +roslaunch rosbridge_server rosbridge_websocket.launch & + +sleep 5 +# run simulation +git clone https://github.com/lgsvl/PythonAPI +cd PythonAPI +pip3 install --user -e . +python3 /api.py + +# sleep 10 +# echo 'finishing the simulation' +# echo 'uploading rosbag to S3' + +# wait +# sudo kill $(jobs -p) diff --git a/server.sh b/server.sh index 6421b99..6b93e82 100644 --- a/server.sh +++ b/server.sh @@ -1,5 +1,6 @@ #!/bin/bash -docker build -t sim . +docker build -t sim . && \ +# docker run --device=/dev/tty0:rw -it --rm --gpus all \ docker run --privileged -it --rm --gpus all \ -v $HOME/lgsvlsimulator-linux64-2019.11:/lg \ -v $HOME/container-unity3d-2:/home/autoware/.config/unity3d:rw \ diff --git a/test-api-move.py b/test-api-move.py new file mode 100755 index 0000000..89ed828 --- /dev/null +++ b/test-api-move.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +import os +import lgsvl + +sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +if sim.current_scene == "BorregasAve": + sim.reset() +else: + sim.load("BorregasAve") + +spawns = sim.get_spawn() + +state = lgsvl.AgentState() +state.transform = spawns[0] +a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) + +state = lgsvl.AgentState() + +forward = lgsvl.utils.transform_to_forward(spawns[0]) +right = lgsvl.utils.transform_to_right(spawns[0]) + +# 10 meters ahead, on left lane +state.transform.position = spawns[0].position + 10.0 * forward +state.transform.rotation = spawns[0].rotation + +npc1 = sim.add_agent("Sedan", lgsvl.AgentType.NPC, state) + +state = lgsvl.AgentState() + +# 10 meters ahead, on right lane +state.transform.position = spawns[0].position + 4.0 * right + 10.0 * forward +state.transform.rotation = spawns[0].rotation + +npc2 = sim.add_agent("SUV", lgsvl.AgentType.NPC, state) + +# If the passed bool is False, then the NPC will not moved +# The float passed is the maximum speed the NPC will drive +# 11.1 m/s is ~40 km/h +npc1.follow_closest_lane(True, 11.1) + +# 5.6 m/s is ~20 km/h +npc2.follow_closest_lane(True, 5.6) + +sim.run() diff --git a/utils/install-docker.sh b/utils/install-docker.sh index 804a492..2cc0f9f 100644 --- a/utils/install-docker.sh +++ b/utils/install-docker.sh @@ -15,7 +15,12 @@ curl -fsSL get.docker.com -o get-docker.sh sudo sh get-docker.sh +# add $USER to docker group +# to run without docker +sudo gpasswd -a $USER docker + # to test (with gpu) # docker run --gpus all nvidia/cuda nvidia-smi # or (without gpu) # docker run hello-world +