Coding in c/c++,there is a very detailed thing: when we declare a variable,especially the member variable of a c++ class, we assume that variable is initialized automatically,but it is not in sometimes,it depends on the compiler.
For example,there is a Motor class in master_board project:
class Motor
{
double kp; // [A/rad]
double kd; // [As/rad]
}
Motor::Motor()
{
position = 0;
position_offset = 0;
velocity = 0;
current = 0;
is_enabled = false;
is_ready = false;
index_toggle_bit = false;
has_index_been_detected = false;
enable = false;
enable_position_rollover_error = false;
enable_index_toggle_bit = false;
enable_index_offset_compensation = false;
}
kp,kd are not explicitly initialized in its constructor,then kp,kd may not be zero sometimes,this will cause a wicked bug.
I have been testing blmc_drivers,master_board_sdk in Centos,ubuntu,and raspberry pi,met this situation happen time to times,especially on those OS without large memory,like raspberry pi.
I think it is a good habit that initialize all variables explicitly.