Qt: show current calibration values (#20455)
* show current calibration * read calibration from capnp * use CalStatus * cleanup calibrationd.py * remove import capnp * keep json writing,remove comment * fix test error * cleanup * remove test_read_saved_params * cleanup * write out capnp * restore test * clean up * get calibration from CalibrationParams * cleanup * update calibration when the description is visible * cleanup Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: Comma Device <device@comma.ai>albatross
parent
795b9ab35e
commit
57fe8488ac
|
@ -80,7 +80,7 @@ class Calibrator():
|
||||||
rpy_init = list(msg.liveCalibration.rpyCalib)
|
rpy_init = list(msg.liveCalibration.rpyCalib)
|
||||||
valid_blocks = msg.liveCalibration.validBlocks
|
valid_blocks = msg.liveCalibration.validBlocks
|
||||||
except (ValueError, capnp.lib.capnp.KjException):
|
except (ValueError, capnp.lib.capnp.KjException):
|
||||||
# TODO: remove this when offroad can read capnp
|
# TODO: remove this after next release
|
||||||
calibration_params = json.loads(calibration_params)
|
calibration_params = json.loads(calibration_params)
|
||||||
rpy_init = calibration_params["calib_radians"]
|
rpy_init = calibration_params["calib_radians"]
|
||||||
valid_blocks = calibration_params['valid_blocks']
|
valid_blocks = calibration_params['valid_blocks']
|
||||||
|
@ -134,10 +134,7 @@ class Calibrator():
|
||||||
|
|
||||||
write_this_cycle = (self.idx == 0) and (self.block_idx % (INPUTS_WANTED//5) == 5)
|
write_this_cycle = (self.idx == 0) and (self.block_idx % (INPUTS_WANTED//5) == 5)
|
||||||
if self.param_put and write_this_cycle:
|
if self.param_put and write_this_cycle:
|
||||||
# TODO: change to raw bytes when offroad can read capnp
|
put_nonblocking("CalibrationParams", self.get_msg().to_bytes())
|
||||||
cal_params = {"calib_radians": list(self.rpy),
|
|
||||||
"valid_blocks": int(self.valid_blocks)}
|
|
||||||
put_nonblocking("CalibrationParams", json.dumps(cal_params).encode('utf8'))
|
|
||||||
|
|
||||||
def handle_v_ego(self, v_ego):
|
def handle_v_ego(self, v_ego):
|
||||||
self.v_ego = v_ego
|
self.v_ego = v_ego
|
||||||
|
|
|
@ -93,12 +93,34 @@ DevicePanel::DevicePanel(QWidget* parent) : QWidget(parent) {
|
||||||
GLWindow::ui_state.scene.driver_view = true; }
|
GLWindow::ui_state.scene.driver_view = true; }
|
||||||
));
|
));
|
||||||
|
|
||||||
offroad_btns.append(new ButtonControl("Reset Calibration", "RESET",
|
QString resetCalibDesc = "openpilot requires the device to be mounted within 4° left or right and within 5° up or down. openpilot is continuously calibrating, resetting is rarely required.";
|
||||||
"openpilot requires the device to be mounted within 4° left or right and within 5° up or down. openpilot is continuously calibrating, resetting is rarely required.", [=]() {
|
ButtonControl *resetCalibBtn = new ButtonControl("Reset Calibration", "RESET", resetCalibDesc, [=]() {
|
||||||
if (ConfirmationDialog::confirm("Are you sure you want to reset calibration?")) {
|
if (ConfirmationDialog::confirm("Are you sure you want to reset calibration?")) {
|
||||||
Params().remove("CalibrationParams");
|
Params().remove("CalibrationParams");
|
||||||
}
|
}
|
||||||
}));
|
});
|
||||||
|
connect(resetCalibBtn, &ButtonControl::showDescription, [=]() {
|
||||||
|
QString desc = resetCalibDesc;
|
||||||
|
std::string calib_bytes = Params().get("CalibrationParams");
|
||||||
|
if (!calib_bytes.empty()) {
|
||||||
|
try {
|
||||||
|
AlignedBuffer aligned_buf;
|
||||||
|
capnp::FlatArrayMessageReader cmsg(aligned_buf.align(calib_bytes.data(), calib_bytes.size()));
|
||||||
|
auto calib = cmsg.getRoot<cereal::Event>().getLiveCalibration();
|
||||||
|
if (calib.getCalStatus() != 0) {
|
||||||
|
double pitch = calib.getRpyCalib()[1] * (180 / M_PI);
|
||||||
|
double yaw = calib.getRpyCalib()[2] * (180 / M_PI);
|
||||||
|
desc += QString(" Your device is pointed %1° %2 and %3° %4.")
|
||||||
|
.arg(QString::number(std::abs(pitch), 'g', 1), pitch > 0 ? "up" : "down",
|
||||||
|
QString::number(std::abs(yaw), 'g', 1), yaw > 0 ? "right" : "left");
|
||||||
|
}
|
||||||
|
} catch (kj::Exception) {
|
||||||
|
qInfo() << "invalid CalibrationParams";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resetCalibBtn->setDescription(desc);
|
||||||
|
});
|
||||||
|
offroad_btns.append(resetCalibBtn);
|
||||||
|
|
||||||
offroad_btns.append(new ButtonControl("Review Training Guide", "REVIEW",
|
offroad_btns.append(new ButtonControl("Review Training Guide", "REVIEW",
|
||||||
"Review the rules, features, and limitations of openpilot", [=]() {
|
"Review the rules, features, and limitations of openpilot", [=]() {
|
||||||
|
|
|
@ -48,6 +48,9 @@ AbstractControl::AbstractControl(const QString &title, const QString &desc, cons
|
||||||
vlayout->addWidget(description);
|
vlayout->addWidget(description);
|
||||||
|
|
||||||
connect(title_label, &QPushButton::clicked, [=]() {
|
connect(title_label, &QPushButton::clicked, [=]() {
|
||||||
|
if (!description->isVisible()) {
|
||||||
|
emit showDescription();
|
||||||
|
}
|
||||||
description->setVisible(!description->isVisible());
|
description->setVisible(!description->isVisible());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,14 @@ QFrame *horizontal_line(QWidget *parent = nullptr);
|
||||||
class AbstractControl : public QFrame {
|
class AbstractControl : public QFrame {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
void setDescription(const QString &desc) {
|
||||||
|
if(description) description->setText(desc);
|
||||||
|
}
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void showDescription();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
AbstractControl(const QString &title, const QString &desc = "", const QString &icon = "", QWidget *parent = nullptr);
|
AbstractControl(const QString &title, const QString &desc = "", const QString &icon = "", QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue