Skip to content

Commit

Permalink
Merge branch 'commaai:master' into PA-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Edison-CBS authored May 30, 2024
2 parents 5db36e6 + aa081f5 commit 41b96dc
Show file tree
Hide file tree
Showing 21 changed files with 91 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tools_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
- name: Setup Dev Container CLI
run: npm install -g @devcontainers/cli
- name: Build dev container image
run: devcontainer build --workspace-folder .
run: ./scripts/retry.sh devcontainer build --workspace-folder .
- name: Run dev container
run: |
mkdir -p /tmp/devcontainer_scons_cache/
Expand Down
5 changes: 5 additions & 0 deletions common/prefix.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "common/params.h"
#include "common/util.h"
#include "system/hardware/hw.h"

class OpenpilotPrefix {
public:
Expand All @@ -25,6 +26,10 @@ class OpenpilotPrefix {
system(util::string_format("rm %s -rf", real_path.c_str()).c_str());
unlink(param_path.c_str());
}
if (getenv("COMMA_CACHE") == nullptr) {
system(util::string_format("rm %s -rf", Path::download_cache_root().c_str()).c_str());
}
system(util::string_format("rm %s -rf", Path::comma_home().c_str()).c_str());
system(util::string_format("rm %s -rf", msgq_path.c_str()).c_str());
unsetenv("OPENPILOT_PREFIX");
}
Expand Down
20 changes: 12 additions & 8 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ inputs = "*"
Jinja2 = "*"
lru-dict = "*"
matplotlib = "*"
metadrive-simulator = { version = "0.4.2.3", markers = "platform_machine != 'aarch64'" } # no linux/aarch64 wheels for certain dependencies
# No release for this fix https://github.com/metadriverse/metadrive/issues/632. Pinned to this commit until next release
metadrive-simulator = {git = "https://github.com/metadriverse/metadrive.git", rev ="233a3a1698be7038ec3dd050ca10b547b4b3324c", markers = "platform_machine != 'aarch64'" } # no linux/aarch64 wheels for certain dependencies
mpld3 = "*"
mypy = "*"
myst-parser = "*"
Expand Down
2 changes: 2 additions & 0 deletions selfdrive/car/chrysler/fingerprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
b'68413871AE ',
b'68413871AH ',
b'68413871AI ',
b'68413873AH ',
b'68413873AI ',
b'68443120AE ',
b'68443123AC ',
Expand All @@ -165,6 +166,7 @@
b'68414271AC',
b'68414271AD',
b'68414275AC',
b'68414275AD',
b'68443154AB',
b'68443155AC',
b'68443158AB',
Expand Down
1 change: 1 addition & 0 deletions selfdrive/car/hyundai/fingerprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,7 @@
b'\xf1\x00NQ5 FR_CMR AT GEN LHD 1.00 1.00 99211-P1060 665',
b'\xf1\x00NQ5 FR_CMR AT USA LHD 1.00 1.00 99211-P1030 662',
b'\xf1\x00NQ5 FR_CMR AT USA LHD 1.00 1.00 99211-P1040 663',
b'\xf1\x00NQ5 FR_CMR AT EUR LHD 1.00 1.00 99211-P1040 663',
b'\xf1\x00NQ5 FR_CMR AT USA LHD 1.00 1.00 99211-P1060 665',
b'\xf1\x00NQ5 FR_CMR AT USA LHD 1.00 1.00 99211-P1070 690',
],
Expand Down
8 changes: 5 additions & 3 deletions selfdrive/monitoring/dmonitoringd.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ def dmonitoringd_thread():
# 20Hz <- dmonitoringmodeld
while True:
sm.update()
if (not sm.updated['driverStateV2']) or (not sm.all_checks()):
if not sm.updated['driverStateV2']:
# iterate when model has new output
continue

DM.run_step(sm)
valid = sm.all_checks()
if valid:
DM.run_step(sm)

# publish
dat = DM.get_state_packet()
dat = DM.get_state_packet(valid=valid)
pm.send('driverMonitoringState', dat)

