Skip to content

Commit 5cad2ff

Browse files
committed
pls compile brotato✌️
1 parent ce06bce commit 5cad2ff

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

pybricks/experimental/odometry.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
// SPDX-License-Identifier: MIT
2+
#include "py/mpconfig.h"
3+
4+
// This must match the flag in your mpconfigport.h
5+
#if PYBRICKS_PY_EXPERIMENTAL
6+
7+
#include "py/mphal.h"
8+
#include "py/runtime.h"
9+
#include <math.h>
10+
#include <stdint.h>
11+
#include <stdbool.h>
12+
213
#include <pybricks/common.h>
314
#include <pbio/servo.h>
415
#include <pbio/control.h>
516
#include "pybricks/experimental/odometry.h"
617
#include "pybricks/experimental/platform_math.h"
718

819
// --- THE FIX: Forward declare the Motor Object structure ---
9-
// This replaces the #include "pybricks/pupdevices/pb_type_pupdevices_motor.h"
1020
typedef struct _pb_type_pupdevices_Motor_obj_t {
1121
mp_obj_base_t base;
12-
pbio_servo_t *srv; // In some versions this is 'servo'
22+
pbio_servo_t *srv;
1323
} pb_type_pupdevices_Motor_obj_t;
1424
// -----------------------------------------------------------
1525

@@ -69,28 +79,24 @@ void pb_background_odometry_update(void) {
6979
void pb_background_pursuit_update(void) {
7080
if (!pursuit_running || !left_servo_ptr || !right_servo_ptr) return;
7181

72-
// 1. Check Exit Condition (Reached end of spline)
7382
if (global_x >= sp_x_end) {
7483
pursuit_running = false;
7584
pbio_servo_stop(left_servo_ptr, PBIO_CONTROL_ON_COMPLETION_BRAKE);
7685
pbio_servo_stop(right_servo_ptr, PBIO_CONTROL_ON_COMPLETION_BRAKE);
7786
return;
7887
}
7988

80-
// 2. Project Target Point
8189
float target_x = global_x + p_lookahead;
8290
if (target_x > sp_x_end) target_x = sp_x_end;
8391

8492
float tx2 = target_x * target_x;
8593
float tx3 = tx2 * target_x;
8694
float target_y = (sp_a * tx3) + (sp_b * tx2) + (sp_c * target_x) + sp_d;
8795

88-
// 3. Pure Pursuit Math
8996
float x_dif = target_x - global_x;
9097
float y_dif = target_y - global_y;
9198
float dist_sq = (x_dif * x_dif) + (y_dif * y_dif);
9299

93-
// Transform to local robot coordinates
94100
float relative_y = (y_dif * pb_fast_cos(global_h)) - (x_dif * pb_fast_sin(global_h));
95101

96102
float m_left = 1.0f;
@@ -104,7 +110,6 @@ void pb_background_pursuit_update(void) {
104110
m_left = two_r / (two_r - track);
105111
}
106112

107-
// 4. Drive
108113
pbio_servo_run_forever(left_servo_ptr, (int32_t)(p_target_speed * m_left));
109114
pbio_servo_run_forever(right_servo_ptr, (int32_t)(p_target_speed * m_right));
110115
}
@@ -129,7 +134,11 @@ mp_obj_t experimental_start_odometry(size_t n_args, const mp_obj_t *args) {
129134
}
130135

131136
mp_obj_t experimental_get_odometry(void) {
132-
mp_obj_t tuple[3] = { mp_obj_new_float_from_f(global_x), mp_obj_new_float_from_f(global_y), mp_obj_new_float_from_f(global_h) };
137+
mp_obj_t tuple[3] = {
138+
mp_obj_new_float_from_f(global_x),
139+
mp_obj_new_float_from_f(global_y),
140+
mp_obj_new_float_from_f(global_h)
141+
};
133142
return mp_obj_new_tuple(3, tuple);
134143
}
135144

@@ -160,4 +169,4 @@ mp_obj_t experimental_stop_pursuit(void) {
160169
return mp_const_none;
161170
}
162171

163-
#endif
172+
#endif // PYBRICKS_PY_EXPERIMENTAL

0 commit comments

Comments
 (0)