无法找到/读取配置文件.conf-FileIOException

Unable to find/read config file .conf - FileIOException

本文关键字:读取 配置文件 conf-FileIOException      更新时间:2023-10-16

我试图使用libconfig::readFile((打开并读取程序中的.conf文件,但它总是给我一个FileIOException。我认为程序无法定位文件,但我不知道问题出在哪里。

这是.conf文件代码:

controlLoopPeriod = 100.0;  # ms
saturationMax = [10.0];
saturationMin = [-10.0];

task = {  Linear_Velocity = {
type = 0;   # 0 equality, 1 inequality
gain = 1.0;
enable = true;
saturation = 10.0; 
};
};

priorityLevels = ( { name = "PL_JPosition";
tasks = ["Joint_Position"];
lambda = 0.0001;
threshold = 0.01; 
} 
);

actions = ( { name = "jPosition";
levels = ["PL_JPosition"]; 
} 
);

states = {  State_move = {
minHeadingError = 0.05;
maxHeadingError = 0.2; 
};
};

这就是我试图打开文件并阅读它的地方:

bool RobotPositionController::LoadConfiguration() { 
libconfig::Config confObj;
// Inizialization
std::string confPath = "home/nimblbot/tpik_ctr_algo/ctrl_rob_nimblbot";
confPath.append("/conf/");
confPath.append(fileName_);
std::cout << "PATH TO CONF FILE : " << confPath << std::endl;
// Read the file. If there is an error, report it and exit.
try {
confObj.readFile(confPath.c_str());
} catch (const libconfig::FileIOException& fioex) {
std::cerr << "I/O error while reading file: " << fioex.what() << std::endl;
return -1;
} catch (const libconfig::ParseException& pex) {
std::cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine() << " - " << pex.getError() << std::endl;
return -1;
}
conf_->ConfigureFromFile(confObj);
ConfigureTaskFromFile(tasksMap_, confObj);
ConfigurePriorityLevelsFromFile(actionManager_, tasksMap_, confObj);
// Set Saturation values for the iCAT (read from conf file)
iCat_->SetSaturation(conf_->saturationMin, conf_->saturationMax);
ConfigureActionsFromFile(actionManager_, confObj);
//insert states in the map
statesMap_.insert({ states::ID::jPos, stateJPosition_ });

ConfigureSatesFromFile(statesMap_, confObj);
//insert command in the map
commandsMap_.insert({ commands::ID::jPos, commandJPosition_ });

return true;
}

提前感谢您的任何帮助。

在我看来,您在主路径的开头缺少一个/

即,更改:

std::string confPath = "home/nimblbot/tpik_ctr_algo/ctrl_rob_nimblbot";

用于:

std::string confPath = "/home/nimblbot/tpik_ctr_algo/ctrl_rob_nimblbot";

我认为你已经检查了.conf文件存在于:

/home/nimblbot/tpik_ctr_algo/ctrl_rob_nimblbot/conf