/** * This file is part of SUPER * * Copyright 2025 Yunfan REN, MaRS Lab, University of Hong Kong, * Developed by Yunfan REN * for more information see . * If you use this code, please cite the respective publications as * listed on the above website. * * SUPER is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * SUPER is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with SUPER. If not, see . */ #include #include #include #include #include #include #include #include #include #include using namespace super_utils; using namespace fsm; using PointType = pcl::PointXYZI; namespace fs = std::filesystem; std::string format_time(const std::filesystem::file_time_type& file_time) { auto sys_time = std::chrono::system_clock::from_time_t( std::chrono::duration_cast(file_time.time_since_epoch()).count()); std::time_t cftime = std::chrono::system_clock::to_time_t(sys_time); std::stringstream ss; ss << std::put_time(std::localtime(&cftime), "%Y-%m-%d %H:%M:%S"); return ss.str(); } // 获取目录下最新修改的 .bin 文件 std::pair getLatestBinFile(const std::string& directory) { std::string latestFile; std::filesystem::file_time_type latestTime; try { for (const auto& entry : fs::directory_iterator(directory)) { if (entry.is_regular_file() && entry.path().extension() == ".bin") { auto currentModTime = fs::last_write_time(entry); if (latestFile.empty() || currentModTime > latestTime) { latestFile = entry.path().string(); latestTime = currentModTime; } } } if (latestFile.empty()) { throw std::runtime_error("No .bin files found in the directory."); } return {latestFile, format_time(latestTime)}; } catch (const std::exception& e) { std::cerr << "Error: " << e.what() << std::endl; return {"", ""}; } } int main(int argc, char** argv) { ros::init(argc, argv, "fsm_node"); ros::NodeHandle nh("~"); const std::string directory = LOG_FILE_DIR("replan_logs/"); auto [latestFile, latestTime] = getLatestBinFile(directory); if (!latestFile.empty()) { std::cout << "Latest .bin file: " << latestFile << std::endl; } else { std::cout << "No .bin file found." << std::endl; return 0; } ros_interface::RosInterface::Ptr ros_ptr = std::make_shared(nh); vector replan_logs; BinaryFileHandler>::load(latestFile, replan_logs); // read and plot sleep(5); ros::AsyncSpinner spinner(0); spinner.start(); // enable keyboard initscr(); // 启动 ncurses 模式 cbreak(); // 禁用行缓冲,立即传递按键 noecho(); // 不在终端显示按键 keypad(stdscr, TRUE); // 启用功能键支持(非必需,但推荐) nodelay(stdscr, TRUE); // 非阻塞模式,不等待输入 std::cout<<"Check sim time"<= replan_logs.size()) replan_id = replan_logs.size() - 1; }else if (ch == 'r'){ } else { continue; } } else { replan_id++; usleep(100000); } auto& replan = replan_logs[replan_id]; // system("clear"); fmt::print(" -- [Bench] Visualize replan ID: {}\n", replan_id); visualization_msgs::Marker del; visualization_msgs::MarkerArray arr; del.action = visualization_msgs::Marker::DELETEALL; arr.markers.push_back(del); ros_ptr->setVisualizationEn(true); // setup optimizer #define CONFIG_FILE_DIR(name) (std::string(std::string(ROOT_DIR) + "config/"+(name))) const std::string path = CONFIG_FILE_DIR("click.yaml"); auto cfg = traj_opt::Config(path,"exp_traj"); auto b_cfg = traj_opt::Config(path,"backup_traj"); ExpTrajOpt::Ptr exp_traj_opt = std::make_shared(cfg,ros_ptr); BackupTrajOpt::Ptr backup_traj_opt = std::make_shared(b_cfg,ros_ptr); Trajectory traj; replan.replanExpTrajectory(exp_traj_opt, traj); ros_ptr->vizExpTraj(traj); Trajectory backup_traj; replan.replanBackupTrajectory(backup_traj_opt, backup_traj); ros_ptr->vizBackupTraj(backup_traj); replan.visualize(ros_ptr); replan.print(); } ros::waitForShutdown(); return 0; }