Skip to main content
Version: 4.0.0-beta.5

Health Check

ez::health checks that the IMU (and, with more than one, that they agree), every drive motor, every configured odom tracker, and every device you've registered with device_add() is responding, before you rely on them in a match.

Functions​

preflight()​

Checks that the IMU, every drive motor, every configured odom tracker, and every device registered with device_add() responds. Prints each failure, with its port where the device has one, and rumbles the controller when anything is wrong.

Safe to call from initialize() and again at the start of autonomous().

chassis your drive
controller the controller to rumble on failure

ez::health::Report preflight(ez::Drive& chassis, pros::Controller& controller);

device_add()​

Registers a smart device (a motor that isn't on the drive, or a distance, rotation, or optical sensor - anything deriving from pros::Device) for inclusion in preflight() checks.

A null device is ignored, and a null name is reported as "unnamed device".

device the sensor or motor to watch
name a label used when it fails a check

void device_add(pros::Device* device, const char* name);

preflight_register()​

Adds a "Health Check" page to the auton selector, so preflight() can be run from the brain instead of from code. Call this in initialize(), after ez::as::initialize().

This is only a convenience - preflight() is an ordinary function, so calling it from an opcontrol button works just as well, for example:

if (master.get_digital_new_press(DIGITAL_Y)) ez::health::preflight(chassis, master);

chassis your drive

void preflight_register(ez::Drive& chassis);

Report​

preflight() returns a Report. Temperature and IMU disagreement are warnings rather than failures, so motors_hot, motors_warm and imu_max_drift_deg deliberately do not count against all_ok(). A drive motor at 55 C or more counts in motors_hot, because the V5 starts cutting motor power at that temperature. One from 45 C up to 55 C counts in motors_warm, which is still at full power. When everything else passes but a motor is hot or warm, or the IMUs disagree, the controller rumbles a short . instead of the --- it rumbles for a failure.

If you have two or more IMUs, preflight() also reports whether the good ones disagree with each other. imu_max_drift_deg is the number of degrees between the most and least agreeing IMU's scaled reading, once that spread has held above the threshold for about half a second. It is 0 while they agree, or when there are fewer than 2 good IMUs. This only reports, it never ejects an IMU or changes which one drives the heading, because with only two IMUs there is no way to tell which one drifted. The threshold defaults to 15 degrees, see imu_drift_threshold_set().

struct Report {
bool imu_ok = true;
int motors_bad = 0; // drive motors not responding
int motors_hot = 0; // drive motors hot enough to be losing power
int motors_warm = 0; // drive motors warm but still at full power
double imu_max_drift_deg = 0.0; // degrees the good IMUs disagree by, 0 when they agree
int trackers_bad = 0; // configured odom trackers not responding
int devices_bad = 0; // registered devices not responding
bool all_ok() const;
};