Skip to content

Commit

Permalink
dockerize carla + openpilot (commaai#2011)
Browse files Browse the repository at this point in the history
* dockerize carla + openpilot

* separate dockerfile

* bring back CI dockerfile

* cleanup bridge

* add op docker build and start script

* build container in CI

* fix camerad hack

* remove most magic numbers from bridge.py

* openpilot-sim docker build and run scripts

* fix dmonitoring hacks

* revert controlsd hacks

* clean up build scripts

* singular

* fix path

* fix image name

* modify sim readme

* sim readme and start script changes

* dockerfile with working opengl

* working opengl + passing panda build_st in docker

* fix bug in sim docker file

* bugfix sim docker file

* bugfix all op-sim docker issues

* modify readme + run script

* IT DRIVES

* clean this up

* more cleanup

* cleanup docker stuff

* more cleanup

* start with openpilot-base

* install carla python package

* Script is not in lib

* chmod

* everything should be running in docker now, the code may not be nice though

* works locally...

* rhdChecked is deprecated

* Checkout using git lfs when building sim container

* try to pass the tests

* pull latest docker

* gps should not throw an error on openpilot launch in bridge.py

* fixed a coding style error

* Only start ubloxd in car

* fixed more style problems

* revert typo

* Use enviromental variable to prevent errors in a simulator

* Remove unused import

* Attempt to fix missing enviromental variable

* fix typo

* less work for users, auto tmux engagement

* less work for users, auto tmux engagement

* fix check for nvidia

* clean up nvidia check

* remove typo, shorted dockerfile

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
Co-authored-by: Willem Melching <willem.melching@gmail.com>
Co-authored-by: Bruce Wayne <batman@workstation-eu-gregor.eu.local>
Co-authored-by: Gregor Kikelj <gregor1234567890@gmail.com>
old-commit-hash: c5dfbe7
  • Loading branch information
5 people authored Sep 10, 2020
1 parent 6aebe5f commit db0a4ef
Show file tree
Hide file tree
Showing 19 changed files with 450 additions and 199 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ xx/projects
!xx/projects/map3d
xx/ops
xx/junk
tools/sim/carla
tools/sim/*.tar.gz
26 changes: 26 additions & 0 deletions .github/workflows/sim_tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: simulator
on:
push:

# TODO: remove the push trigger, and only run on schedule
#schedule:
#- cron: '0 * * * *'

jobs:
docker_build:
name: build container
runs-on: ubuntu-16.04
timeout-minutes: 50
steps:
- uses: actions/checkout@v2
with:
submodules: true
lfs: true
- name: Docker build
run: |
tools/sim/build_container.sh
- name: Push to dockerhub
run: |
docker login -u wmelching -p ${{ secrets.COMMA_DOCKERHUB_TOKEN }}
docker tag commaai/openpilot-sim docker.io/commaai/openpilot-sim:latest
docker push docker.io/commaai/openpilot-sim:latest
12 changes: 8 additions & 4 deletions selfdrive/controls/controlsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
LANE_DEPARTURE_THRESHOLD = 0.1
STEER_ANGLE_SATURATION_TIMEOUT = 1.0 / DT_CTRL
STEER_ANGLE_SATURATION_THRESHOLD = 2.5 # Degrees
SIMULATION = "SIMULATION" in os.environ

ThermalStatus = log.ThermalData.ThermalStatus
State = log.ControlsState.OpenpilotState
Expand Down Expand Up @@ -193,7 +194,7 @@ def update_events(self, CS):
elif self.sm['pathPlan'].laneChangeState in [LaneChangeState.laneChangeStarting,
LaneChangeState.laneChangeFinishing]:
self.events.add(EventName.laneChange)

if self.can_rcv_error or (not CS.canValid and self.sm.frame > 5 / DT_CTRL):
self.events.add(EventName.canError)
if self.mismatch_counter >= 200:
Expand All @@ -210,7 +211,9 @@ def update_events(self, CS):
self.events.add(EventName.sensorDataInvalid)
if not self.sm['liveLocationKalman'].gpsOK and (self.distance_traveled > 1000) and os.getenv("NOSENSOR") is None:
# Not show in first 1 km to allow for driving out of garage. This event shows after 5 minutes
self.events.add(EventName.noGps)
# GPS is not yet working in a simulation
if not SIMULATION:
self.events.add(EventName.noGps)
if not self.sm['pathPlan'].paramsValid:
self.events.add(EventName.vehicleModelInvalid)
if not self.sm['liveLocationKalman'].posenetOK:
Expand All @@ -229,11 +232,12 @@ def update_events(self, CS):
if self.sm['plan'].fcw:
self.events.add(EventName.fcw)
if self.sm['model'].frameDropPerc > 1:
self.events.add(EventName.modeldLagging)
if not SIMULATION:
self.events.add(EventName.modeldLagging)

# Only allow engagement with brake pressed when stopped behind another stopped car
if CS.brakePressed and self.sm['plan'].vTargetFuture >= STARTING_TARGET_SPEED \
and not self.CP.radarOffCan and CS.vEgo < 0.3:
and not self.CP.radarOffCan and CS.vEgo < 0.3:
self.events.add(EventName.noTarget)

def data_sample(self):
Expand Down
6 changes: 3 additions & 3 deletions selfdrive/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,31 +234,31 @@ def get_running():
'plannerd',
'loggerd',
'radard',
'dmonitoringd',
'calibrationd',
'paramsd',
'camerad',
'modeld',
'proclogd',
'ubloxd',
'locationd',
'clocksd',
]

driver_view_processes = [
'camerad',
'dmonitoringd',
'dmonitoringmodeld'
]

if WEBCAM:
car_started_processes += [
'dmonitoringd',
'dmonitoringmodeld',
]

if not PC:
car_started_processes += [
'ubloxd',
'sensord',
'dmonitoringd',
'dmonitoringmodeld',
]

Expand Down
5 changes: 2 additions & 3 deletions selfdrive/modeld/modeld
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/bin/sh
if [ -d /system ]; then
export LD_LIBRARY_PATH="/data/pythonpath/phonelibs/snpe/aarch64/:$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH="/data/pythonpath/phonelibs/snpe/aarch64/:$LD_LIBRARY_PATH"
else
export LD_LIBRARY_PATH="/usr/lib/aarch64-linux-gnu:/data/pythonpath/phonelibs/snpe/larch64:$HOME/openpilot/phonelibs/snpe/x86_64-linux-clang:$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH="/usr/lib/aarch64-linux-gnu:/data/pythonpath/phonelibs/snpe/larch64:$HOME/openpilot/phonelibs/snpe/x86_64-linux-clang:/openpilot/phonelibs/snpe/x86_64:$HOME/openpilot/phonelibs/snpe/x86_64:$LD_LIBRARY_PATH"
fi
exec ./_modeld

104 changes: 104 additions & 0 deletions tools/sim/Dockerfile.sim
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
FROM commaai/openpilot-base:latest
#Carla

COPY ./tools/sim/install_carla.sh /tmp
RUN /tmp/install_carla.sh

#Intel openCL- run openCL on CPU
RUN apt-get update && apt-get install -y \
apt-utils \
unzip \
tar \
curl \
xz-utils \

beignet-opencl-icd \

alien \
clinfo \
dbus \
gcc-arm-none-eabi \
tmux \
vim \

# libglvnd dependencies
automake \
libtool \
libxext-dev \
libx11-dev \
x11proto-gl-dev \
libpng16-16 \
&& rm -rf /var/lib/apt/lists/*


ARG INTEL_DRIVER=opencl_runtime_16.1.1_x64_ubuntu_6.4.0.25.tgz
ARG INTEL_DRIVER_URL=http://registrationcenter-download.intel.com/akdlm/irc_nas/9019
RUN mkdir -p /tmp/opencl-driver-intel
WORKDIR /tmp/opencl-driver-intel
RUN echo INTEL_DRIVER is $INTEL_DRIVER; \
curl -O $INTEL_DRIVER_URL/$INTEL_DRIVER; \
if echo $INTEL_DRIVER | grep -q "[.]zip$"; then \
unzip $INTEL_DRIVER; \
mkdir fakeroot; \
for f in intel-opencl-*.tar.xz; do tar -C fakeroot -Jxvf $f; done; \
cp -R fakeroot/* /; \
ldconfig; \
else \
tar -xzf $INTEL_DRIVER; \
for i in $(basename $INTEL_DRIVER .tgz)/rpm/*.rpm; do alien --to-deb $i; done; \
dpkg -i *.deb; \
rm -rf $INTEL_DRIVER $(basename $INTEL_DRIVER .tgz) *.deb; \
mkdir -p /etc/OpenCL/vendors; \
echo /opt/intel/*/lib64/libintelocl.so > /etc/OpenCL/vendors/intel.icd; \
fi; \
rm -rf /tmp/opencl-driver-intel;


#Open[GL,CL] for gpu
ENV NVIDIA_DRIVER_CAPABILITIES ${NVIDIA_DRIVER_CAPABILITIES},display
RUN apt-get update && apt-get install -y --no-install-recommends \
mesa-utils \
ocl-icd-libopencl1 \
clinfo && \
rm -rf /var/lib/apt/lists/*
RUN mkdir -p /etc/OpenCL/vendors && \
echo "libnvidia-opencl.so.1" > /etc/OpenCL/vendors/nvidia.icd
ENV NVIDIA_VISIBLE_DEVICES all
ENV NVIDIA_DRIVER_CAPABILITIES compute,utility,display

#Python
ENV PYTHONPATH $HOME/openpilot:${PYTHONPATH}
RUN dbus-uuidgen > /etc/machine-id

# we can apt-get after moving to a newer ubuntu
WORKDIR /opt/libglvnd
RUN git clone --branch="0.1.1" https://github.com/NVIDIA/libglvnd.git . && \
./autogen.sh && \
./configure --prefix=/usr/local --libdir=/usr/local/lib/x86_64-linux-gnu && \
make -j"$(nproc)" install-strip && \
find /usr/local/lib/x86_64-linux-gnu -type f -name 'lib*.la' -delete

ENV LD_LIBRARY_PATH /usr/local/lib/x86_64-linux-gnu:/usr/local/lib/i386-linux-gnu${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

# get same tmux config used on NEOS for debugging
RUN cd $HOME && \
wget https://raw.githubusercontent.com/commaai/eon-neos-builder/master/devices/eon/home/.tmux.conf

RUN mkdir -p $HOME/openpilot

COPY SConstruct $HOME/openpilot/

COPY ./phonelibs $HOME/openpilot/phonelibs
COPY ./laika $HOME/openpilot/laika
COPY ./laika_repo $HOME/openpilot/laika_repo
COPY ./rednose $HOME/openpilot/rednose
COPY ./common $HOME/openpilot/common
COPY ./models $HOME/openpilot/models
COPY ./opendbc $HOME/openpilot/opendbc
COPY ./cereal $HOME/openpilot/cereal
COPY ./panda $HOME/openpilot/panda
COPY ./selfdrive $HOME/openpilot/selfdrive
COPY ./tools $HOME/openpilot/tools

WORKDIR $HOME/openpilot
RUN scons -j40
32 changes: 12 additions & 20 deletions tools/sim/README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
openpilot in simulator
=====================
Needs Ubuntu 16.04

## Checkout openpilot
```
cd ~/
git clone https://github.com/commaai/openpilot.git
## Setup

# Add export PYTHONPATH=$HOME/openpilot to your bashrc
# Have a working tensorflow+keras in python3.7.3 (with [packages] in openpilot/Pipfile)
```
## Install (in terminal 1)
```
cd ~/openpilot/tools/sim
./start_carla.sh # install CARLA 0.9.7 and start the server
```
## openpilot (in terminal 2)
Checkout openpilot
```
cd ~/openpilot/selfdrive/
PASSIVE=0 NOBOARD=1 ./manager.py
cd ~/ && git clone https://github.com/commaai/openpilot.git
```
## bridge (in terminal 3)

## Running the simulator

First, start the CARLA server.
```
# links carla to openpilot, will "start the car" according to manager
cd ~/openpilot/tools/sim
./bridge.py
./start_carla.sh
```

Then use `start_openpilot_docker.sh` to start the docker container.

## Controls

Now put the focus on the terminal running bridge.py and you can control
openpilot driving in the simulation with the following keys

Expand All @@ -37,4 +30,3 @@ openpilot driving in the simulation with the following keys
| 3 | Cruise cancel |
| q | Exit all |


Loading

0 comments on commit db0a4ef

Please sign in to comment.