openpilot is an open source driver assistance system. openpilot performs the functions of Automated Lane Centering and Adaptive Cruise Control for over 200 supported car makes and models.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

156 lines
3.9 KiB

#pragma once
#include <eigen3/Eigen/Dense>
#include <memory>
#include <string>
#include <QTimer>
#include <QColor>
#include <QFuture>
#include <QPolygonF>
#include "cereal/messaging/messaging.h"
#include "common/mat.h"
#include "common/params.h"
#include "common/util.h"
#include "system/hardware/hw.h"
#include "selfdrive/ui/qt/prime_state.h"
const int UI_BORDER_SIZE = 30;
const int UI_HEADER_HEIGHT = 420;
const int UI_FREQ = 20; // Hz
const int BACKLIGHT_OFFROAD = 50;
const float MIN_DRAW_DISTANCE = 10.0;
const float MAX_DRAW_DISTANCE = 100.0;
const Eigen::Matrix3f VIEW_FROM_DEVICE = (Eigen::Matrix3f() <<
0.0, 1.0, 0.0,
0.0, 0.0, 1.0,
1.0, 0.0, 0.0).finished();
const Eigen::Matrix3f FCAM_INTRINSIC_MATRIX = (Eigen::Matrix3f() <<
2648.0, 0.0, 1928.0 / 2,
0.0, 2648.0, 1208.0 / 2,
0.0, 0.0, 1.0).finished();
// tici ecam focal probably wrong? magnification is not consistent across frame
// Need to retrain model before this can be changed
const Eigen::Matrix3f ECAM_INTRINSIC_MATRIX = (Eigen::Matrix3f() <<
567.0, 0.0, 1928.0 / 2,
0.0, 567.0, 1208.0 / 2,
0.0, 0.0, 1.0).finished();
typedef enum UIStatus {
STATUS_DISENGAGED,
STATUS_OVERRIDE,
STATUS_ENGAGED,
} UIStatus;
const QColor bg_colors [] = {
[STATUS_DISENGAGED] = QColor(0x17, 0x33, 0x49, 0xc8),
[STATUS_OVERRIDE] = QColor(0x91, 0x9b, 0x95, 0xf1),
[STATUS_ENGAGED] = QColor(0x17, 0x86, 0x44, 0xf1),
};
Torch model (#2452) * refactor draw model * rebase master * correct valid_len * rename function * rename variables * white space * rebase to master * e16c13ac-927d-455e-ae0a-81b482a2c787 * start rewriting * save proress * compiles! * oops * many fixes * seems to work * fix desires * finally cleaned * wrong std for ll * dont pulse none * compiles! * ready to test * WIP does not compile * compiles * various fixes * does something! * full 3d * not needed * draw up to 100m * fix segfault * wrong sign * fix flicker * add road edges * finish v2 packet * Added pytorch supercombo * fix rebase * no more keras * Hacky solution to the NCHW/NHWC incompatibility between SNPE and our frame data * dont break dmonitoringd, final model 229e3ce1-7259-412b-85e6-cc646d70f1d8/430 * fix hack * Revert "fix hack" This reverts commit 5550fc01a7881d065a5eddbbb42dac55ef7ec36c. * Removed axis permutation hack * Folded padding layers into conv layers * Removed the last pad layer from the dlc * Revert "Removed the last pad layer from the dlc" This reverts commit b85f24b9e1d04abf64e85901a7ff49e00d82020a. * Revert "Folded padding layers into conv layers" This reverts commit b8d1773e4e76dea481acebbfad6a6235fbb58463. * vision model: 5034ac8b-5703-4a49-948b-11c064d10880/780 temporal model: 229e3ce1-7259-412b-85e6-cc646d70f1d8/430 with permute + pool opt * fix ui drawing with clips * ./compile_torch.py 5034ac8b-5703-4a49-948b-11c064d10880/780 dfcd2375-81d8-49df-95bf-1d2d6ad86010/450 with variable history length * std::clamp * not sure how this compiled before * 2895ace6-a296-47ac-86e6-17ea800a74e5/550 * db090195-8810-42de-ab38-bb835d775d87/601 * 5m is very little * onnx runner * add onnxruntime to pipfile * run in real time without using the whole CPU * bump cereal; * add stds * set road edge opacity based on stddev * don't access the model packet in paint * convert mat.h to a c++ header file (#2499) * update tests * safety first Co-authored-by: deanlee <deanlee3@gmail.com> Co-authored-by: mitchell <mitchell@comma.ai> Co-authored-by: Comma Device <device@comma.ai> Co-authored-by: George Hotz <george@comma.ai> Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> old-commit-hash: 08846b5c0ec3a5299c8cb73904da15a18d3aaccf
5 years ago
typedef struct UIScene {
Eigen::Matrix3f view_from_calib = VIEW_FROM_DEVICE;
Eigen::Matrix3f view_from_wide_calib = VIEW_FROM_DEVICE;
cereal::PandaState::PandaType pandaType;
UI: refactor model related functions (#19657) Squashed commit of the following: commit 7d7fb15e4cdd0e47fa38f949f79581dc611db015 Author: Willem Melching <willem.melching@gmail.com> Date: Wed Jan 6 11:31:09 2021 +0100 no extern commit 901893966e3f908435bceb8777253dfa916a3d91 Merge: 9816e01e c0703a57 Author: Willem Melching <willem.melching@gmail.com> Date: Wed Jan 6 11:27:29 2021 +0100 Merge branch 'master' into refactor_model_draw commit 9816e01e6ff0284521fa18b07ec15b3900577687 Author: deanlee <deanlee3@gmail.com> Date: Wed Jan 6 04:02:08 2021 +0000 fix lead_d commit 6fa500dbce26544cc3fdeb4d9b0d2d654382a40b Author: deanlee <deanlee3@gmail.com> Date: Tue Jan 5 13:18:20 2021 +0000 populate model data in update_socket commit e25db7e28c1b543a04c3e837aa44431c42dbb5b2 Author: deanlee <deanlee3@gmail.com> Date: Tue Jan 5 12:59:13 2021 +0000 update model in function commit 0834a3ffe7eaa080671f13c32dd6475ae5392d5b Author: deanlee <deanlee3@gmail.com> Date: Tue Jan 5 12:50:21 2021 +0000 continue commit 95b08679c2593eb0770a68b3cf1a59f1fb3b74f4 Author: Willem Melching <willem.melching@gmail.com> Date: Tue Jan 5 13:26:34 2021 +0100 Update selfdrive/ui/paint.cc commit 0eef065ae4f96c2ee5d97b4ccdfdbf0ae4945385 Author: Dean Lee <deanlee3@gmail.com> Date: Tue Jan 5 20:11:01 2021 +0800 Update selfdrive/ui/paint.cc Co-authored-by: Willem Melching <willem.melching@gmail.com> commit 955ad9b03a176174b86b28d5bb6f48d6e2a09281 Author: deanlee <deanlee3@gmail.com> Date: Thu Dec 31 04:45:31 2020 +0000 refactor model related functions old-commit-hash: 37cb4bec631197f6b369bf89f94786772bd05336
4 years ago
// modelV2
Torch model (#2452) * refactor draw model * rebase master * correct valid_len * rename function * rename variables * white space * rebase to master * e16c13ac-927d-455e-ae0a-81b482a2c787 * start rewriting * save proress * compiles! * oops * many fixes * seems to work * fix desires * finally cleaned * wrong std for ll * dont pulse none * compiles! * ready to test * WIP does not compile * compiles * various fixes * does something! * full 3d * not needed * draw up to 100m * fix segfault * wrong sign * fix flicker * add road edges * finish v2 packet * Added pytorch supercombo * fix rebase * no more keras * Hacky solution to the NCHW/NHWC incompatibility between SNPE and our frame data * dont break dmonitoringd, final model 229e3ce1-7259-412b-85e6-cc646d70f1d8/430 * fix hack * Revert "fix hack" This reverts commit 5550fc01a7881d065a5eddbbb42dac55ef7ec36c. * Removed axis permutation hack * Folded padding layers into conv layers * Removed the last pad layer from the dlc * Revert "Removed the last pad layer from the dlc" This reverts commit b85f24b9e1d04abf64e85901a7ff49e00d82020a. * Revert "Folded padding layers into conv layers" This reverts commit b8d1773e4e76dea481acebbfad6a6235fbb58463. * vision model: 5034ac8b-5703-4a49-948b-11c064d10880/780 temporal model: 229e3ce1-7259-412b-85e6-cc646d70f1d8/430 with permute + pool opt * fix ui drawing with clips * ./compile_torch.py 5034ac8b-5703-4a49-948b-11c064d10880/780 dfcd2375-81d8-49df-95bf-1d2d6ad86010/450 with variable history length * std::clamp * not sure how this compiled before * 2895ace6-a296-47ac-86e6-17ea800a74e5/550 * db090195-8810-42de-ab38-bb835d775d87/601 * 5m is very little * onnx runner * add onnxruntime to pipfile * run in real time without using the whole CPU * bump cereal; * add stds * set road edge opacity based on stddev * don't access the model packet in paint * convert mat.h to a c++ header file (#2499) * update tests * safety first Co-authored-by: deanlee <deanlee3@gmail.com> Co-authored-by: mitchell <mitchell@comma.ai> Co-authored-by: Comma Device <device@comma.ai> Co-authored-by: George Hotz <george@comma.ai> Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> old-commit-hash: 08846b5c0ec3a5299c8cb73904da15a18d3aaccf
5 years ago
float lane_line_probs[4];
float road_edge_stds[2];
QPolygonF track_vertices;
QPolygonF lane_line_vertices[4];
QPolygonF road_edge_vertices[2];
// lead
QPointF lead_vertices[2];
longitudinal personality: change via steering wheel distance button (#31792) * start at param * start by sending personality * change to personality * POC: button changes personality * what's wrong with this? * fix * not really possible but fuzzy test catches this * there's always a typo * dang, we're dropping messages * clean up * no comment * bump * rename * not all cars yet * works but at what cost * clean up * inside settings * write param so we save the distance button changes * setChecked activates buttonToggled and already writes param! * don't need this, we update from longitudinalPlan on changes * some clean up * more * ui * allow some time for ui to receive and write param * plannerd: only track changes in case no ui * Revert "plannerd: only track changes in case no ui" This reverts commit 2b081aa6ceb92c67a621b74592b2292756d29871. * write in plannerd as well, I assume this is atomic? * don't write when setting checked (only user clicks) * better nane * more * Update selfdrive/controls/lib/longitudinal_planner.py Co-authored-by: Cameron Clough <cameronjclough@gmail.com> * doesn't write param now * ParamWatcher is nice * no debug * Update translations * fix * odd drain sock proc replay behavior * vanish * Revert "odd drain sock proc replay behavior" This reverts commit 29b70b39413e1852bb512155af6b6a94a5bd9454. * add GM * only if OP long * move personality to controlsState, since eventually it won't be exclusive to long planner more bump * diff without translations * fix * put nonblocking * CS should start at up to date personality always (no ui flicker) * update toggle on cereal message change * fix * fix that * ubmp * mypy doesn't know this is an int :( * update translations * fix the tests --------- Co-authored-by: Cameron Clough <cameronjclough@gmail.com> old-commit-hash: 3d63c7093afec7ba24f447a44f02f7bea1f7282b
1 year ago
cereal::LongitudinalPersonality personality;
float light_sensor = -1;
bool started, ignition, is_metric, longitudinal_control;
bool world_objects_visible = false;
uint64_t started_frame;
} UIScene;
class UIState : public QObject {
Q_OBJECT
public:
UIState(QObject* parent = 0);
void updateStatus();
inline bool engaged() const {
return scene.started && (*sm)["selfdriveState"].getSelfdriveState().getEnabled();
}
std::unique_ptr<SubMaster> sm;
UIStatus status;
UIScene scene = {};
QString language;
PrimeState *prime_state;
Eigen::Matrix3f car_space_transform = Eigen::Matrix3f::Zero();
QRectF clip_region;
signals:
void uiUpdate(const UIState &s);
void offroadTransition(bool offroad);
private slots:
void update();
private:
QTimer *timer;
bool started_prev = false;
};
UIState *uiState();
// device management class
class Device : public QObject {
Q_OBJECT
public:
Device(QObject *parent = 0);
bool isAwake() { return awake; }
void setOffroadBrightness(int brightness) {
offroad_brightness = std::clamp(brightness, 0, 100);
}
private:
bool awake = false;
int interactive_timeout = 0;
bool ignition_on = false;
int offroad_brightness = BACKLIGHT_OFFROAD;
int last_brightness = 0;
FirstOrderFilter brightness_filter;
QFuture<void> brightness_future;
void updateBrightness(const UIState &s);
void updateWakefulness(const UIState &s);
void setAwake(bool on);
signals:
void displayPowerChanged(bool on);
void interactiveTimeout();
public slots:
void resetInteractiveTimeout(int timeout = -1);
void update(const UIState &s);
};
Device *device();
void ui_update_params(UIState *s);
int get_path_length_idx(const cereal::XYZTData::Reader &line, const float path_height);
void update_model(UIState *s,
const cereal::ModelDataV2::Reader &model);
void update_leads(UIState *s, const cereal::RadarState::Reader &radar_state, const cereal::XYZTData::Reader &line);
void update_line_data(const UIState *s, const cereal::XYZTData::Reader &line,
float y_off, float z_off, QPolygonF *pvd, int max_idx, bool allow_invert);