# load live always-on toggle
Expand Down
4 changes: 2 additions & 2 deletions selfdrive/monitoring/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,9 @@ def _update_events(self, driver_engaged, op_engaged, standstill, wrong_gear, car
self.current_events.add(alert)


def get_state_packet(self):
def get_state_packet(self, valid=True):
# build driverMonitoringState packet
dat = messaging.new_message('driverMonitoringState', valid=True)
dat = messaging.new_message('driverMonitoringState', valid=valid)
dat.driverMonitoringState = {
"events": self.current_events.to_msg(),
"faceDetected": self.face_detected,
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/test/process_replay/ref_commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dbf5b05ff480145a79b5941e360d0698b70979cd
87aa5052e36d5cf83698b1eb6e50aef5c86df8ca
13 changes: 13 additions & 0 deletions selfdrive/ui/qt/maps/map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <QDebug>

#include "common/swaglog.h"
#include "selfdrive/ui/qt/maps/map_helpers.h"
#include "selfdrive/ui/qt/util.h"
#include "selfdrive/ui/ui.h"
Expand Down Expand Up @@ -118,6 +119,14 @@ void MapWindow::updateState(const UIState &s) {
const SubMaster &sm = *(s.sm);
update();

// on rising edge of a valid system time, reinitialize the map to set a new token
if (sm.valid("clocks") && !prev_time_valid) {
LOGW("Time is now valid, reinitializing map");
m_settings.setApiKey(get_mapbox_token());
initializeGL();
}
prev_time_valid = sm.valid("clocks");

if (sm.updated("liveLocationKalman")) {
auto locationd_location = sm["liveLocationKalman"].getLiveLocationKalman();
auto locationd_pos = locationd_location.getPositionGeodetic();
Expand Down Expand Up @@ -262,6 +271,10 @@ void MapWindow::initializeGL() {
loaded_once = true;
}
});

QObject::connect(m_map.data(), &QMapLibre::Map::mapLoadingFailed, [=](QMapLibre::Map::MapLoadingFailure err_code, const QString &reason) {
LOGE("Map loading failed with %d: '%s'\n", err_code, reason.toStdString().c_str());
});
}

void MapWindow::paintGL() {
Expand Down
1 change: 1 addition & 0 deletions selfdrive/ui/qt/maps/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class MapWindow : public QOpenGLWidget {
void setError(const QString &err_str);

bool loaded_once = false;
bool prev_time_valid = true;

// Panning
QPointF m_lastPos;
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/ui/ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ UIState::UIState(QObject *parent) : QObject(parent) {
sm = std::make_unique<SubMaster, const std::initializer_list<const char *>>({
"modelV2", "controlsState", "liveCalibration", "radarState", "deviceState",
"pandaStates", "carParams", "driverMonitoringState", "carState", "liveLocationKalman", "driverStateV2",
"wideRoadCameraState", "managerState", "navInstruction", "navRoute", "uiPlan",
"wideRoadCameraState", "managerState", "navInstruction", "navRoute", "uiPlan", "clocks",
});

Params params;
Expand Down
5 changes: 5 additions & 0 deletions tools/cabana/streams/abstractstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class AbstractStream : public QObject {
AbstractStream(QObject *parent);
virtual ~AbstractStream() {}
virtual void start() = 0;
virtual void stop() {}
virtual bool liveStreaming() const { return true; }
virtual void seekTo(double ts) {}
virtual QString routeName() const = 0;
Expand Down Expand Up @@ -128,11 +129,15 @@ class AbstractStream : public QObject {
};

class AbstractOpenStreamWidget : public QWidget {
Q_OBJECT
public:
AbstractOpenStreamWidget(AbstractStream **stream, QWidget *parent = nullptr) : stream(stream), QWidget(parent) {}
virtual bool open() = 0;
virtual QString title() = 0;

signals:
void enableOpenButton(bool);

protected:
AbstractStream **stream = nullptr;
};
Expand Down
9 changes: 8 additions & 1 deletion tools/cabana/streams/livestream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ LiveStream::LiveStream(QObject *parent) : AbstractStream(parent) {
QObject::connect(stream_thread, &QThread::finished, stream_thread, &QThread::deleteLater);
}

LiveStream::~LiveStream() {
stop();
}

void LiveStream::startUpdateTimer() {
update_timer.stop();
update_timer.start(1000.0 / settings.fps, this);
Expand All @@ -55,11 +59,14 @@ void LiveStream::start() {
begin_date_time = QDateTime::currentDateTime();
}

LiveStream::~LiveStream() {
void LiveStream::stop() {
if (!stream_thread) return;

update_timer.stop();
stream_thread->requestInterruption();
stream_thread->quit();
stream_thread->wait();
stream_thread = nullptr;
}

// called in streamThread
Expand Down
1 change: 1 addition & 0 deletions tools/cabana/streams/livestream.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class LiveStream : public AbstractStream {
LiveStream(QObject *parent);
virtual ~LiveStream();
void start() override;
void stop() override;
inline QDateTime beginDateTime() const { return begin_date_time; }
inline double routeStartTime() const override { return begin_event_ts / 1e9; }
void setSpeed(float speed) override { speed_ = speed; }
Expand Down
31 changes: 21 additions & 10 deletions tools/cabana/streams/pandastream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@
#include <QMessageBox>
#include <QPushButton>
#include <QThread>
#include <QTimer>

PandaStream::PandaStream(QObject *parent, PandaStreamConfig config_) : config(config_), LiveStream(parent) {}
PandaStream::PandaStream(QObject *parent, PandaStreamConfig config_) : config(config_), LiveStream(parent) {
if (!connect()) {
throw std::runtime_error("Failed to connect to panda");
}
}

bool PandaStream::connect() {
try {
qDebug() << "Connecting to panda with serial" << config.serial;
qDebug() << "Connecting to panda " << config.serial;
panda.reset(new Panda(config.serial.toStdString()));
config.bus_config.resize(3);
qDebug() << "Connected";
Expand Down Expand Up @@ -80,6 +85,13 @@ AbstractOpenStreamWidget *PandaStream::widget(AbstractStream **stream) {

OpenPandaWidget::OpenPandaWidget(AbstractStream **stream) : AbstractOpenStreamWidget(stream) {
form_layout = new QFormLayout(this);
if (can && dynamic_cast<PandaStream *>(can) != nullptr) {
form_layout->addWidget(new QLabel(tr("Already connected to %1.").arg(can->routeName())));
form_layout->addWidget(new QLabel("Close the current connection via [File menu -> Close Stream] before connecting to another Panda."));
QTimer::singleShot(0, [this]() { emit enableOpenButton(false); });
return;
}

QHBoxLayout *serial_layout = new QHBoxLayout();
serial_layout->addWidget(serial_edit = new QComboBox());

Expand Down Expand Up @@ -116,6 +128,7 @@ void OpenPandaWidget::buildConfigForm() {
Panda panda(serial.toStdString());
has_fd = (panda.hw_type == cereal::PandaState::PandaType::RED_PANDA) || (panda.hw_type == cereal::PandaState::PandaType::RED_PANDA_V2);
} catch (const std::exception& e) {
qDebug() << "failed to open panda" << serial;
has_panda = false;
}
}
Expand Down Expand Up @@ -170,13 +183,11 @@ void OpenPandaWidget::buildConfigForm() {
}

bool OpenPandaWidget::open() {
if (!config.serial.isEmpty()) {
auto panda_stream = std::make_unique<PandaStream>(qApp, config);
if (panda_stream->connect()) {
*stream = panda_stream.release();
return true;
}
try {
*stream = new PandaStream(qApp, config);
return true;
} catch (std::exception &e) {
QMessageBox::warning(nullptr, tr("Warning"), tr("Failed to connect to panda: '%1'").arg(e.what()));
return false;
}
QMessageBox::warning(nullptr, tr("Warning"), tr("Failed to connect to panda"));
return false;
}
5 changes: 3 additions & 2 deletions tools/cabana/streams/pandastream.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ class PandaStream : public LiveStream {
Q_OBJECT
public:
PandaStream(QObject *parent, PandaStreamConfig config_ = {});
bool connect();
~PandaStream() { stop(); }
static AbstractOpenStreamWidget *widget(AbstractStream **stream);
inline QString routeName() const override {
return QString("Live Streaming From Panda %1").arg(config.serial);
return QString("Panda: %1").arg(config.serial);
}

protected:
bool connect();
void streamThread() override;

std::unique_ptr<Panda> panda;
Expand Down
1 change: 1 addition & 0 deletions tools/cabana/streams/socketcanstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class SocketCanStream : public LiveStream {
Q_OBJECT
public:
SocketCanStream(QObject *parent, SocketCanStreamConfig config_ = {});
~SocketCanStream() { stop(); }
static AbstractOpenStreamWidget *widget(AbstractStream **stream);
static bool available();

Expand Down
5 changes: 3 additions & 2 deletions tools/cabana/streamselector.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "tools/cabana/streamselector.h"

#include <QDialogButtonBox>
#include <QFileDialog>
#include <QLabel>
#include <QPushButton>
Expand Down Expand Up @@ -31,7 +30,7 @@ StreamSelector::StreamSelector(AbstractStream **stream, QWidget *parent) : QDial
line->setFrameStyle(QFrame::HLine | QFrame::Sunken);
layout->addWidget(line);

auto btn_box = new QDialogButtonBox(QDialogButtonBox::Open | QDialogButtonBox::Cancel);
btn_box = new QDialogButtonBox(QDialogButtonBox::Open | QDialogButtonBox::Cancel);
layout->addWidget(btn_box);

addStreamWidget(ReplayStream::widget(stream));
Expand Down Expand Up @@ -60,4 +59,6 @@ StreamSelector::StreamSelector(AbstractStream **stream, QWidget *parent) : QDial

void StreamSelector::addStreamWidget(AbstractOpenStreamWidget *w) {
tab->addTab(w, w->title());
auto open_btn = btn_box->button(QDialogButtonBox::Open);
QObject::connect(w, &AbstractOpenStreamWidget::enableOpenButton, open_btn, &QPushButton::setEnabled);
}
2 changes: 2 additions & 0 deletions tools/cabana/streamselector.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <QDialogButtonBox>
#include <QDialog>
#include <QLineEdit>
#include <QTabWidget>
Expand All @@ -17,4 +18,5 @@ class StreamSelector : public QDialog {
private:
QLineEdit *dbc_file;
QTabWidget *tab;
QDialogButtonBox *btn_box;
};
2 changes: 1 addition & 1 deletion tools/sim/bridge/metadrive/metadrive_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def get_cam_as_rgb(cam):
cam.get_cam().reparentTo(env.vehicle.origin)
cam.get_cam().setPos(C3_POSITION)
cam.get_cam().setHpr(C3_HPR)
img = cam.perceive(clip=False)
img = cam.perceive(to_float=False)
if type(img) != np.ndarray:
img = img.get() # convert cupy array to numpy
return img
Expand Down

0 comments on commit 41b96dc

Please sign in to comment.