48 lines
1.0 KiB
C++
48 lines
1.0 KiB
C++
#include "tools.h"
|
|
|
|
#include <cstdlib>
|
|
#include <unistd.h>
|
|
#include <limits.h>
|
|
#include <thread>
|
|
#include <chrono>
|
|
#include <iostream>
|
|
|
|
namespace tools {
|
|
|
|
std::string get_cwd() {
|
|
char buf[PATH_MAX];
|
|
if (getcwd(buf, sizeof(buf)) != nullptr) return std::string(buf);
|
|
return std::string(".");
|
|
}
|
|
|
|
std::string get_actions_record_path()
|
|
{
|
|
// 统一的动作记录文件路径,供机械臂+灵巧手联合示教等模块使用
|
|
return get_cwd() + std::string("/../actions/recorded_points.csv");
|
|
}
|
|
|
|
void clear_screen() {
|
|
std::system("clear");
|
|
}
|
|
|
|
void sleep_ms(uint32_t ms)
|
|
{
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
|
|
}
|
|
|
|
std::string trim(const std::string &s)
|
|
{
|
|
size_t start = s.find_first_not_of(" \t\r\n");
|
|
if (start == std::string::npos) return std::string();
|
|
size_t end = s.find_last_not_of(" \t\r\n");
|
|
return s.substr(start, end - start + 1);
|
|
}
|
|
|
|
std::string get_line_trimmed() {
|
|
std::string s;
|
|
if (!std::getline(std::cin, s)) return std::string();
|
|
return trim(s);
|
|
}
|
|
|
|
} // namespace tools
|