Display the steering torque in the screen's border
This commit is contained in:
@@ -15,7 +15,18 @@ void FrogPilotOnroadWindow::updateState(const UIState &s, const FrogPilotUIState
|
||||
const cereal::CarState::Reader &carState = sm["carState"].getCarState();
|
||||
const cereal::CarControl::Reader &carControl = fpsm["carControl"].getCarControl();
|
||||
|
||||
torque = -carControl.getActuators().getTorque();
|
||||
|
||||
showFPS = frogpilot_toggles.value("show_fps").toBool();
|
||||
showSteering = frogpilot_toggles.value("steering_metrics").toBool();
|
||||
|
||||
if (showSteering) {
|
||||
float absTorque = std::abs(torque);
|
||||
smoothedSteer = 0.25f * absTorque + 0.75f * smoothedSteer;
|
||||
if (std::abs(smoothedSteer - absTorque) < 0.01f) {
|
||||
smoothedSteer = absTorque;
|
||||
}
|
||||
}
|
||||
|
||||
if (showFPS) {
|
||||
static float avgFPS = 0.0f;
|
||||
@@ -48,6 +59,10 @@ void FrogPilotOnroadWindow::paintEvent(QPaintEvent *event) {
|
||||
p.setClipRegion(marginRegion);
|
||||
p.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
|
||||
|
||||
if (showSteering) {
|
||||
paintSteeringTorqueBorder(p);
|
||||
}
|
||||
|
||||
if (showFPS) {
|
||||
paintFPS(p);
|
||||
}
|
||||
@@ -66,3 +81,21 @@ void FrogPilotOnroadWindow::paintFPS(QPainter &p) {
|
||||
|
||||
p.restore();
|
||||
}
|
||||
|
||||
void FrogPilotOnroadWindow::paintSteeringTorqueBorder(QPainter &p) {
|
||||
p.save();
|
||||
|
||||
QLinearGradient gradient(rect.topLeft(), rect.bottomLeft());
|
||||
gradient.setColorAt(0.0, bg_colors[STATUS_TRAFFIC_MODE_ENABLED]);
|
||||
gradient.setColorAt(0.25, bg_colors[STATUS_EXPERIMENTAL_MODE_ENABLED]);
|
||||
gradient.setColorAt(0.5, bg_colors[STATUS_CEM_DISABLED]);
|
||||
gradient.setColorAt(0.75, bg_colors[STATUS_ENGAGED]);
|
||||
|
||||
int visibleHeight = rect.height() * smoothedSteer;
|
||||
int xPos = (torque < 0) ? rect.x() : (rect.x() + rect.width() - UI_BORDER_SIZE);
|
||||
int yPos = rect.y() + rect.height() - visibleHeight;
|
||||
|
||||
p.fillRect(QRect(xPos, yPos, UI_BORDER_SIZE, visibleHeight), gradient);
|
||||
|
||||
p.restore();
|
||||
}
|
||||
|
||||
@@ -21,9 +21,14 @@ public:
|
||||
private:
|
||||
void paintEvent(QPaintEvent *event);
|
||||
void paintFPS(QPainter &p);
|
||||
void paintSteeringTorqueBorder(QPainter &p);
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
|
||||
bool showFPS;
|
||||
bool showSteering;
|
||||
|
||||
float smoothedSteer;
|
||||
float torque;
|
||||
|
||||
QRect rect;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user