无法 find/read 配置文件 .conf - FileIOException
Unable to find/read config file .conf - FileIOException
我正在尝试使用 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
我正在尝试使用 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