|
5 | 5 |
|
6 | 6 | #if PYBRICKS_PY_EXPERIMENTAL |
7 | 7 |
|
| 8 | +// Include this AFTER the MicroPython headers so mp_obj_t is defined |
8 | 9 | #include "pybricks/experimental/odometry.h" |
9 | 10 |
|
10 | | -// Define STATIC if not already defined (usually it is in mpconfig.h) |
11 | 11 | #ifndef STATIC |
12 | 12 | #define STATIC static |
13 | 13 | #endif |
14 | 14 |
|
15 | | -// This is the function that Python calls |
16 | 15 | STATIC mp_obj_t experimental_odometry_benchmark(size_t n_args, const mp_obj_t *args) { |
17 | 16 | int num_iters = mp_obj_get_int(args[0]); |
18 | 17 | float wheel_circ = mp_obj_get_float(args[1]); |
19 | 18 | float axle_track = mp_obj_get_float(args[2]); |
20 | 19 | mp_obj_t right_func = args[3]; |
21 | 20 | mp_obj_t left_func = args[4]; |
22 | 21 |
|
| 22 | + // With the header included, the compiler now knows these are floats, not doubles |
23 | 23 | return calculate_odometry(num_iters, wheel_circ, axle_track, right_func, left_func); |
24 | 24 | } |
25 | | -// Define as a MicroPython function object |
| 25 | + |
26 | 26 | STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(experimental_odometry_benchmark_obj, 5, 5, experimental_odometry_benchmark); |
27 | 27 |
|
28 | | -// Map the C function to the Python name "odometry_benchmark" |
29 | 28 | STATIC const mp_rom_map_elem_t experimental_globals_table[] = { |
30 | 29 | { MP_ROM_QSTR(MP_QSTR_odometry_benchmark), MP_ROM_PTR(&experimental_odometry_benchmark_obj) }, |
31 | 30 | }; |
32 | 31 | STATIC MP_DEFINE_CONST_DICT(pb_module_experimental_globals, experimental_globals_table); |
33 | 32 |
|
34 | | -// Structure for MicroPython to register the module |
35 | 33 | const mp_obj_module_t pb_module_experimental = { |
36 | 34 | .base = { &mp_type_module }, |
37 | 35 | .globals = (mp_obj_dict_t *)&pb_module_experimental_globals, |
|
0 commit comments