@@ -59,19 +59,17 @@ void SteeringWheelDisplay::updateSteeringData(
59
59
const autoware_vehicle_msgs::msg::SteeringReport::ConstSharedPtr & msg)
60
60
{
61
61
try {
62
- // Assuming msg->steering_angle is the field you're interested in
63
- float steeringAngle = msg->steering_tire_angle ;
64
- // we received it as a radian value, but we want to display it in degrees
65
- steering_angle_ =
66
- (steeringAngle * -180 / M_PI) *
67
- 17 ; // 17 is the ratio between the steering wheel and the steering tire angle i assume
62
+ last_msg_ptr_ = msg;
63
+
64
+ steering_angle_ = msg->steering_tire_angle ;
68
65
} catch (const std::exception & e) {
69
66
// Log the error
70
67
std::cerr << " Error in processMessage: " << e.what () << std::endl;
71
68
}
72
69
}
73
70
74
- void SteeringWheelDisplay::drawSteeringWheel (QPainter & painter, const QRectF & backgroundRect)
71
+ void SteeringWheelDisplay::drawSteeringWheel (
72
+ QPainter & painter, const QRectF & backgroundRect, float handle_angle_scale_)
75
73
{
76
74
// Enable Antialiasing for smoother drawing
77
75
painter.setRenderHint (QPainter::Antialiasing, true );
@@ -80,7 +78,7 @@ void SteeringWheelDisplay::drawSteeringWheel(QPainter & painter, const QRectF &
80
78
QImage wheel = coloredImage (scaledWheelImage, gray);
81
79
82
80
// Rotate the wheel
83
- float steeringAngle = steering_angle_; // No need to round here
81
+ float steeringAngle = std::round (handle_angle_scale_ * (steering_angle_ / M_PI) * - 180.0 );
84
82
// Calculate the position
85
83
int wheelCenterX = backgroundRect.left () + wheel.width () + 54 + 54 ;
86
84
int wheelCenterY = backgroundRect.height () / 2 ;
@@ -99,16 +97,40 @@ void SteeringWheelDisplay::drawSteeringWheel(QPainter & painter, const QRectF &
99
97
// Draw the rotated image
100
98
painter.drawImage (drawPoint.x (), drawPoint.y (), rotatedWheel);
101
99
102
- QString steeringAngleStringAfterModulo = QString::number (fmod (steeringAngle, 360 ), ' f' , 0 );
100
+ std::ostringstream steering_angle_ss;
101
+ if (last_msg_ptr_) {
102
+ steering_angle_ss << std::fixed << std::setprecision (1 ) << steering_angle_ * 180.0 / M_PI
103
+ << " °" ;
104
+ } else {
105
+ steering_angle_ss << " N/A" ;
106
+ }
107
+
108
+ QString steeringAngleString = QString::fromStdString (steering_angle_ss.str ());
109
+ // if the string doesn't have a negative sign, add a space to the front of the string
110
+ // to align the text in both cases (negative and positive)
111
+ if (steeringAngleString[0 ] != ' -' ) {
112
+ steeringAngleString = " " + steeringAngleString;
113
+ }
103
114
104
115
// Draw the steering angle text
105
- QFont steeringFont (" Quicksand" , 9 , QFont::Bold);
116
+ QFont steeringFont (" Quicksand" , 8 , QFont::Bold);
106
117
painter.setFont (steeringFont);
107
118
painter.setPen (QColor (0 , 0 , 0 , 255 ));
108
- QRect steeringRect (
109
- wheelCenterX - wheelImage.width () / 2 , wheelCenterY - wheelImage.height () / 2 ,
110
- wheelImage.width (), wheelImage.height ());
111
- painter.drawText (steeringRect, Qt::AlignCenter, steeringAngleStringAfterModulo + " °" );
119
+ // QRect steeringRect(
120
+ // wheelCenterX - wheelImage.width() / 2 + 1, wheelCenterY - wheelImage.height() / 2,
121
+ // wheelImage.width(), wheelImage.height());
122
+ // painter.drawText(steeringRect, Qt::AlignCenter, steeringAngleString);
123
+
124
+ // Measure the text
125
+ QFontMetrics fontMetrics (steeringFont);
126
+ QRect textRect = fontMetrics.boundingRect (steeringAngleString);
127
+
128
+ // Center the text
129
+ int textX = wheelCenterX - textRect.width () / 2 ;
130
+ int textY = wheelCenterY - textRect.height () / 2 ;
131
+
132
+ QRect steeringRect (textX, textY, textRect.width (), textRect.height ());
133
+ painter.drawText (steeringRect, Qt::AlignCenter, steeringAngleString);
112
134
}
113
135
114
136
QImage SteeringWheelDisplay::coloredImage (const QImage & source, const QColor & color)
0 commit comments