From 7dda65fb78ac538d27a9346423b3f6b9a0347798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20Fr=C3=B6hlich?= Date: Wed, 6 Nov 2024 23:00:17 +0100 Subject: [PATCH] Add the same compile flags as with ros2_controllers and fix errors (#219) --- CMakeLists.txt | 3 ++- src/limited_proxy.cpp | 18 +++++++++--------- src/pid.cpp | 4 ++-- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9786821c..8777918d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/src/limited_proxy.cpp b/src/limited_proxy.cpp index ecb11fa4..15669f1b 100644 --- a/src/limited_proxy.cpp +++ b/src/limited_proxy.cpp @@ -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. diff --git a/src/pid.cpp b/src/pid.cpp index 282aafb2..c1f23a12 100644 --- a/src/pid.cpp +++ b/src/pid.cpp @@ -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(dt) / 1e9); p_error_last_ = error; return computeCommand(error, error_dot_, dt); @@ -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(dt) / 1e9) * p_error_; if (gains.antiwindup_ && gains.i_gain_ != 0) { // Prevent i_error_ from climbing higher than permitted by i_max_/i_min_