39 {
40 std::lock_guard<std::mutex> lock(mutex_);
41 if (inited_) {
42 return true;
43 }
44
45 sensor_info_map_.clear();
46 distort_model_map_.clear();
47 undistort_model_map_.clear();
48
50
51 MultiSensorMeta sensor_list_proto;
53 AERROR <<
"Invalid MultiSensorMeta file: " << config_file;
54 return false;
55 }
56
57 auto AddSensorInfo = [this](const SensorMeta& sensor_meta_proto) {
58 SensorInfo sensor_info;
59 sensor_info.name = sensor_meta_proto.name();
60 sensor_info.type =
static_cast<SensorType>(sensor_meta_proto.type());
61 sensor_info.orientation =
63 sensor_info.frame_id = sensor_meta_proto.name();
64 sensor_info.is_main_sensor = sensor_meta_proto.is_main_sensor();
65
66 auto pair = sensor_info_map_.insert(
67 make_pair(sensor_meta_proto.name(), sensor_info));
68 if (!pair.second) {
69 AERROR <<
"Duplicate sensor name error.";
70 return false;
71 }
72
73 if (this->
IsCamera(sensor_info.type)) {
74 std::shared_ptr<BrownCameraDistortionModel> distort_model(
75 new BrownCameraDistortionModel());
76
77 auto intrinsic_file = IntrinsicPath(sensor_info.frame_id);
79 AERROR <<
"Failed to load camera intrinsic:" << intrinsic_file;
80 return false;
81 }
82 distort_model_map_.insert(make_pair(
83 sensor_meta_proto.name(),
84 std::dynamic_pointer_cast<BaseCameraDistortionModel>(distort_model)));
85 undistort_model_map_.insert(make_pair(sensor_meta_proto.name(),
86 distort_model->get_camera_model()));
87 }
88 return true;
89 };
90
91 for (const SensorMeta& sensor_meta_proto : sensor_list_proto.sensor_meta()) {
92 if (!AddSensorInfo(sensor_meta_proto)) {
93 AERROR <<
"Failed to add sensor_info: " << sensor_meta_proto.name();
94 return false;
95 }
96 }
97
98 inited_ = true;
99 AINFO <<
"Init sensor_manager success.";
100 return true;
101}
bool IsCamera(const std::string &name) const
bool GetProtoFromASCIIFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as ascii representation of protobufs,...
bool LoadBrownCameraIntrinsic(const std::string &yaml_file, base::BrownCameraDistortionModel *model)
SensorType
Sensor types are set in the order of lidar, radar, camera, ultrasonic Please make sure SensorType has...
std::string GetCommonConfigFile(const std::string &config_file)
Get the perception common config path