약간의 수정2

This commit is contained in:
2025-12-10 00:12:53 +09:00
parent d3a2802333
commit 2ca19bf287
3 changed files with 46 additions and 4 deletions

View File

@@ -42,7 +42,7 @@ void test_ir(void) {
ir_ready_ready();
ir_read_value(&ir_value);
print_binary(ir_value);
printf("\n";)
printf("\n");
ir_read_off();
}
}

View File

@@ -13,7 +13,7 @@
#define TRUE 1
#define FALSE 0
#define PRACTICE 3
#define PRACTICE 4
#if PRACTICE == 1
@@ -514,6 +514,48 @@ void position_init_led(void) {
}
#elif PRACTICE == 4
void LineTracerPrac4(void) {
Clock_Init48MHz();
ir_init();
motor_init();
// PID Constants
const float Kp = 0.005f;
const float Kd = 0.02f;
const int BASE_SPEED = 10;
const int MAX_DRV = 20;
int error = 0;
int prev_error = 0;
float pid_out = 0;
int speed_l, speed_r;
while (1) {
uint8_t raw_val;
ir_read_ready();
Clock_Delay1ms(1);
ir_read_value(&raw_val);
ir_read_off();
error = get_error(raw_val);
pid_out = (Kp * error) + (Kd * (error - prev_error));
prev_error = error;
speed_l = BASE_SPEED + (int)pid_out;
speed_r = BASE_SPEED - (int)pid_out;
if (speed_l > MAX_DRV) speed_l = MAX_DRV;
if (speed_l < 0) speed_l = 0;
if (speed_r > MAX_DRV) speed_r = MAX_DRV;
if (speed_r < 0) speed_r = 0;
motor_move_custom(speed_l, speed_r);
Clock_Delay1ms(2);
}
}
#endif
int main(void) {
@@ -523,6 +565,8 @@ int main(void) {
LineTracerPrac2();
#elif PRACTICE == 3
LineTracerPrac3();
#elif PRACTICE == 4
LineTracerPrac4();
#else
printf("No practice selected.\n");
#endif

View File

@@ -37,8 +37,6 @@ void senbuf_get(SensorBuffer *sb, uint8_t *out, int lookahead) {
}
}
// History Buffer
void hisbuf_init(HistoryBuffer *sb) {