c++readfilelibconfig

Unable to find/read config file .conf - FileIOException


I'm trying to open and read a .conf file in my program using libconfig::readFile(), but it gives me always a FileIOException. I think that the program is unable to locate the file but I don't know where the problem is.

This is the .conf file code:

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; 
            };
          };

This is where I'm trying to open the file and read it:

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;
    }

Thanks in advance for any type of help.


Solution

  • It looks to me you are missing a / at the beginning of your home path.

    I.e., change:

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

    For:

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

    I take it you have checked the .conf file exists at:

    /home/nimblbot/tpik_ctr_algo/ctrl_rob_nimblbot/conf