Я работаю над школьным проектом с очень небольшими ресурсами. Мне нужно сделать линию после робота, который находит путь через лабиринт, повернув налево, когда это возможно. У меня уже есть небольшое тело, но робот, похоже, не поворачивает налево/следуйте линии, когда это необходимо. Я также понятия не имею, как я могу избавиться от небольших отклонений и как я могу сделать поворот робота, когда нет линий?
Материалы:
arduino leonardo < /p>
< /li>
qtr-8a Датчик земли < / p>
< /li>
Два основных двигателя DC < /p>
< /li>
< /ul>
code:
#include //setup for motors
DRV8835MotorShield motors;
void setup() {
// put your setup code here, to run once:
motors.flipM1(true);
motors.flipM2(true);
}
void loop() {
//left groundsensor= analogRead(A0);
//rightgroundsensor = analogRead(A2);
//middlegroundsensor = analogRead(A1);
//motorstM1//right weel
//motors.setM2Speed(100);//left weel
if(analogRead(A0) > 750){ //turn left
motors.setM1Speed(100);
motors.setM2Speed(-100);
}
else if(analogRead(A1) > 750){//nothing left, so go straight
motors.setM1Speed(100);
motors.setM2Speed(100);
}
else if(analogRead(A2) > 750){//nothing in the middle, so robot has deviated, turn right a bit, if the deviation is to the rigth, I don't need the next loop
while(analogRead(A0) < 750){//turn right till black line is in the middle again
motors.setM1Speed(-100);
motors.setM1Speed(100);
}
}
else{//if they are all < 750, it's a deviation or a dead end, I will have to watch how the robot deviates so that I can turn let it always turn in the opposite direction
while(analogRead(A1) < 750){//turn right/left till black line is in the middle again
motors.setM1Speed(-100);
motors.setM1Speed(100);
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/724 ... n-carduino