From 4c41805a3d39b02ccf8c7814961ae98cf99fe9d2 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 27 May 2024 11:24:08 +1000 Subject: [PATCH] AC_PID: use NEW_NOTHROW for new(std::nothrow) --- libraries/AC_PID/AC_PID.cpp | 4 ++-- libraries/AC_PID/examples/AC_PID_test/AC_PID_test.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/AC_PID/AC_PID.cpp b/libraries/AC_PID/AC_PID.cpp index 166be7b7b3..3f6d22e562 100644 --- a/libraries/AC_PID/AC_PID.cpp +++ b/libraries/AC_PID/AC_PID.cpp @@ -162,7 +162,7 @@ void AC_PID::set_notch_sample_rate(float sample_rate) if (_notch_T_filter != 0) { if (_target_notch == nullptr) { - _target_notch = new NotchFilterFloat(); + _target_notch = NEW_NOTHROW NotchFilterFloat(); } AP_Filter* filter = AP::filters().get_filter(_notch_T_filter); if (filter != nullptr && !filter->setup_notch_filter(*_target_notch, sample_rate)) { @@ -174,7 +174,7 @@ void AC_PID::set_notch_sample_rate(float sample_rate) if (_notch_E_filter != 0) { if (_error_notch == nullptr) { - _error_notch = new NotchFilterFloat(); + _error_notch = NEW_NOTHROW NotchFilterFloat(); } AP_Filter* filter = AP::filters().get_filter(_notch_E_filter); if (filter != nullptr && !filter->setup_notch_filter(*_error_notch, sample_rate)) { diff --git a/libraries/AC_PID/examples/AC_PID_test/AC_PID_test.cpp b/libraries/AC_PID/examples/AC_PID_test/AC_PID_test.cpp index ad193a4aa3..0053c9b22e 100644 --- a/libraries/AC_PID/examples/AC_PID_test/AC_PID_test.cpp +++ b/libraries/AC_PID/examples/AC_PID_test/AC_PID_test.cpp @@ -70,8 +70,8 @@ void setup() void loop() { // setup (unfortunately must be done here as we cannot create a global AC_PID object) - AC_PID *pid = new AC_PID(TEST_P, TEST_I, TEST_D, 0.0f, TEST_IMAX * 100.0f, 0.0f, 0.0f, TEST_FILTER); - // AC_HELI_PID *heli_pid= new AC_HELI_PID(TEST_P, TEST_I, TEST_D, TEST_INITIAL_FF, TEST_IMAX * 100, 0.0f, 0.0f, TEST_FILTER); + AC_PID *pid = NEW_NOTHROW AC_PID(TEST_P, TEST_I, TEST_D, 0.0f, TEST_IMAX * 100.0f, 0.0f, 0.0f, TEST_FILTER); + // AC_HELI_PID *heli_pid= NEW_NOTHROW AC_HELI_PID(TEST_P, TEST_I, TEST_D, TEST_INITIAL_FF, TEST_IMAX * 100, 0.0f, 0.0f, TEST_FILTER); // display PID gains hal.console->printf("P %f I %f D %f imax %f\n", (double)pid->kP(), (double)pid->kI(), (double)pid->kD(), (double)pid->imax());