1010#include "py/runtime.h"
1111#include <math.h>
1212
13- // Direct access to Pybricks internal types
14- #include "pybricks/pupdevices/pb_type_pupdevices_motor .h"
15- #include "pybricks/robotics/pb_type_robotics_drivebase .h"
13+ // Adjusted include paths to match Pybricks build system search paths
14+ #include "pybricks/pupdevices.h"
15+ #include "pybricks/robotics.h"
1616#include <pbio/tacho.h>
1717
1818#if defined(__ARM_ARCH_7M__ ) || defined(__ARM_ARCH_7EM__ )
@@ -68,11 +68,11 @@ static float get_float_from_obj(mp_obj_t obj) {
6868// The "Bare Metal" Odometry Benchmark
6969// -----------------------------------------------------------------------------
7070static mp_obj_t experimental_odometry_benchmark (size_t n_args , const mp_obj_t * args ) {
71- // 1. Unpack Arguments as RAW C-STRUCTS
7271 int num_iters = mp_obj_get_int (args [0 ]);
7372 float wheel_circ = get_float_from_obj (args [1 ]);
7473
75- // Cast Python objects directly to their internal C types
74+ // Unpack as pointers to Pybricks objects
75+ // Note: We use the generic object pointer then cast to access members
7676 pb_type_Motor_obj_t * right_motor = (pb_type_Motor_obj_t * )MP_OBJ_TO_PTR (args [2 ]);
7777 pb_type_Motor_obj_t * left_motor = (pb_type_Motor_obj_t * )MP_OBJ_TO_PTR (args [3 ]);
7878 pb_type_DriveBase_obj_t * db = (pb_type_DriveBase_obj_t * )MP_OBJ_TO_PTR (args [4 ]);
@@ -83,16 +83,14 @@ static mp_obj_t experimental_odometry_benchmark(size_t n_args, const mp_obj_t *a
8383
8484 uint32_t start_time = mp_hal_ticks_ms ();
8585
86- // 2. The High-Speed Loop (Zero Python Callbacks)
8786 for (int i = 0 ; i < num_iters ; i ++ ) {
88- // Direct pointer access to encoder angles
8987 int32_t r_ang , l_ang ;
9088 pbio_tacho_get_angle (right_motor -> tacho , & r_ang );
9189 pbio_tacho_get_angle (left_motor -> tacho , & l_ang );
9290
93- // Direct pointer access to DriveBase heading (no .angle() call)
94- // Note: heading is already a float in the DriveBase struct
95- float robot_heading = db -> heading ;
91+ // Heading access: On many Pybricks versions, it's inside a state struct
92+ // We use the getter to be safe across EV3/Spike builds
93+ float robot_heading = pbio_drivebase_get_heading ( db -> db ) ;
9694
9795 float current_linear = (float )(r_ang + l_ang ) * deg_to_mm ;
9896 float linear = current_linear - last_linear ;
0 commit comments