how optimize this code "bool TrafficLightImageVisualization::initialize() { char…
- User
how optimize this code "bool TrafficLightImageVisualization::initialize() { char hostname[65]; gethostname(hostname, sizeof(hostname)); updater_.setHardwareID(hostname);
std::string prefix = "diagnostics."; setMaxInputDelay(this->declare_parameter( prefix + "max_input_delay", 500L)); setMaxOutputDelay(this->declare_parameter( prefix + "max_output_delay", 500L)); setMaxProcessingTime(this->declare_parameter( prefix + "max_processing_time", 100L));
updater_.add("[Traffic Light Image Visualization] Status", this, &TrafficLightImageVisualization::diagnosticsCallback);
std::string subImgTopic = this->declare_parameterstd::string("sub_image_topic", ""); std::string subRoiTopic = this->declare_parameterstd::string("sub_roi_topic", ""); std::string subStatesTopic = this->declare_parameterstd::string("sub_states_topic", ""); std::string pubImageTopic = this->declare_parameterstd::string("pub_image_topic", "");
createSubscriptions(subImgTopic, subRoiTopic, subStatesTopic);
createPublisher(pubImageTopic);
findDetectorTopic_ = subRoiTopic.find("detected_objects");
iconWidth_ = this->declare_parameter<uint16_t >("icon_width", 0); iconHeight_ = this->declare_parameter<uint16_t >("icon_height", 0);
std::string iconsPath = this->declare_parameterstd::string("icons_path", ""); loadIcons(iconsPath);
return true; } "
- Assistant
- User
optimize this code "void TrafficLightImageVisualization::createSubscriptions(const std::string &subImgTopic, const std::string &subRoiTopic, const std::string &subStatesTopic) { if (subImgTopic.find("united_messages") != std::string::npos) { vc_image_sub_ = create_subscription<vc_messages::msg::Image>(subImgTopic, rclcpp::SensorDataQoS().keep_last(1), std::bind(&TrafficLightImageVisualization::unitedCallback, this, std::placeholders::1)); } else { image_sub = this->create_nami_subscription<sensor_msgs::msg::Image>(subImgTopic, rclcpp::SensorDataQoS().keep_last(1), std::bind(&TrafficLightImageVisualization::imageCallback, this, std::placeholders::_1)); }
roi_tl_sub_ = this->create_nami_subscription<nami_perception_msgs::msg::ObjectArray>(subRoiTopic, rclcpp::SensorDataQoS().keep_last(1), std::bind(&TrafficLightImageVisualization::roiCallback, this, std::placeholders::_1));
- Assistant