FDCL Param Class
FDCL Param Class

This library provides a C++ tool to read parameters from a text file, or save them to a text file.

Contents

  1. Basic Introduction
  2. Using the Class
  3. Contributing

Basic Introduction

Configuration File

The format of the compatible text file is illustrated by the following sample file saved as fdcl.cfg

1 UAV:
2  m: 2.5
3  J: 3, 0, 0, 0, 2, 0, 0, 0, 1
4 Control:
5  kR: 1.8
6  kW: 2.0
7 IMU:
8  dev: "/dev/tty"
9 I2C:
10  dev: "/dev/i2c"
11  addr: 50
12 GPS:
13  available: 1

The name of the parameter is composed of the group name, and the variable name. For example, in the above file, UAV is the group name and m is the variable name.

More precisely, if the new line begins with letters without any space, the letters before : are considered as the group. Or, if the new line begins with space (tab works too), the the letters between space and : are considered as the variable.

The parameter name is constructed by concatenating group and variable. Note that the variable names can be repeated if they do not belong to the same group.

The followig types are suppored for the parameter value:

  1. bool (0: false, 1: true)
  2. double
  3. integer
  4. string (nested in " ")
  5. Eigen double matrix of an arbitrary size

Note the string parameter should be nested in " ". For an eigen matrix, each row is concetanted in a single line, where each element is separated by , For example, in the above configuration file, the 3x3 matrix J is defined as

1 J = [ 3 2 1;
2  0 2 0;
3  0 0 1];

in the Matlab notation.

Usage

The usuage of the library is illustrated by the following sample code.

1 #include <iostream>
2 #include <string>
3 #include "Eigen/Dense"
4 
5 #include "fdcl/param.hpp"
6 
7 using namespace std;
8 
9 int main(void)
10 {
11  // define variables to store the variables read from
12  // the config file
13  double m;
14  string dev;
15  int addr;
16  Eigen::Matrix<double, 3, 3> J;
17  bool GPS;
18 
19  // initialize the FDCL param class
20  fdcl::param cfg;
21 
22  // open the config file
23  cfg.open("fdcl.cfg");
24 
25  // read variables
26  // Note: the **group** name and the **variable** name are
27  // joined with `.` in between.
28  cfg.read("UAV.m",m);
29  cout << "m=" << m << endl;
30 
31  cfg.read("UAV.J",J);
32  cout << "J=" << J << endl;
33 
34  cfg.read("IMU.dev",dev);
35  cout << "dev=" << dev << endl;
36 
37  cfg.read("GPS.available",GPS);
38  cout << "GPS=" << GPS << endl;
39 
40  // update variables already in the config file
41  cfg.save("I2C.addr",50);
42 
43  cfg.read("I2C.addr",addr);
44  cout << "addr=" << addr << endl;
45 
46  cfg.save("GPS.available",true);
47  cfg.read("GPS.available",GPS);
48  cout << "GPS=" << GPS << endl;
49 
50  // close the config file
51  cfg.close();
52 }

Using Eigen Matrices

The package supports Eigen matrices for save and read functions, which are declared as template functions. Therefore, those functions must be explicitly instantiated according to the particular type of the Eigen matrices used.

For example, the above example uses the Eigen marix type Eigen::Matrix<double, 3, 3>, and at the end of fdcl_param.cpp the following explicit istantiattion are included:

1 template void fdcl_param::read(const string param_name, Eigen::MatrixBase< Eigen::Matrix <double,3,3> >& M);
2 template void fdcl_param::save(const string param_name, Eigen::MatrixBase< Eigen::Matrix <double,3,3> >& M);

When using other types or sizes of Eigen matrices, the corresponding instantiations must be included at the end of param.cpp

What it does NOT do

back to content

Using the Class

To add this to class to your code, using CMake and cloning it as a git submodule is recommended. This instructions assumes that you are going to add your submodules to a directory named libraries in the main project directory. If your submodule directory is different, make sure to change the path wherever it says libraries. First, add this as a submodule in git.

1 cd 'main/project/dir'
2 git submodule add https://github.com/fdcl-gwu/fdcl_param.git ./libraries/fdcl_param
3 git submodule update --init --recursive

NOTE: Whenever you clone your main project, you must recursively update the submodules:

1 git submodule update --init --recursive

Now, in the main project's CMake file (CMakeLists.txt), do the followings:

1 include_directories(${PROJECT_SOURCE_DIR}/libraries/fdcl_param/include)
2 add_subdirectory(${PROJECT_SOURCE_DIR}/libraries/fdcl_param fdcl_param)

Also, whenever you make a file that uses fdcl_param class, add fdcl_param to the linker:

1 target_link_libraries(name/of/the/library/or/exec
2  PRIVATE fdcl_param
3 )

Then, you can simply call #include "fdcl/param.hpp" in your source/header files in the main directory.

back to content

Contributing

Generating the Documentation

Document generation is done with Doxygen If you do not have Doxygen, install it first

1 sudo apt-get install -y doxygen graphviz

Use Doxygen to generate the documentation

1 cd docs/Doxygen
2 doxygen Doxygen

This will generate the documentation. Commit and push to update the online documentation. back to contents

back to content