15 #include <sensor_msgs/image_encodings.hpp>
27 rclcpp::Node(
"LaneDetectionGTNode"), m_mapDataLayer(1) {
28 log(
"Initializing LaneDetectionGT-Node...");
31 std::string configPath =
"settings/onstartup_simulation_lanedetection_config.conf";
34 int configGTKeepLast = std::stoi(configMap->at(
"groundtruthKeepLast"));
37 log(
"Configuration (", configPath,
"):",
"\n",
39 " - GroundtruthKeepLast: ", configGTKeepLast,
"\n",
43 rclcpp::QoS qos_params = rclcpp::QoS(rclcpp::KeepLast(configGTKeepLast), qos_profile_default);
50 qos_params = get_qos_profile(QOS_BEST_EFFORT);
53 m_imgtransPub = image_transport::create_publisher(
this, TOPIC_VCI_LANE_IMAGE_SIMULATION);
57 log(
"Waiting for messages...");
82 int* groundtruthTileIterator;
102 if (p_message->id != *groundtruthTileIterator) {
103 if(p_message->id == 1 && *groundtruthTileIterator != -1) {
104 *groundtruthTileIterator = -1;
112 log(
"Left Line Groundtruth Message Received (", p_message->id,
")");
115 log(
"Center Line Groundtruth Message Received (", p_message->id,
")");
118 log(
"Right Line Groundtruth Message Received (", p_message->id,
")");
131 if (*groundtruthTileIterator != -1) {
132 *groundtruthTileIterator += 1;
141 Vector2f centerPoint =
Vector2f(p_message->points[0].x - p_message->points[2].x, p_message->points[0].y - p_message->points[2].y) / 2;
142 centerPoint[0] += p_message->points[2].x;
143 centerPoint[1] += p_message->points[2].y;
145 float width = std::fabs(p_message->points[0].x - p_message->points[1].x);
146 if (width <= 0.0001) {
147 width = std::fabs(p_message->points[0].y - p_message->points[1].y);
152 obstacle.
widthCM = width * 100;
154 m_obstacleMap.insert(std::pair<int, Obstacle>(p_message->id, obstacle));
156 log(
"Obstacle Message Received (", p_message->id,
") with Center Point [m] (x y): ", centerPoint[0],
" ", centerPoint[1],
" and Width [m]: ", width);
168 double siny_cosp = 2 * (p_message->orientation.w * p_message->orientation.z + p_message->orientation.x * p_message->orientation.y);
169 double cosy_cosp = 1 - 2 * (p_message->orientation.y * p_message->orientation.y + p_message->orientation.z * p_message->orientation.z);
170 double yaw = std::atan2(siny_cosp, cosy_cosp);
185 carPosOffToFrontAx = rotationMat * carPosOffToFrontAx;
198 log(
"Ready to start loop.");
212 std::shared_ptr<sensor_msgs::msg::Image> lineMessageUPtr = std::make_unique<sensor_msgs::msg::Image>();
220 if (effectiveWindowSize[0] < 0 || effectiveWindowSize[1] < 0)
log_warning(
"Effective Window Size not correct!");
224 lineMessageUPtr->encoding = sensor_msgs::image_encodings::RGB8;
225 lineMessageUPtr->is_bigendian = 0;
226 lineMessageUPtr->step = lineMessageUPtr->width * 3;
228 lineMessageUPtr->data.clear();
229 lineMessageUPtr->data.resize(lineMessageUPtr->step * lineMessageUPtr->height);
231 int linePointsAmountOnImage = 0;
237 for (
int i = 0; i < 3; ++i) {
238 for(
auto& [pointXRaw, pointsYVec] : lineMapObjPtr->
getPointsXY()) {
239 for (
auto& pointYRaw : pointsYVec) {
242 vec = lineObj->reverseRotationMatrix * vec;
245 int pointX = std::round(vec[0]) + lineMessageUPtr->width / 2;
246 int pointY = lineMessageUPtr->height - std::round(vec[1]);
249 if (pointX < 0 || pointY < 0 || pointX >= lineMessageUPtr->width || pointY >= lineMessageUPtr->height) {
254 int index = lineMessageUPtr->step * pointY + pointX * 3 + pixelByteIndex;
255 if(index >=
static_cast<int>(lineMessageUPtr->data.size()))
continue;
257 lineMessageUPtr->data[index] = 255;
259 linePointsAmountOnImage++;
261 catch (
const std::exception& ex) {
268 lineMapObjPtr = &lineObj->centerLine;
272 lineMapObjPtr = &lineObj->rightLine;
283 log(
"LineDetection Top View Image Message sent! LinePointsAmountOnImage: ", linePointsAmountOnImage);
288 std::unique_ptr<ObstacleListType> obstacleListUPtr = std::make_unique<ObstacleListType>();
291 bool obstacleFound =
false;
297 distanceToObstacleVec = rotationMat * distanceToObstacleVec;
299 if(distanceToObstacleVec[1] >= 0) {
302 obstacleListElt.pos_x = distanceToObstacleVec[0];
303 obstacleListElt.pos_x /= 100;
304 obstacleListElt.pos_y = distanceToObstacleVec[1];
305 obstacleListElt.pos_y /= 100;
306 obstacleListElt.width = obstacle.widthCM;
307 obstacleListElt.width /= 100;
309 obstacleListUPtr->obstacles.push_back(obstacleListElt);
311 log(
"[OBSTACLE] Found in FOV. Distance: ", distanceToObstacleVec.norm(),
" - Position x,y: ", distanceToObstacleVec[0],
",", distanceToObstacleVec[1]);
312 obstacleFound =
true;
321 log(
"Obstacle Detection Message sent!");