728x90
반응형
SMALL
🚀 경주의 시작!
라인트레이싱을 이용한 경주에 참가했습니다! 연습 때는 21초로 빠르게 주행했지만,
본 경기에서는 이탈로 인해 속도를 조절하면서 결국 28초로 4등을 기록했어요.
아쉽지만 다음엔 더 잘할 수 있도록 개선해봅시다! 😤
⚙️ 문제 분석: 바퀴 편차 발생 원인
경기 중 차량이 일정하게 나아가지 못하고 편차가 발생하는 이유는 다양합니다.
원인 설명
🔧 바퀴 마찰력 차이 | 좌우 바퀴의 마찰력 차이로 인해 직진성이 떨어짐 |
⚖️ 무게중심 문제 | 로봇의 무게 중심이 한쪽으로 치우쳐 균형이 맞지 않음 |
🏗️ 조립 오차 | 모터 장착 위치, 차축의 미세한 틀어짐 등이 원인 |
이를 해결하기 위해 편차 조정 코드를 추가해보았습니다! 🛠️
📝 코드 분석 & 개선
바퀴 편차를 줄이기 위해 속도 조정이 필요합니다. 현재 코드에서 좌우 바퀴 속도를 동적으로 조정하여 직진성을 개선할 수 있도록 했어요.
#define ir_R 7
#define ir_L 8
#define motor_A_1A 5
#define motor_A_1B 6
#define motor_B_1A 10
#define motor_B_1B 9
int speed_R = 120;
int speed_L = 120;
int correction = 10; // 편차 보정 값
void forward() {
analogWrite(motor_A_1A, 0);
analogWrite(motor_A_1B, speed_R - correction);
analogWrite(motor_B_1A, speed_L + correction);
analogWrite(motor_B_1B, 0);
}
void setup() {
Serial.begin(115200);
pinMode(ir_R, INPUT);
pinMode(ir_L, INPUT);
pinMode(motor_A_1A, OUTPUT);
pinMode(motor_A_1B, OUTPUT);
pinMode(motor_B_1A, OUTPUT);
pinMode(motor_B_1B, OUTPUT);
}
void loop() {
int val_R = digitalRead(ir_R);
int val_L = digitalRead(ir_L);
if (val_R == LOW && val_L == LOW) {
forward();
Serial.println("F");
}
}
아래는 최종 코드
#define ir_R 7
#define ir_L 8
#define motor_A_1A 5
#define motor_A_1B 6
#define motor_B_1A 10
#define motor_B_1B 9
int moving_direction = 0;
int moving_speed = 0;
int delta_R = 0;
int delta_L = 0;
int speed_R = 100;
int speed_L = 100;
void forward(int speed_R, int speed_L) {
analogWrite(motor_A_1A, 0);
analogWrite(motor_A_1B, speed_R);
analogWrite(motor_B_1A, speed_L);
analogWrite(motor_B_1B, 0);
}
void backward(int speed_R, int speed_L) {
analogWrite(motor_A_1A, speed_R);
analogWrite(motor_A_1B, 0);
analogWrite(motor_B_1A, 0);
analogWrite(motor_B_1B, speed_L);
}
void turnLeft(int speed_R, int speed_L) {
analogWrite(motor_A_1A, 0);
analogWrite(motor_A_1B, speed_R);
analogWrite(motor_B_1A, 0);
analogWrite(motor_B_1B, speed_L);
}
void turnRight(int speed_R, int speed_L) {
analogWrite(motor_A_1A, speed_R);
analogWrite(motor_A_1B, 0);
analogWrite(motor_B_1A, speed_L);
analogWrite(motor_B_1B, 0);
}
void stopAll() {
analogWrite(motor_A_1A, 0);
analogWrite(motor_A_1B, 0);
analogWrite(motor_B_1A, 0);
analogWrite(motor_B_1B, 0);
}
void setup() {
Serial.begin(115200);
pinMode(ir_R,INPUT);
pinMode(ir_L,INPUT);
pinMode(motor_A_1A, OUTPUT);
pinMode(motor_A_1B, OUTPUT);
pinMode(motor_B_1A, OUTPUT);
pinMode(motor_B_1B, OUTPUT);
}
void loop() {
int val_R = digitalRead(ir_R);
int val_L = digitalRead(ir_L);
if (val_R == LOW && val_L == LOW) {
forward(120,120);
Serial.println("F");
} else if (val_R == HIGH && val_L == HIGH) {
stopAll();
} else if (val_L == HIGH) {
turnLeft(200,80);
Serial.println("L");
delay(170);
} else if (val_R == HIGH) {
turnRight(170,90);
Serial.println("R");
delay(170);
}
}
🚀 개선된 점
- correction 값을 추가해 좌우 바퀴 속도 미세 조정 ✨
- 속도 차이를 보정하여 더 안정적인 직진 가능 ✅
- 일관된 라인트레이싱 주행을 기대 🎯
📌 다음 목표
- PID 제어 적용해서 자동으로 편차 보정 🔍
- 속도 최적화를 통해 빠르고 안정적인 주행 구현 🏁
- 센서 반응 개선으로 더 정확한 라인트레이싱 🎯
이번 경기에서는 아쉬운 결과였지만, 개선을 통해 더 나은 성능을 기대해봅니다! 다음엔 꼭 1등! 🥇
🔥 계속 도전하자! 💪
728x90
반응형
LIST
'KG_KAIROS > MCU (Arduino & STM32)' 카테고리의 다른 글
[KG_KAIROS] STM32_CUBE IDE (0) | 2024.08.30 |
---|---|
🦾[KG_KAIROS] RobotArm 제작!! (0) | 2024.07.19 |
[KG_KAIROS] ESP32 모터제어(ThingSpeak) (0) | 2024.07.17 |
[KG_KAIROS] ESP32 보드 활용 (0) | 2024.07.16 |
[KG_KAIROS] 아두이노 기초2 (0) | 2024.07.12 |