47int main(
int argc,
char** argv) {
48 google::ParseCommandLineFlags(&argc, &argv,
true);
51 FLAGS_alsologtostderr =
true;
54 AINFO <<
"The navigator configuration filename is: "
55 << FLAGS_navigator_config_filename;
58 AERROR <<
"Failed to parse " << FLAGS_navigator_config_filename;
63 std::vector<std::string> navigation_line_filenames;
65 AERROR <<
"Failed to get navigation file names.";
68 <<
" navigation_filename_1 navigation_filename_2 ...\n"
71 <<
" left.txt.smoothed right.txt.smoothed middle.txt.smoothed";
75 ADEBUG <<
"The flag \"navigator_down_sample\" is: "
80 for (
const std::string& filename : navigation_line_filenames) {
81 auto* navigation_path = navigation_info.add_navigation_path();
84 AWARN <<
"Failed to load file: " << filename;
87 AINFO <<
"The file: " << filename +
" is processed ";
88 navigation_path->set_path_priority(i);
89 navigation_path->mutable_path()->set_name(
"Navigation path " + i);
92 if (navigation_info.navigation_path_size() < 1) {
93 AERROR <<
"No navigation information is fetched.";
97 std::shared_ptr<apollo::cyber::Node> node(
100 FLAGS_navigation_topic);
106 static constexpr int kTransNum = 3;
109 if (trans_num > kTransNum) {
112 apollo::common::util::FillHeader(node->Name(), &navigation_info);
113 writer->Write(navigation_info);
114 ADEBUG <<
"Sending navigation info:" << navigation_info.DebugString();
123 int argc,
char** argv,
124 std::vector<std::string>* navigation_line_filenames) {
125 CHECK_NOTNULL(navigation_line_filenames);
126 bool initialized =
false;
129 navigation_line_filenames->resize(argc - 1);
130 for (
int i = 0; i < argc - 1; ++i) {
131 navigation_line_filenames->at(i) = argv[i + 1];
134 }
catch (
const std::exception& e) {
135 AERROR <<
"Failed to get navigation line filenames: " << e.what();
146 CHECK_NOTNULL(navigation_path);
148 std::ifstream ifs(filename, std::ios::in);
149 if (!ifs.is_open()) {
150 AERROR <<
"Failed to open " << filename;
153 std::string line_str;
154 double last_sampled_s = std::numeric_limits<double>::min();
155 double current_sampled_s = 0.0;
157 double current_kappa = 0.0;
158 int original_points_num = 0;
159 int down_sampled_points_num = 0;
160 const auto& sample_param = navigator_config.
sample_param();
161 while (std::getline(ifs, line_str)) {
163 auto json_obj = json::parse(line_str);
164 current_sampled_s = json_obj[
"s"];
165 current_kappa = json_obj[
"kappa"];
166 diff_s = std::fabs(current_sampled_s - last_sampled_s);
167 bool not_down_sampling =
169 ? diff_s >= sample_param.straight_sample_interval() ||
170 (diff_s >= sample_param.small_kappa_sample_interval() &&
171 std::fabs(current_kappa) > sample_param.small_kappa()) ||
172 (diff_s >= sample_param.middle_kappa_sample_interval() &&
173 std::fabs(current_kappa) > sample_param.middle_kappa()) ||
174 (diff_s >= sample_param.large_kappa_sample_interval() &&
175 std::fabs(current_kappa) > sample_param.large_kappa())
179 if (not_down_sampling || !navigation_path->has_path()) {
180 last_sampled_s = current_sampled_s;
181 auto* point = navigation_path->mutable_path()->add_path_point();
182 point->set_x(json_obj[
"x"]);
183 point->set_y(json_obj[
"y"]);
184 point->set_s(current_sampled_s);
185 point->set_theta(json_obj[
"theta"]);
186 point->set_kappa(current_kappa);
187 point->set_dkappa(json_obj[
"dkappa"]);
188 ++down_sampled_points_num;
189 ADEBUG <<
"down_sample_x: " << json_obj[
"x"]
190 <<
", down_sample_y: " << json_obj[
"y"];
192 ++original_points_num;
193 }
catch (
const std::exception& e) {
194 AERROR <<
"Failed to parse JSON data: " << e.what();
198 AINFO <<
"The number of original points is: " << original_points_num
199 <<
" and the number of down sampled points is: "
200 << down_sampled_points_num <<
" in the file: " << filename;
206 ACHECK(navigator_config.has_sample_param());
207 const auto& sample_param = navigator_config.
sample_param();
208 ACHECK(sample_param.has_straight_sample_interval());
209 ACHECK(sample_param.has_small_kappa_sample_interval());
210 ACHECK(sample_param.has_middle_kappa_sample_interval());
211 ACHECK(sample_param.has_large_kappa_sample_interval());
212 ACHECK(sample_param.has_small_kappa());
213 ACHECK(sample_param.has_middle_kappa());
214 ACHECK(sample_param.has_large_kappa());
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...