Skip to content

Maplab specific style

Florian Tschopp edited this page Jun 28, 2019 · 1 revision

Line breaks:

  • should be consistent per package.
  • can be either 80c or 100c.
  • lines should not be broken before 80/100c if the content fits.

LOG output:

  • LOG(INFO) should only be used in rare cases
    • to temporarily debug an algorithm
    • to display the status of a command
    • in independent executables or classes that are tightly coupled to only specific executables
  • Use VLOG(LEVEL) in all other cases.
  • LOG(X) output that was inserted for debugging, needs to be removed before opening a pull-request.
  • Multi-line strings should be concatenated using the stream operator.
VLOG(3) << "Computing the 512 x 512 covariance matrix "
        << "this might take a while."

In order to still be able to follow what your code is doing with VLOG messaging, you can turn on VLOG for individual files with the --vmodule flag. For example, to see ceres optimizer output, you would run vi_map_console with:

rosrun vi_batch_applications vi_map_console --vmodule=*optimizer*=3

--vmodule allows a comma separated list of values. For example: --vmodule=*optimizer*=3,loop*=3.

See this page for how to choose your log level.

Transformations and Rotations

The following equations hold:

A_v = q_A_B * B_v;  // The quaternion of rotation that takes vectors from frame B to frame A.
A_v = R_A_B * B_v;  // The rotation matrix that takes vectors from frame B to frame A.
A_p = T_A_B * B_p;  // The transformation that takes points from frame B to frame A.

Frames of reference:

Physical quantity notations

For Quaternions of rotation:

aslam::Quaternion q_A_B;  // The orientation of the B frame of ref. wrt. the A frame of ref. 

For Angle-Axis parameterization of a rotation:

aslam::AngleAxis aa_A_B;  // The orientation of the B frame of ref. wrt. the A frame of ref. 

For translational offsets:

aslam::Position3d p_A_B;  // The position of the B frame of ref. wrt. the A frame of ref. expressed in A

For bearing vectors:

Eigen::Vector3d bv_A_d;  // The bearing vector d expressed in frame A

For transformations:

aslam::Transformation T_A_B;  // The transformation that denotes the orienation and position of the B frame of ref. wrt. the A frame of ref.

For points:

Eigen::Matrix<double, 3, 1> p_G;  // Position of a point expressed in the global frame of reference.
Eigen::Matrix<double, 3, 1> p_G_fi;  // Position of feature/point i expressed in the global frame of reference.

For time indexed quantities:

aslam::Transformation T_A_Bk;    // The same as above but denoting the quantities of the frame B at time step k.
aslam::Transformation T_A_Bkm1;  // The same as above but denoting the quantities of the frame B at time step k-1.
aslam::Transformation T_A_Bkp1;  // The same as above but denoting the quantities of the frame B at time step k+1.

For indexing cameras, points etc:

Eigen::Matrix<double, 3, 1> p_G_Ci;  // The position of camera i expressed in the global frame of reference.
Eigen::Matrix<double, 3, 1> p_G_Cj;  // The position of camera j expressed in the global frame of reference.

For velocities:

Eigen::Matrix<double, 3, 1> v_G;  // A velocity expressed in the global frame of reference.

For rotational velocities:

Eigen::Matrix<double, 3, 1> w_I;  // A rotational velocity expressed in the IMU frame of reference.

For linear acceleration:

Eigen::Matrix<double, 3, 1> a_I;  // A linear acceleration expressed in the IMU frame of reference.

Gravity:

Eigen::Matrix<double, 3, 1> g_G(0, 0, 9.81);  // The gravity vector is an acceleration acting along the positive z axis of the global frame of reference.

Notations of other quantities

Probability:

double P_landmark_seen;  // Probability that landmark is seen.

Mutex notation

mutable Cache cache_;
RawContainerPtr const raw_container_;
IdSet available_ids_;

mutable std::mutex m_available_ids_;  // Specifically protects available_ids_ .
mutable std::mutex m_cache_and_raw_;  // Protects cache_ and raw_container_ .

For code that doesn't need to be very performing, consider using common::Monitor , which makes it impossible to access a variable without locking it:

common::Monitor<IdSet> available_ids_;
available_ids_.get()->emplace(id);

Check all pointer and function arguments:

All pointers to a function must be checked for null:

void runEvaluation(double* sum_positive_samples) {
  CHECK_NOTNULL(sum_positive_samples);
}

The same is true for std::functions:

std::function<void(int)> foo;
std::function<void(int)> bar = [](int){};

CHECK(foo);  // Fails.
CHECK(bar);  // Does not fail.

Don't pass shared-ptrs to functions unless they are reset inside:

Instead of doing this:

void trackVisualFeaturesInFrame(
    const std::shared_ptr<aslam::VisualFrame>& frame) { /* ... */}

Pass the argument as reference to const or by pointer.

If you need to reset the pointer inside the method, pass the shared-ptr by pointer:

void createNewVisualFrame(std::shared_ptr<aslam::VisualFrame>* frame) {
  CHECK_NOTNULL(frame);
  frame->reset(new aslam::VisualFrame(...));
}

Settings and result structs

To avoid long function parameter lists, write structs for passing in settings and result pointers as soon as either the settings or result pointer count exceeds 3. Apply the following rules:

  • Declare the struct inside the class that the function belongs to, so that the user doesn't have to search for the struct.
  • DO NOT provide any constructor that initializes the members based on constructor parameters. That would defeat the purpose of settings/result structs. These should be used as follows:
Class::SettingStruct settings;
settings.a = x;
settings.b = y;
// No need to set settings.c, since we'll just use the default value.
class_object.functions(settings);

Note that this allows users calling your functions without reading the manual; they can simply autocomplete the settings.

  • DO provide a default constructor that sets default values.
  • Result structs are a great way of taking the burden of allocating multiple result objects from the user. If possible, make all result vectors, sets etc. plain members of the results struct and pass a pointer to the results struct to your function. If you have use cases where results might go straight into other objects, pass pointers to those result objects to the settings or as function parameter instead of incorporating them in the result struct.

Clone this wiki locally