Skip to content

Add Error Handling and BIT - #82

Open
mchoo7 wants to merge 79 commits into
mainfrom
feature/error-handling
Open

mchoo7 wants to merge 79 commits into
mainfrom
feature/error-handling

Conversation

@mchoo7

@mchoo7 mchoo7 commented Oct 31, 2025

Copy link
Copy Markdown

This PR adds error handling as defined in ZP_Error. It also adds an independent PBIT and CBIT module to report different severities of different errors. This reduces the amount of logic in SM, AM, and TM needed for error handling.

This PR also raises the standard from C++14 to C++17.

Comment thread stm32h753iitx/boardfiles/drivers/gps/gps.hpp Outdated
Comment thread stm32l552xx/boardfiles/drivers/gps/gps.cpp Outdated
Comment thread stm32l552xx/boardfiles/drivers/gps/gps.cpp Outdated
Comment thread stm32l552xx/boardfiles/drivers/logger/logger.cpp Outdated
Comment thread stm32l552xx/boardfiles/drivers/logger/logger.cpp Outdated
Comment thread stm32l552xx/boardfiles/rtos/threads/src/unified_threads.cpp Outdated
Comment thread zeropilot4.0/include/error.h Outdated
Comment thread zeropilot4.0/include/thread_msgs/tm_queue.hpp Outdated
Comment thread zeropilot4.0/src/attitude_manager/direct_mapping.cpp Outdated
Comment thread zeropilot4.0/src/attitude_manager/pid.cpp Outdated
@Rosnaky Rosnaky changed the title feat: implement error handling Add Error Handling Jun 16, 2026
@smzalam
smzalam force-pushed the feature/error-handling branch from 1b2e853 to 7db5e3f Compare June 17, 2026 03:39
Both boards still called the pre-merge ZP_PARAM::get(id) single-argument form
when deciding whether to construct the rangefinder. hwbuild.bash does not
compile boardfiles (it builds only libzeropilot4.0.a), so the library build
could not catch this; it surfaced from a direct arm-none-eabi-g++ syntax pass
over every boardfile in both vehicle configurations.
Comment thread zeropilot4.0/src/bit/zp_bit.cpp Outdated
Comment thread zeropilot4.0/src/bit/zp_bit.cpp Outdated
Comment thread zeropilot4.0/include/bit/zp_bit.hpp Outdated
Comment thread stm32l552xx/boardfiles/drivers/barometer/icp_20100.cpp Outdated
constexpr ZP_Error ZP_ERROR_MEMORY_OVERFLOW {1u << 13}; // Buffer or FIFO queue overflow
constexpr ZP_Error ZP_ERROR_TIMEOUT {1u << 14}; // Operation timed out
constexpr ZP_Error ZP_ERROR_NACK {1u << 15}; // Peripheral did not acknowledge
constexpr ZP_Error ZP_ERROR_EXT_API {1u << 16}; // OR'd with a code above: failure came from HAL/RTOS/FatFs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would suggest ZP_ERROR_INVALID_ID or something along those lines so that instead of returning ZP_ERROR_FAIL for invalid ID access, we return a more specific error code.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would there be a scenario where ZP_ERROR_INVALID_ARG would not suffice

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah if an ID doesnt exist, invalid ARG might indicate that there was something wrong with the argument used rather than an ID, say a CAN node ID, doesn't exist. it's clearer what's happening, no reason to not have it

@Rosnaky Rosnaky Sep 18, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a scenario where we ever encounter an invalid CAN ID. I also don't think there is an existing module that could return this as an error code. I think it would be better to introduce this error when it is actually used rather than having a whole bunch of error codes that never get used

Comment thread stm32l552xx/boardfiles/drivers/iwdg/iwdg.cpp
Comment thread stm32l552xx/boardfiles/drivers/rangefinder/tf02pro.cpp Outdated
Comment thread zeropilot4.0/include/driver_ifaces/power_module_iface.hpp Outdated
Comment thread zeropilot4.0/src/attitude_manager/MahonyAHRS.cpp
Comment thread zeropilot4.0/src/zp_param/zp_params.cpp Outdated
@@ -0,0 +1,170 @@
#include "zp_bit.hpp"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename bit folder to zp_bit to match param and error folders?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

constexpr ZP_Error ZP_ERROR_MEMORY_OVERFLOW {1u << 13}; // Buffer or FIFO queue overflow
constexpr ZP_Error ZP_ERROR_TIMEOUT {1u << 14}; // Operation timed out
constexpr ZP_Error ZP_ERROR_NACK {1u << 15}; // Peripheral did not acknowledge
constexpr ZP_Error ZP_ERROR_EXT_API {1u << 16}; // OR'd with a code above: failure came from HAL/RTOS/FatFs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah if an ID doesnt exist, invalid ARG might indicate that there was something wrong with the argument used rather than an ID, say a CAN node ID, doesn't exist. it's clearer what's happening, no reason to not have it

@Rosnaky
Rosnaky force-pushed the feature/error-handling branch from 1f77790 to 97d32d9 Compare September 18, 2026 04:28
@Rosnaky
Rosnaky force-pushed the feature/error-handling branch from 938616b to ba6f217 Compare September 18, 2026 06:07

@Penguronik Penguronik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just had a few quick qs nonblocking, nice stuff

}

// Reception is aborted by the error, and nothing else would ever start it again
(void)telemLinkHandle->restartRx();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this too silent? Any chance we can log it somewhere or just have a clear TODO for logging it somewhere after logging pr gets merged so we dont miss it

cmake_minimum_required(VERSION 3.12)
project(zeropilot4.0)

set(CMAKE_CXX_STANDARD 17)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason we're upping the standard btw, its ok just curious

#include "unit_conversions.hpp"
#include <limits>

static inline float readParam(ZP_Error &result, ZP_PARAM_ID id) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this AM specific or something youd want to be more general?

ScaledImuBatch_t scaledImuData = {};
ZP_Error imuStatus = imuDriver->readRawData(imuData);
imuStatus |= imuDriver->scaleIMUData(imuData, scaledImuData);
(void)imuStatus;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whats the point of this line imuStatus gets used later it seems

setArmFlag = false;

systemUtilsDriver->profilerEnd(profilerId);
return;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really this prs concern i guess but single point of return would be nice since we have stuff like profiler that we need to remember calling before a return statement

if (REPORT_TICK) {
const MAV_SEVERITY SEVERITY = (BIT_CONFIG[i].level == BitLevel_e::CRITICAL) ? MAV_SEVERITY_CRITICAL : MAV_SEVERITY_WARNING;
result |= sendStatusTextToTelemetryManager(SEVERITY, BIT_HANDLERS[i].failText);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok so no more function ptrs and any action would be taken for like disarm in here then? As well as maybe any other manager would check this bit and act themselves as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants