From 0389bf521478d2e46ae7e9bb25c9d4f6cf6fa893 Mon Sep 17 00:00:00 2001 From: T Grinch <10247070+thenetworkgrinch@users.noreply.github.com> Date: Wed, 7 Sep 2022 11:01:55 -0500 Subject: [PATCH] [hal] REVPH: Improve handling of disconnected CAN Bus (#4169) Force the status to be 0 (no error) upon initialization of the REV PneumaticHub. This prevents a program crash in the case of a robot code restart with no CAN Bus present. --- hal/src/main/native/athena/CTREPCM.cpp | 4 +++- hal/src/main/native/athena/REVPH.cpp | 10 +++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/hal/src/main/native/athena/CTREPCM.cpp b/hal/src/main/native/athena/CTREPCM.cpp index 5f42322325..79c1ae3983 100644 --- a/hal/src/main/native/athena/CTREPCM.cpp +++ b/hal/src/main/native/athena/CTREPCM.cpp @@ -233,9 +233,11 @@ void HAL_SetCTREPCMClosedLoopControl(HAL_CTREPCMHandle handle, HAL_Bool enabled, return; } + int32_t can_status = 0; + std::scoped_lock lock{pcm->lock}; pcm->control.bits.closedLoopEnable = enabled ? 1 : 0; - SendControl(pcm.get(), status); + SendControl(pcm.get(), &can_status); } HAL_Bool HAL_GetCTREPCMClosedLoopControl(HAL_CTREPCMHandle handle, diff --git a/hal/src/main/native/athena/REVPH.cpp b/hal/src/main/native/athena/REVPH.cpp index a3790cc606..ae3f460cc8 100644 --- a/hal/src/main/native/athena/REVPH.cpp +++ b/hal/src/main/native/athena/REVPH.cpp @@ -228,20 +228,20 @@ HAL_REVPHHandle HAL_InitializeREVPH(int32_t module, sizeof(hph->desiredSolenoidsState)); std::memset(&hph->versionInfo, 0, sizeof(hph->versionInfo)); + int32_t can_status = 0; + // Start closed-loop compressor control by starting solenoid state updates - HAL_SendREVPHSolenoidsState(hph.get(), status); + HAL_SendREVPHSolenoidsState(hph.get(), &can_status); return handle; } void HAL_FreeREVPH(HAL_REVPHHandle handle) { auto hph = REVPHHandles->Get(handle); - if (hph == nullptr) { - return; + if (hph) { + HAL_CleanCAN(hph->hcan); } - HAL_CleanCAN(hph->hcan); - REVPHHandles->Free(handle); }