From 2e552b51e3333d6e2c6186defe8b8a15ad370f9d Mon Sep 17 00:00:00 2001 From: Agustin Alba Chicar Date: Wed, 27 Dec 2023 20:38:36 +0100 Subject: [PATCH] Fixes some compilation warnings. (#196) Signed-off-by: Agustin Alba Chicar --- andino_firmware/src/app.cpp | 5 +++-- andino_firmware/src/pcint.cpp | 2 +- andino_firmware/src/pcint.h | 2 ++ andino_firmware/src/pid.h | 27 +++++++++++++-------------- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/andino_firmware/src/app.cpp b/andino_firmware/src/app.cpp index 7917c59a..faf41ef7 100644 --- a/andino_firmware/src/app.cpp +++ b/andino_firmware/src/app.cpp @@ -296,15 +296,16 @@ void App::cmd_set_motors_pwm(const char* arg1, const char* arg2) { } void App::cmd_set_pid_tuning_gains(const char* arg1, const char*) { + static constexpr int kSizePidArgs{4}; int i = 0; char arg[20]; char* str; - int pid_args[4]; + int pid_args[kSizePidArgs]{0, 0, 0, 0}; // Example: "u 30:20:10:50". strcpy(arg, arg1); char* p = arg; - while ((str = strtok_r(p, ":", &p)) != NULL) { + while ((str = strtok_r(p, ":", &p)) != NULL && i < kSizePidArgs) { pid_args[i] = atoi(str); i++; } diff --git a/andino_firmware/src/pcint.cpp b/andino_firmware/src/pcint.cpp index 37bd7d93..ebc17b03 100644 --- a/andino_firmware/src/pcint.cpp +++ b/andino_firmware/src/pcint.cpp @@ -70,7 +70,7 @@ void PCInt::attach_interrupt(uint8_t pin, InterruptCallback callback) { *(kPortToPCMask[port]) |= bit_mask; // Set corresponding bit in the Pin Change Interrupt Control register. - PCICR |= 0x01 << port; + PCICR |= static_cast(0x01 << port); // Set callback function. g_callbacks[port] = callback; diff --git a/andino_firmware/src/pcint.h b/andino_firmware/src/pcint.h index 9d3c9210..27e4f891 100644 --- a/andino_firmware/src/pcint.h +++ b/andino_firmware/src/pcint.h @@ -49,6 +49,8 @@ class PCInt { static void attach_interrupt(uint8_t pin, InterruptCallback callback); private: + PCInt() = delete; + /// Map between ports and Pin Change Mask registers. static constexpr volatile uint8_t* kPortToPCMask[]{&PCMSK0, &PCMSK1, &PCMSK2}; }; diff --git a/andino_firmware/src/pid.h b/andino_firmware/src/pid.h index c78898e7..768f8cb7 100644 --- a/andino_firmware/src/pid.h +++ b/andino_firmware/src/pid.h @@ -48,8 +48,7 @@ class PID { ki_(ki), ko_(ko), output_min_(output_min), - output_max_(output_max), - enabled_(false) {} + output_max_(output_max) {} /// @brief Resets the PID controller. /// @@ -82,32 +81,32 @@ class PID { private: /// Tuning proportional gain. - int kp_; + int kp_{0}; /// Tuning derivative gain. - int kd_; + int kd_{0}; /// Tuning integral gain. - int ki_; + int ki_{0}; /// Tuning output gain. - int ko_; + int ko_{0}; /// Output minimum limit. - int output_min_; + int output_min_{0}; /// Output maximum limit. - int output_max_; + int output_max_{0}; /// True if the PID is enabled, false otherwise. - bool enabled_; + bool enabled_{false}; /// Setpoint value. - int setpoint_; + int setpoint_{0}; /// Accumulated integral term. - int integral_term_; + int integral_term_{0}; /// Last received encoder value. - long last_encoder_count_; + long last_encoder_count_{0}; /// Last computed input value. - int last_input_; + int last_input_{0}; /// Last computed output value. - long last_output_; + long last_output_{0}; }; } // namespace andino