commit
79d24b5f40
101 changed files with 688 additions and 946 deletions
@ -1 +1 @@ |
||||
Subproject commit a3a6e4969e58875f7cdfc9e6cc6b1af3ee2392b5 |
||||
Subproject commit d11688a90a1cebacb3fe00dcfbba5f27551b2d89 |
@ -1,4 +1,4 @@ |
||||
import os |
||||
|
||||
|
||||
BASEDIR = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), "../")) |
||||
BASEDIR = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), "../")) |
||||
|
@ -0,0 +1,42 @@ |
||||
# openpilot development workflow |
||||
|
||||
Aside from the ML models, most tools used for openpilot development are in this repo. |
||||
|
||||
Most development happens on normal Ubuntu workstations, and not in cars or directly on comma devices. See the [setup guide](../tools) for getting your PC setup for openpilot development. |
||||
|
||||
## Quick start |
||||
|
||||
```bash |
||||
# get the latest stuff |
||||
git pull |
||||
git submodule update --init --recursive |
||||
|
||||
# update dependencies |
||||
tools/ubuntu_setup.sh |
||||
|
||||
# build everything |
||||
scons -j$(nproc) |
||||
|
||||
# build just the ui with either of these |
||||
scons -j8 selfdrive/ui/ |
||||
cd selfdrive/ui/ && scons -u -j8 |
||||
|
||||
# test everything |
||||
pytest . |
||||
|
||||
# test just logging services |
||||
cd system/loggerd && pytest . |
||||
|
||||
# run the linter |
||||
pre-commit run --all |
||||
``` |
||||
|
||||
## Testing |
||||
|
||||
### Automated Testing |
||||
|
||||
All PRs and commits are automatically checked by GitHub Actions. Check out `.github/workflows/` for what GitHub Actions runs. Any new tests should be added to GitHub Actions. |
||||
|
||||
### Code Style and Linting |
||||
|
||||
Code is automatically checked for style by GitHub Actions as part of the automated tests. You can also run these tests yourself by running `pre-commit run --all`. |
@ -1 +1 @@ |
||||
Subproject commit 5b0c73977f1428700d0344d52874a90a4c5168fb |
||||
Subproject commit 93b983d49a2d6d5c67e15ce7650f55e4f121485d |
@ -1 +1 @@ |
||||
Subproject commit a5753a2077288b066e441dc2ba2f96d8062e5e49 |
||||
Subproject commit a88fe8c883758951ba2854eb2f6726d5365df099 |
@ -0,0 +1,39 @@ |
||||
#!/bin/bash |
||||
set -ex |
||||
|
||||
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)" |
||||
cd $DIR |
||||
|
||||
# git clone --mirror |
||||
SRC=/tmp/openpilot.git/ |
||||
OUT=/tmp/smallpilot/ |
||||
|
||||
echo "starting size $(du -hs .git/)" |
||||
|
||||
rm -rf $OUT |
||||
|
||||
cd $SRC |
||||
git remote update |
||||
|
||||
# copy contents |
||||
#rsync -a --exclude='.git/' $DIR $OUT |
||||
|
||||
cp -r $SRC $OUT |
||||
|
||||
cd $OUT |
||||
|
||||
# remove all tags |
||||
git tag -l | xargs git tag -d |
||||
|
||||
# remove non-master branches |
||||
BRANCHES="release2 dashcam dashcam3 release3 devel master-ci nightly" |
||||
for branch in $BRANCHES; do |
||||
git branch -D $branch |
||||
git branch -D ${branch}-staging || true |
||||
done |
||||
|
||||
#git gc |
||||
git reflog expire --expire=now --all |
||||
git gc --prune=now |
||||
git gc --aggressive --prune=now |
||||
echo "new one is $(du -hs .)" |
@ -1,11 +1,77 @@ |
||||
## Port structure |
||||
##### interface.py |
||||
# selfdrive/car |
||||
|
||||
### Check out this blogpost for a high level overview of car ports |
||||
https://blog.comma.ai/how-to-write-a-car-port-for-openpilot/ |
||||
|
||||
## Useful car porting utilities |
||||
|
||||
Testing car ports in your car is very time consuming! Checkout these utilities to do basic checks on your work before running it in your car. |
||||
|
||||
### [Cabana](/tools/cabana/README.md) |
||||
|
||||
View your car's CAN signals through DBC files, which openpilot uses to parse and create messages that talk to the car. |
||||
|
||||
Example: |
||||
```bash |
||||
> tools/cabana/cabana '1bbe6bf2d62f58a8|2022-07-14--17-11-43' |
||||
``` |
||||
|
||||
### [selfdrive/debug/auto_fingerprint.py](/selfdrive/debug/auto_fingerprint.py) |
||||
|
||||
Given a route and platform, automatically inserts FW fingerprints from the platform into the correct place in values.py |
||||
|
||||
Example: |
||||
```bash |
||||
> python selfdrive/debug/auto_fingerprint.py '1bbe6bf2d62f58a8|2022-07-14--17-11-43' 'SUBARU OUTBACK 6TH GEN' |
||||
Attempting to add fw version for: SUBARU OUTBACK 6TH GEN |
||||
``` |
||||
|
||||
### [selfdrive/car/tests/test_car_interfaces.py](/selfdrive/car/tests/test_car_interfaces.py) |
||||
|
||||
Finds common bugs for car interfaces, without even requiring a route! |
||||
|
||||
|
||||
#### Example: Typo in signal name |
||||
```bash |
||||
> pytest selfdrive/car/tests/test_car_interfaces.py -k subaru # (replace with the brand you are working on!) |
||||
|
||||
===================================================================== |
||||
FAILED selfdrive/car/tests/test_car_interfaces.py::TestCarInterfaces::test_car_interfaces_165_SUBARU_LEGACY_7TH_GEN - KeyError: 'CruiseControlOOPS' |
||||
|
||||
``` |
||||
|
||||
### [selfdrive/debug/test_car_model.py](/selfdrive/debug/test_car_model.py) |
||||
|
||||
Given a route, runs most of the car interface to check for common errors like missing signals, blocked panda messages, and mismatches. |
||||
|
||||
#### Example: Panda safety mismatch for gasPressed |
||||
```bash |
||||
> python selfdrive/debug/test_car_model.py '4822a427b188122a|2023-08-14--16-22-21' |
||||
|
||||
===================================================================== |
||||
FAIL: test_panda_safety_carstate (__main__.CarModelTestCase.test_panda_safety_carstate) |
||||
Assert that panda safety matches openpilot's carState |
||||
---------------------------------------------------------------------- |
||||
Traceback (most recent call last): |
||||
File "/home/batman/xx/openpilot/openpilot/selfdrive/car/tests/test_models.py", line 380, in test_panda_safety_carstate |
||||
self.assertFalse(len(failed_checks), f"panda safety doesn't agree with openpilot: {failed_checks}") |
||||
AssertionError: 1 is not false : panda safety doesn't agree with openpilot: {'gasPressed': 116} |
||||
``` |
||||
|
||||
|
||||
## Car Port structure |
||||
|
||||
### interface.py |
||||
Generic interface to send and receive messages from CAN (controlsd uses this to communicate with car) |
||||
##### carcontroller.py |
||||
|
||||
### carcontroller.py |
||||
Builds CAN messages to send to car |
||||
|
||||
##### carstate.py |
||||
Reads CAN from car and builds openpilot CarState message |
||||
|
||||
##### values.py |
||||
Fingerprints and absolute limits |
||||
Fingerprints, limits for actuation, car doc information, etc |
||||
|
||||
##### radar_interface.py |
||||
Radar interface |
||||
Interface for parsing radar points from the car |
||||
|
@ -1,3 +1,3 @@ |
||||
version https://git-lfs.github.com/spec/v1 |
||||
oid sha256:0b7184d46dc2ba3f84eb748252634205105a3742bac29942ae4380b0332fa850 |
||||
size 52524758 |
||||
oid sha256:cf6133c5bff295a3ee69eeb01297ba77adb6b83dbc1d774442a48117dbaf4626 |
||||
size 48457192 |
||||
|
@ -1,37 +0,0 @@ |
||||
import pytest |
||||
|
||||
from openpilot.selfdrive.test.process_replay.helpers import ALL_PROCS |
||||
from openpilot.selfdrive.test.process_replay.test_processes import ALL_CARS |
||||
|
||||
|
||||
def pytest_addoption(parser: pytest.Parser): |
||||
parser.addoption("--whitelist-procs", type=str, nargs="*", default=ALL_PROCS, |
||||
help="Whitelist given processes from the test (e.g. controlsd)") |
||||
parser.addoption("--whitelist-cars", type=str, nargs="*", default=ALL_CARS, |
||||
help="Whitelist given cars from the test (e.g. HONDA)") |
||||
parser.addoption("--blacklist-procs", type=str, nargs="*", default=[], |
||||
help="Blacklist given processes from the test (e.g. controlsd)") |
||||
parser.addoption("--blacklist-cars", type=str, nargs="*", default=[], |
||||
help="Blacklist given cars from the test (e.g. HONDA)") |
||||
parser.addoption("--ignore-fields", type=str, nargs="*", default=[], |
||||
help="Extra fields or msgs to ignore (e.g. carState.events)") |
||||
parser.addoption("--ignore-msgs", type=str, nargs="*", default=[], |
||||
help="Msgs to ignore (e.g. onroadEvents)") |
||||
parser.addoption("--update-refs", action="store_true", |
||||
help="Updates reference logs using current commit") |
||||
parser.addoption("--upload-only", action="store_true", |
||||
help="Skips testing processes and uploads logs from previous test run") |
||||
parser.addoption("--long-diff", action="store_true", |
||||
help="Outputs diff in long format") |
||||
|
||||
|
||||
@pytest.fixture(scope="class", autouse=True) |
||||
def process_replay_test_arguments(request): |
||||
if hasattr(request.cls, "segment"): # check if a subclass of TestProcessReplayBase |
||||
request.cls.tested_procs = list(set(request.config.getoption("--whitelist-procs")) - set(request.config.getoption("--blacklist-procs"))) |
||||
request.cls.tested_cars = list({c.upper() for c in set(request.config.getoption("--whitelist-cars")) - set(request.config.getoption("--blacklist-cars"))}) |
||||
request.cls.ignore_fields = request.config.getoption("--ignore-fields") |
||||
request.cls.ignore_msgs = request.config.getoption("--ignore-msgs") |
||||
request.cls.upload_only = request.config.getoption("--upload-only") |
||||
request.cls.update_refs = request.config.getoption("--update-refs") |
||||
request.cls.long_diff = request.config.getoption("--long-diff") |
@ -1,150 +0,0 @@ |
||||
#!/usr/bin/env python3 |
||||
import os |
||||
import sys |
||||
import unittest |
||||
|
||||
from parameterized import parameterized |
||||
from typing import Optional, Union, List |
||||
|
||||
|
||||
from openpilot.selfdrive.test.openpilotci import get_url, upload_file |
||||
from openpilot.selfdrive.test.process_replay.compare_logs import compare_logs, format_process_diff |
||||
from openpilot.selfdrive.test.process_replay.process_replay import CONFIGS, PROC_REPLAY_DIR, FAKEDATA, replay_process |
||||
from openpilot.system.version import get_commit |
||||
from openpilot.tools.lib.filereader import FileReader |
||||
from openpilot.tools.lib.helpers import save_log |
||||
from openpilot.tools.lib.logreader import LogReader, LogIterable |
||||
|
||||
|
||||
BASE_URL = "https://commadataci.blob.core.windows.net/openpilotci/" |
||||
REF_COMMIT_FN = os.path.join(PROC_REPLAY_DIR, "ref_commit") |
||||
EXCLUDED_PROCS = {"modeld", "dmonitoringmodeld"} |
||||
|
||||
|
||||
def get_log_data(segment): |
||||
r, n = segment.rsplit("--", 1) |
||||
with FileReader(get_url(r, n)) as f: |
||||
return f.read() |
||||
|
||||
|
||||
ALL_PROCS = sorted({cfg.proc_name for cfg in CONFIGS if cfg.proc_name not in EXCLUDED_PROCS}) |
||||
PROC_TO_CFG = {cfg.proc_name: cfg for cfg in CONFIGS} |
||||
|
||||
cpu_count = os.cpu_count() or 1 |
||||
|
||||
|
||||
class TestProcessReplayBase(unittest.TestCase): |
||||
""" |
||||
Base class that replays all processes within test_proceses from a segment, |
||||
and puts the log messages in self.log_msgs for analysis by other tests. |
||||
""" |
||||
segment: Optional[Union[str, LogIterable]] = None |
||||
tested_procs: List[str] = ALL_PROCS |
||||
|
||||
@classmethod |
||||
def setUpClass(cls, create_logs=True): |
||||
if "Base" in cls.__name__: |
||||
raise unittest.SkipTest("skipping base class") |
||||
|
||||
if isinstance(cls.segment, str): |
||||
cls.log_reader = LogReader.from_bytes(get_log_data(cls.segment)) |
||||
else: |
||||
cls.log_reader = cls.segment |
||||
|
||||
if create_logs: |
||||
cls._create_log_msgs() |
||||
|
||||
@classmethod |
||||
def _run_replay(cls, cfg): |
||||
try: |
||||
return replay_process(cfg, cls.log_reader, disable_progress=True) |
||||
except Exception as e: |
||||
raise Exception(f"failed on segment: {cls.segment} \n{e}") from e |
||||
|
||||
@classmethod |
||||
def _create_log_msgs(cls): |
||||
cls.log_msgs = {} |
||||
cls.proc_cfg = {} |
||||
|
||||
for proc in cls.tested_procs: |
||||
cfg = PROC_TO_CFG[proc] |
||||
|
||||
log_msgs = cls._run_replay(cfg) |
||||
|
||||
cls.log_msgs[proc] = log_msgs |
||||
cls.proc_cfg[proc] = cfg |
||||
|
||||
|
||||
class TestProcessReplayDiffBase(TestProcessReplayBase): |
||||
""" |
||||
Base class for checking for diff between process outputs. |
||||
""" |
||||
update_refs = False |
||||
upload_only = False |
||||
long_diff = False |
||||
ignore_msgs: List[str] = [] |
||||
ignore_fields: List[str] = [] |
||||
|
||||
def setUp(self): |
||||
super().setUp() |
||||
if self.upload_only: |
||||
raise unittest.SkipTest("skipping test, uploading only") |
||||
|
||||
@classmethod |
||||
def setUpClass(cls): |
||||
super().setUpClass(not cls.upload_only) |
||||
|
||||
if cls.long_diff: |
||||
cls.maxDiff = None |
||||
|
||||
os.makedirs(os.path.dirname(FAKEDATA), exist_ok=True) |
||||
|
||||
cls.cur_commit = get_commit() |
||||
cls.assertNotEqual(cls.cur_commit, None, "Couldn't get current commit") |
||||
|
||||
cls.upload = cls.update_refs or cls.upload_only |
||||
|
||||
try: |
||||
with open(REF_COMMIT_FN) as f: |
||||
cls.ref_commit = f.read().strip() |
||||
except FileNotFoundError: |
||||
print("Couldn't find reference commit") |
||||
sys.exit(1) |
||||
|
||||
cls._create_ref_log_msgs() |
||||
|
||||
@classmethod |
||||
def _create_ref_log_msgs(cls): |
||||
cls.ref_log_msgs = {} |
||||
|
||||
for proc in cls.tested_procs: |
||||
cur_log_fn = os.path.join(FAKEDATA, f"{cls.segment}_{proc}_{cls.cur_commit}.bz2") |
||||
if cls.update_refs: # reference logs will not exist if routes were just regenerated |
||||
ref_log_path = get_url(*cls.segment.rsplit("--", 1)) |
||||
else: |
||||
ref_log_fn = os.path.join(FAKEDATA, f"{cls.segment}_{proc}_{cls.ref_commit}.bz2") |
||||
ref_log_path = ref_log_fn if os.path.exists(ref_log_fn) else BASE_URL + os.path.basename(ref_log_fn) |
||||
|
||||
if not cls.upload_only: |
||||
save_log(cur_log_fn, cls.log_msgs[proc]) |
||||
cls.ref_log_msgs[proc] = list(LogReader(ref_log_path)) |
||||
|
||||
if cls.upload: |
||||
assert os.path.exists(cur_log_fn), f"Cannot find log to upload: {cur_log_fn}" |
||||
upload_file(cur_log_fn, os.path.basename(cur_log_fn)) |
||||
os.remove(cur_log_fn) |
||||
|
||||
@parameterized.expand(ALL_PROCS) |
||||
def test_process_diff(self, proc): |
||||
if proc not in self.tested_procs: |
||||
raise unittest.SkipTest(f"{proc} was not requested to be tested") |
||||
|
||||
cfg = self.proc_cfg[proc] |
||||
log_msgs = self.log_msgs[proc] |
||||
ref_log_msgs = self.ref_log_msgs[proc] |
||||
|
||||
diff = compare_logs(ref_log_msgs, log_msgs, self.ignore_fields + cfg.ignore, self.ignore_msgs) |
||||
|
||||
diff_short, diff_long = format_process_diff(diff) |
||||
|
||||
self.assertEqual(len(diff), 0, "\n" + diff_long if self.long_diff else diff_short) |
@ -1 +1 @@ |
||||
35a05ff1b68062c9478b2adfe96f1c294bee1b6c |
||||
91cd2bf71771c2770c0effc26c0bb23d27208138 |
||||
|
@ -1,44 +1,21 @@ |
||||
#pragma once |
||||
|
||||
#include <QStackedLayout> |
||||
|
||||
#include "selfdrive/ui/qt/widgets/cameraview.h" |
||||
|
||||
class DriverViewScene : public QWidget { |
||||
class DriverViewWindow : public CameraWidget { |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
explicit DriverViewScene(QWidget *parent); |
||||
explicit DriverViewWindow(QWidget *parent); |
||||
|
||||
public slots: |
||||
void frameUpdated(); |
||||
signals: |
||||
void done(); |
||||
|
||||
protected: |
||||
void showEvent(QShowEvent *event) override; |
||||
void hideEvent(QHideEvent *event) override; |
||||
void paintEvent(QPaintEvent *event) override; |
||||
void paintGL() override; |
||||
|
||||
private: |
||||
Params params; |
||||
QPixmap face_img; |
||||
bool is_rhd = false; |
||||
bool frame_updated = false; |
||||
}; |
||||
|
||||
class DriverViewWindow : public QWidget { |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
explicit DriverViewWindow(QWidget *parent); |
||||
|
||||
signals: |
||||
void done(); |
||||
|
||||
protected: |
||||
void mouseReleaseEvent(QMouseEvent* e) override; |
||||
void closeView(); |
||||
|
||||
CameraWidget *cameraView; |
||||
DriverViewScene *scene; |
||||
QStackedLayout *layout; |
||||
}; |
||||
|
@ -1,4 +0,0 @@ |
||||
#!/bin/sh |
||||
cd "$(dirname "$0")" |
||||
export QT_DBL_CLICK_DIST=150 |
||||
exec ./_ui |
@ -1,22 +0,0 @@ |
||||
from openpilot.tools.sim.bridge.common import SimulatorBridge |
||||
from openpilot.tools.sim.bridge.carla.carla_world import CarlaWorld |
||||
|
||||
|
||||
class CarlaBridge(SimulatorBridge): |
||||
TICKS_PER_FRAME = 5 |
||||
|
||||
def __init__(self, arguments): |
||||
super().__init__(arguments) |
||||
self.host = arguments.host |
||||
self.port = arguments.port |
||||
self.town = arguments.town |
||||
self.num_selected_spawn_point = arguments.num_selected_spawn_point |
||||
|
||||
def spawn_world(self): |
||||
import carla |
||||
|
||||
client = carla.Client(self.host, self.port) |
||||
client.set_timeout(5) |
||||
|
||||
return CarlaWorld(client, high_quality=self.high_quality, dual_camera=self.dual_camera, |
||||
num_selected_spawn_point=self.num_selected_spawn_point, town=self.town) |
@ -1,145 +0,0 @@ |
||||
import numpy as np |
||||
|
||||
from openpilot.common.params import Params |
||||
from openpilot.tools.sim.lib.common import SimulatorState, vec3 |
||||
from openpilot.tools.sim.bridge.common import World |
||||
from openpilot.tools.sim.lib.camerad import W, H |
||||
|
||||
|
||||
class CarlaWorld(World): |
||||
def __init__(self, client, high_quality, dual_camera, num_selected_spawn_point, town): |
||||
super().__init__(dual_camera) |
||||
import carla |
||||
|
||||
low_quality_layers = carla.MapLayer(carla.MapLayer.Ground | carla.MapLayer.Walls | carla.MapLayer.Decals) |
||||
|
||||
layers = carla.MapLayer.All if high_quality else low_quality_layers |
||||
|
||||
world = client.load_world(town, map_layers=layers) |
||||
|
||||
settings = world.get_settings() |
||||
settings.fixed_delta_seconds = 0.01 |
||||
world.apply_settings(settings) |
||||
|
||||
world.set_weather(carla.WeatherParameters.ClearSunset) |
||||
|
||||
self.world = world |
||||
world_map = world.get_map() |
||||
|
||||
blueprint_library = world.get_blueprint_library() |
||||
|
||||
vehicle_bp = blueprint_library.filter('vehicle.tesla.*')[1] |
||||
vehicle_bp.set_attribute('role_name', 'hero') |
||||
spawn_points = world_map.get_spawn_points() |
||||
assert len(spawn_points) > num_selected_spawn_point, \ |
||||
f'''No spawn point {num_selected_spawn_point}, try a value between 0 and {len(spawn_points)} for this town.''' |
||||
self.spawn_point = spawn_points[num_selected_spawn_point] |
||||
self.vehicle = world.spawn_actor(vehicle_bp, self.spawn_point) |
||||
|
||||
physics_control = self.vehicle.get_physics_control() |
||||
physics_control.mass = 2326 |
||||
physics_control.torque_curve = [[20.0, 500.0], [5000.0, 500.0]] |
||||
physics_control.gear_switch_time = 0.0 |
||||
self.vehicle.apply_physics_control(physics_control) |
||||
|
||||
self.vc: carla.VehicleControl = carla.VehicleControl(throttle=0, steer=0, brake=0, reverse=False) |
||||
self.max_steer_angle: float = self.vehicle.get_physics_control().wheels[0].max_steer_angle |
||||
self.params = Params() |
||||
|
||||
self.steer_ratio = 15 |
||||
|
||||
self.carla_objects = [] |
||||
|
||||
transform = carla.Transform(carla.Location(x=0.8, z=1.13)) |
||||
|
||||
def create_camera(fov, callback): |
||||
blueprint = blueprint_library.find('sensor.camera.rgb') |
||||
blueprint.set_attribute('image_size_x', str(W)) |
||||
blueprint.set_attribute('image_size_y', str(H)) |
||||
blueprint.set_attribute('fov', str(fov)) |
||||
blueprint.set_attribute('sensor_tick', str(1/20)) |
||||
if not high_quality: |
||||
blueprint.set_attribute('enable_postprocess_effects', 'False') |
||||
camera = world.spawn_actor(blueprint, transform, attach_to=self.vehicle) |
||||
camera.listen(callback) |
||||
return camera |
||||
|
||||
self.road_camera = create_camera(fov=40, callback=self.cam_callback_road) |
||||
if dual_camera: |
||||
self.road_wide_camera = create_camera(fov=120, callback=self.cam_callback_wide_road) # fov bigger than 120 shows unwanted artifacts |
||||
else: |
||||
self.road_wide_camera = None |
||||
|
||||
# re-enable IMU |
||||
imu_bp = blueprint_library.find('sensor.other.imu') |
||||
imu_bp.set_attribute('sensor_tick', '0.01') |
||||
self.imu = world.spawn_actor(imu_bp, transform, attach_to=self.vehicle) |
||||
|
||||
gps_bp = blueprint_library.find('sensor.other.gnss') |
||||
self.gps = world.spawn_actor(gps_bp, transform, attach_to=self.vehicle) |
||||
self.params.put_bool("UbloxAvailable", True) |
||||
|
||||
self.carla_objects = [self.imu, self.gps, self.road_camera, self.road_wide_camera, self.vehicle] |
||||
|
||||
def close(self): |
||||
for s in self.carla_objects: |
||||
if s is not None: |
||||
try: |
||||
s.destroy() |
||||
except Exception as e: |
||||
print("Failed to destroy carla object", e) |
||||
|
||||
def carla_image_to_rgb(self, image): |
||||
rgb = np.frombuffer(image.raw_data, dtype=np.dtype("uint8")) |
||||
rgb = np.reshape(rgb, (H, W, 4)) |
||||
return np.ascontiguousarray(rgb[:, :, [0, 1, 2]]) |
||||
|
||||
def cam_callback_road(self, image): |
||||
with self.image_lock: |
||||
self.road_image = self.carla_image_to_rgb(image) |
||||
|
||||
def cam_callback_wide_road(self, image): |
||||
with self.image_lock: |
||||
self.wide_road_image = self.carla_image_to_rgb(image) |
||||
|
||||
def apply_controls(self, steer_angle, throttle_out, brake_out): |
||||
self.vc.throttle = throttle_out |
||||
|
||||
steer_carla = steer_angle * -1 / (self.max_steer_angle * self.steer_ratio) |
||||
steer_carla = np.clip(steer_carla, -1, 1) |
||||
|
||||
self.vc.steer = steer_carla |
||||
self.vc.brake = brake_out |
||||
self.vehicle.apply_control(self.vc) |
||||
|
||||
def read_sensors(self, simulator_state: SimulatorState): |
||||
simulator_state.imu.bearing = self.imu.get_transform().rotation.yaw |
||||
|
||||
simulator_state.imu.accelerometer = vec3( |
||||
self.imu.get_acceleration().x, |
||||
self.imu.get_acceleration().y, |
||||
self.imu.get_acceleration().z |
||||
) |
||||
|
||||
simulator_state.imu.gyroscope = vec3( |
||||
self.imu.get_angular_velocity().x, |
||||
self.imu.get_angular_velocity().y, |
||||
self.imu.get_angular_velocity().z |
||||
) |
||||
|
||||
simulator_state.gps.from_xy([self.vehicle.get_location().x, self.vehicle.get_location().y]) |
||||
|
||||
simulator_state.velocity = self.vehicle.get_velocity() |
||||
simulator_state.valid = True |
||||
simulator_state.steering_angle = self.vc.steer * self.max_steer_angle |
||||
|
||||
def read_cameras(self): |
||||
pass # cameras are read within a callback for carla |
||||
|
||||
def tick(self): |
||||
self.world.tick() |
||||
|
||||
def reset(self): |
||||
import carla |
||||
self.vehicle.set_transform(self.spawn_point) |
||||
self.vehicle.set_target_velocity(carla.Vector3D()) |
@ -1,34 +0,0 @@ |
||||
#!/bin/bash |
||||
|
||||
# Requires nvidia docker - https://github.com/NVIDIA/nvidia-docker |
||||
if ! $(apt list --installed | grep -q nvidia-container-toolkit); then |
||||
read -p "Nvidia docker is required. Do you want to install it now? (y/n)"; |
||||
if [ "${REPLY}" == "y" ]; then |
||||
distribution=$(. /etc/os-release;echo $ID$VERSION_ID) |
||||
echo $distribution |
||||
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - |
||||
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list |
||||
sudo apt-get update && sudo apt-get install -y nvidia-docker2 # Also installs docker-ce and nvidia-container-toolkit |
||||
sudo systemctl restart docker |
||||
else |
||||
exit 0 |
||||
fi |
||||
fi |
||||
|
||||
docker pull carlasim/carla:0.9.14 |
||||
|
||||
EXTRA_ARGS="-it" |
||||
if [[ "$DETACH" ]]; then |
||||
EXTRA_ARGS="-d" |
||||
fi |
||||
|
||||
docker kill carla_sim || true |
||||
docker run \ |
||||
--name carla_sim \ |
||||
--rm \ |
||||
--gpus all \ |
||||
--net=host \ |
||||
-v /tmp/.X11-unix:/tmp/.X11-unix:rw \ |
||||
$EXTRA_ARGS \ |
||||
carlasim/carla:0.9.14 \ |
||||
/bin/bash ./CarlaUE4.sh -opengl -nosound -RenderOffScreen -benchmark -fps=20 -quality-level=Low |
@ -1,45 +0,0 @@ |
||||
#!/usr/bin/env python3 |
||||
import subprocess |
||||
import time |
||||
import unittest |
||||
from subprocess import Popen |
||||
|
||||
from openpilot.selfdrive.manager.helpers import unblock_stdout |
||||
from openpilot.tools.sim.run_bridge import parse_args |
||||
from openpilot.tools.sim.bridge.carla.carla_bridge import CarlaBridge |
||||
from openpilot.tools.sim.tests.test_sim_bridge import SIM_DIR, TestSimBridgeBase |
||||
|
||||
from typing import Optional |
||||
|
||||
class TestCarlaBridge(TestSimBridgeBase): |
||||
""" |
||||
Tests need Carla simulator to run |
||||
""" |
||||
carla_process: Optional[Popen] = None |
||||
|
||||
def setUp(self): |
||||
super().setUp() |
||||
|
||||
# We want to make sure that carla_sim docker isn't still running. |
||||
subprocess.run("docker rm -f carla_sim", shell=True, stderr=subprocess.PIPE, check=False) |
||||
self.carla_process = subprocess.Popen("./start_carla.sh", cwd=SIM_DIR) |
||||
|
||||
# Too many lagging messages in bridge.py can cause a crash. This prevents it. |
||||
unblock_stdout() |
||||
# Wait 10 seconds to startup carla |
||||
time.sleep(10) |
||||
|
||||
def create_bridge(self): |
||||
return CarlaBridge(parse_args([])) |
||||
|
||||
def tearDown(self): |
||||
super().tearDown() |
||||
|
||||
# Stop carla simulator by removing docker container |
||||
subprocess.run("docker rm -f carla_sim", shell=True, stderr=subprocess.PIPE, check=False) |
||||
if self.carla_process is not None: |
||||
self.carla_process.wait() |
||||
|
||||
|
||||
if __name__ == "__main__": |
||||
unittest.main() |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue