Skip to content

Commit

Permalink
Add the same compile flags as with ros2_controllers and fix errors (#219
Browse files Browse the repository at this point in the history
)
  • Loading branch information
christophfroehlich authored Nov 6, 2024
1 parent 795b9e6 commit 7dda65f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ cmake_minimum_required(VERSION 3.16)
project(control_toolbox LANGUAGES CXX)

if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
add_compile_options(-Wall -Wextra -Wpedantic)
add_compile_options(-Wall -Wextra -Wpedantic -Werror=conversion -Werror=unused-but-set-variable
-Werror=return-type -Werror=shadow -Werror=format)
endif()

if(WIN32)
Expand Down
18 changes: 9 additions & 9 deletions src/limited_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ double LimitedProxy::update(
{
// Get the parameters. This ensures that they can not change during
// the calculations and are non-negative!
double mass = abs(mass_); // Estimate of the joint mass
double Kd = abs(Kd_); // Damping gain
double Kp = abs(Kp_); // Position gain
double Ki = abs(Ki_); // Integral gain
double Ficl = abs(Ficl_); // Integral force clamp
double Flim = abs(effort_limit_); // Limit on output force
double vlim = abs(vel_limit_); // Limit on velocity
double lam = abs(lambda_proxy_); // Bandwidth of proxy reconvergence
double acon = abs(acc_converge_); // Acceleration of proxy reconvergence
double mass = std::abs(mass_); // Estimate of the joint mass
double Kd = std::abs(Kd_); // Damping gain
double Kp = std::abs(Kp_); // Position gain
double Ki = std::abs(Ki_); // Integral gain
double Ficl = std::abs(Ficl_); // Integral force clamp
double Flim = std::abs(effort_limit_); // Limit on output force
double vlim = std::abs(vel_limit_); // Limit on velocity
double lam = std::abs(lambda_proxy_); // Bandwidth of proxy reconvergence
double acon = std::abs(acc_converge_); // Acceleration of proxy reconvergence

// For numerical stability, upper bound the bandwidth by 2/dt.
// Note this is safe for dt==0.
Expand Down
4 changes: 2 additions & 2 deletions src/pid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ double Pid::computeCommand(double error, uint64_t dt)
error_dot_ = d_error_;

// Calculate the derivative error
error_dot_ = (error - p_error_last_) / (dt / 1e9);
error_dot_ = (error - p_error_last_) / (static_cast<double>(dt) / 1e9);
p_error_last_ = error;

return computeCommand(error, error_dot_, dt);
Expand All @@ -155,7 +155,7 @@ double Pid::computeCommand(double error, double error_dot, uint64_t dt)
p_term = gains.p_gain_ * p_error_;

// Calculate the integral of the position error
i_error_ += (dt / 1e9) * p_error_;
i_error_ += (static_cast<double>(dt) / 1e9) * p_error_;

if (gains.antiwindup_ && gains.i_gain_ != 0) {
// Prevent i_error_ from climbing higher than permitted by i_max_/i_min_
Expand Down

0 comments on commit 7dda65f

Please sign in to comment.