Skip to content

Commit 94d1839

Browse files
committed
please watchdog
1 parent 381eac1 commit 94d1839

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

pybricks/experimental/pb_module_experimental.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#define ACCEL_RAM
2222
#endif
2323

24-
// Manually defining the minimal internal structures to bypass header errors
24+
// Manually defining the minimal internal structures for cross-platform safety
2525
typedef struct _pb_type_Motor_obj_t {
2626
mp_obj_base_t base;
2727
pbio_tacho_t *tacho;
@@ -39,7 +39,7 @@ static const float HALF_PI_F = 1.570796326794896f;
3939
static const float INV_TWO_PI_F = 0.159154943091895f;
4040

4141
// -----------------------------------------------------------------------------
42-
// Core Math Engine
42+
// Core Math Engine (Lasse Schlör Absolute Error Optimized)
4343
// -----------------------------------------------------------------------------
4444
ACCEL_RAM static float fast_sin_internal(float theta) {
4545
float x = theta * INV_TWO_PI_F;
@@ -88,6 +88,7 @@ static mp_obj_t experimental_odometry_benchmark(size_t n_args, const mp_obj_t *a
8888
uint32_t start_time = mp_hal_ticks_ms();
8989

9090
for (int i = 0; i < num_iters; i++) {
91+
// Direct hardware reads
9192
pbio_tacho_get_angle(left_motor->tacho, &ang_l);
9293
pbio_tacho_get_angle(right_motor->tacho, &ang_r);
9394
pbio_drivebase_get_state_user(db_obj->db, NULL, NULL, &h_mdeg, NULL);
@@ -108,8 +109,10 @@ static mp_obj_t experimental_odometry_benchmark(size_t n_args, const mp_obj_t *a
108109
last_lin = cur_lin;
109110
last_heading = cur_heading;
110111

111-
if ((i % 1000) == 0) {
112+
// Stability Yield: Every 2000 loops, give the hub 1ms to update system tasks
113+
if ((i % 2000) == 0) {
112114
mp_handle_pending(true);
115+
mp_hal_delay_ms(1);
113116
}
114117
}
115118

0 commit comments

Comments
 (0)