1010#include "py/runtime.h"
1111#include <math.h>
1212
13- // Pybricks Hardware Headers
1413#include <pbio/tacho.h>
1514#include <pbio/drivebase.h>
16- #include "pybricks/pupdevices.h"
17- #include "pybricks/robotics.h"
1815
1916#if defined(__ARM_ARCH_7M__ ) || defined(__ARM_ARCH_7EM__ )
2017 #define IS_CORTEX_M 1
2421 #define ACCEL_RAM
2522#endif
2623
24+ // Manually defining the minimal internal structures to bypass header errors
25+ typedef struct _pb_type_Motor_obj_t {
26+ mp_obj_base_t base ;
27+ pbio_tacho_t * tacho ;
28+ } pb_type_Motor_obj_t ;
29+
30+ typedef struct _pb_type_DriveBase_obj_t {
31+ mp_obj_base_t base ;
32+ pbio_drivebase_t * db ;
33+ } pb_type_DriveBase_obj_t ;
34+
2735// Constants
2836static const float PI_F = 3.141592653589793f ;
2937static const float TWO_PI_F = 6.283185307179586f ;
@@ -59,7 +67,6 @@ static mp_obj_t experimental_odometry_benchmark(size_t n_args, const mp_obj_t *a
5967 int num_iters = mp_obj_get_int (args [0 ]);
6068 float wheel_circ = mp_obj_get_float (args [1 ]);
6169
62- // Bypassing get_tacho by using the Motor Object passed from Python
6370 pb_type_Motor_obj_t * right_motor = (pb_type_Motor_obj_t * )MP_OBJ_TO_PTR (args [2 ]);
6471 pb_type_Motor_obj_t * left_motor = (pb_type_Motor_obj_t * )MP_OBJ_TO_PTR (args [3 ]);
6572 pb_type_DriveBase_obj_t * db_obj = (pb_type_DriveBase_obj_t * )MP_OBJ_TO_PTR (args [4 ]);
@@ -74,16 +81,18 @@ static mp_obj_t experimental_odometry_benchmark(size_t n_args, const mp_obj_t *a
7481 float last_lin = ((float )ang_l .rotations * 360.0f + (float )ang_l .millidegrees / 1000.0f +
7582 (float )ang_r .rotations * 360.0f + (float )ang_r .millidegrees / 1000.0f ) * deg_to_mm ;
7683
77- // Direct access to the internal DriveBase heading state
78- float last_heading = db_obj -> db -> state .heading / 1000.0f ;
84+ int32_t h_mdeg ;
85+ pbio_drivebase_get_state_user (db_obj -> db , NULL , NULL , & h_mdeg , NULL );
86+ float last_heading = (float )h_mdeg / 1000.0f ;
7987
8088 uint32_t start_time = mp_hal_ticks_ms ();
8189
8290 for (int i = 0 ; i < num_iters ; i ++ ) {
8391 pbio_tacho_get_angle (left_motor -> tacho , & ang_l );
8492 pbio_tacho_get_angle (right_motor -> tacho , & ang_r );
85-
86- float cur_heading = db_obj -> db -> state .heading / 1000.0f ;
93+ pbio_drivebase_get_state_user (db_obj -> db , NULL , NULL , & h_mdeg , NULL );
94+
95+ float cur_heading = (float )h_mdeg / 1000.0f ;
8796 float cur_lin = ((float )ang_l .rotations * 360.0f + (float )ang_l .millidegrees / 1000.0f +
8897 (float )ang_r .rotations * 360.0f + (float )ang_r .millidegrees / 1000.0f ) * deg_to_mm ;
8998
@@ -117,7 +126,6 @@ static mp_obj_t experimental_odometry_benchmark(size_t n_args, const mp_obj_t *a
117126 return mp_obj_new_tuple (5 , tuple );
118127}
119128
120- // Re-enabling 5 argument mode to accept motor objects
121129static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (experimental_odometry_benchmark_obj , 5 , 5 , experimental_odometry_benchmark ) ;
122130
123131static const mp_rom_map_elem_t experimental_globals_table [] = {
0 commit comments