Skip to content

Commit 3a9df0c

Browse files
committed
compile maybe?
1 parent 77d5023 commit 3a9df0c

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

pybricks/experimental/odometry.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,22 @@ void pb_background_pursuit_update(void) {
7070

7171
// 1. PROJECT TARGET POINT
7272
// Use sp_a, sp_b, sp_c, sp_d and p_lookahead to find target_x and target_y
73-
float target_x = 0.0f;
74-
float target_y = 0.0f;
73+
//TODO
74+
//float target_x = 0.0f;
75+
//float target_y = 0.0f;
7576

7677
// 2. CHECK EXIT CONDITION
7778
// Decide when to set pursuit_running = false (e.g. reaching sp_x_end)
7879

7980
// 3. PURE PURSUIT MATH
8081
// Calculate m_left and m_right based on target_x/y relative to global_x/y
81-
float m_left = 1.0f;
82-
float m_right = 1.0f;
82+
//float m_left = 1.0f;
83+
//float m_right = 1.0f;
8384

8485
// 4. DRIVE
85-
pbio_servo_run_velocity(left_servo_ptr, (int32_t)(p_target_speed * m_left));
86-
pbio_servo_run_velocity(right_servo_ptr, (int32_t)(p_target_speed * m_right));
86+
pbio_servo_run_forever(left_servo_ptr, (int32_t)(p_target_speed * m_left));
87+
pbio_servo_run_forever(right_servo_ptr, (int32_t)(p_target_speed * m_right));
88+
8789
}
8890

8991
// --- MicroPython API ---
@@ -132,10 +134,11 @@ mp_obj_t experimental_start_spline(size_t n_args, const mp_obj_t *args) {
132134
mp_obj_t experimental_stop_pursuit(void) {
133135
pursuit_running = false;
134136
if (left_servo_ptr && right_servo_ptr) {
135-
pbio_servo_stop(left_servo_ptr, PBIO_CONTROL_STOP_BRAKE);
136-
pbio_servo_stop(right_servo_ptr, PBIO_CONTROL_STOP_BRAKE);
137+
pbio_servo_stop(left_servo_ptr, PBIO_CONTROL_ON_COMPLETION_BRAKE);
138+
pbio_servo_stop(right_servo_ptr, PBIO_CONTROL_ON_COMPLETION_BRAKE);
137139
}
138140
return mp_const_none;
141+
139142
}
140143

141144
#endif

pybricks/experimental/platform_math.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,25 @@ static inline float pb_fast_cos(float theta) {
4343
// skrauzys nightmare ^1.2
4444
// ---------------------------------------------------------
4545

46-
// use 1 newton iteration without division, using x^1.2 = x^2 * (x^-0.2)^4
4746
static inline float pb_fast_pow_1_2_ultra(float x) {
48-
// protect against zero
4947
if (x > -0.0001f && x < 0.0001f) return 0.0f;
5048

51-
uint32_t i = *(uint32_t*)&x; // evil floating point bit level hacking
49+
union { float f; uint32_t i; } conv;
50+
conv.f = x;
51+
52+
uint32_t i = conv.i & 0x7FFFFFFF; // evil floating point bit level hacking
5253
i &= 0x7FFFFFFF; // absolute value
5354

5455
uint32_t iy = 1278004968 - (i / 5); // what the fuck?
55-
float y = *(float*)&iy;
56+
conv.i = iy;
57+
float y = conv.f;
5658

5759
float y2 = y * y;
5860
float y4 = y2 * y2;
5961
float y5 = y4 * y;
6062
float y_new = y * (1.2f - 0.2f * x * y5); // 1st iteration
6163
// y_new = y_new * ( ... ); // 2nd iteration, this can be removed
6264

63-
//apply x^1.2 = x^2 * (x^-0.2)^4
6465
float yn2 = y_new * y_new;
6566
float yn4 = yn2 * yn2;
6667
float x2 = x * x;

0 commit comments

Comments
 (0)