Ahoj, mám takový problém, postavil jsem si robota použil jsem arduino uno, motor shield, ultrazvukový senzor a servo .Pokud robota zapnu tak sice se vyhne, ale pořád popojíždí dopředu a točí se dokola jako by před ním byla překážka. echo připojené na analog 3a trig na analog 4Ještě se zeptám čím byste to napájeli , po připojení 9v baterie sice kontrolky svítí ale motory to neutáhne, pokud to připojím k 9v zdroji tak to jede bezproblému. Zkoušel jsem zapojit i paralerně dvě 9v baterie .Dík moc za radyMůj kód:#include <AFMotor.h>#include <Servo.h> #include <NewPing.h>#define TRIG_PIN A4 #define ECHO_PIN A3 #define MAX_DISTANCE 200 #define MAX_SPEED 180 #define MAX_SPEED_OFFSET 10 #define COLL_DIST 10 #define TURN_DIST COLL_DIST+10NewPing sonar(TRIG_PIN, ECHO_PIN, MAX_DISTANCE); AF_DCMotor motor1(1, MOTOR12_1KHZ); AF_DCMotor motor2(4, MOTOR12_1KHZ); Servo myservo; int pos = 0; int maxDist = 0; int maxAngle = 0; int maxRight = 0; int maxLeft = 0; int maxFront = 0;int course = 0;int curDist = 0;String motorSet = "";int speedSet = 0;void setup() { myservo.attach(9); myservo.write(90); delay(2000); checkPath(); motorSet = "FORWARD"; myservo.write(90); moveForward();}void loop() { checkForward(); checkPath(); }void checkPath() { int curLeft = 0; int curFront = 0; int curRight = 0; int curDist = 0; myservo.write(144); … delay(120); for(pos = 144; pos >= 36; pos-=18) { myservo.write(pos); delay(90); checkForward(); curDist = readPing(); if (curDist < COLL_DIST) { checkCourse(); break; } if (curDist < TURN_DIST) { changePath(); } if (curDist > curDist) {maxAngle = pos;} if (pos > 90 && curDist > curLeft) { curLeft = curDist;} if (pos == 90 && curDist > curFront) {curFront = curDist;} if (pos < 90 && curDist > curRight) {curRight = curDist;} } maxLeft = curLeft; maxRight = curRight; maxFront = curFront;}void setCourse() { if (maxAngle < 90) {turnRight();} if (maxAngle > 90) {turnLeft();} maxLeft = 0; maxRight = 0; maxFront = 0;}void checkCourse() { moveBackward(); delay(500); moveStop(); setCourse();}void changePath() { if (pos < 90) {veerLeft();} if (pos > 90) {veerRight();} }int readPing() { delay(70); unsigned int uS = sonar.ping(); int cm = uS/US_ROUNDTRIP_CM; return cm;}void checkForward() { if (motorSet=="FORWARD") {motor1.run(FORWARD); motor2.run(FORWARD); } } void checkBackward() { if (motorSet=="BACKWARD") {motor1.run(BACKWARD); motor2.run(BACKWARD); } } void moveStop() {motor1.run(RELEASE); motor2.run(RELEASE);} void moveForward() { motorSet = "FORWARD"; motor1.run(FORWARD); motor2.run(FORWARD); for (speedSet = 0; speedSet < MAX_SPEED; speedSet +=2) { motor1.setSpeed(speedSet+MAX_SPEED_OFFSET); motor2.setSpeed(speedSet); delay(5); }}void moveBackward() { motorSet = "BACKWARD"; motor1.run(BACKWARD); motor2.run(BACKWARD); for (speedSet = 0; speedSet < MAX_SPEED; speedSet +=2) { motor1.setSpeed(speedSet+MAX_SPEED_OFFSET); motor2.setSpeed(speedSet); delay(5); }} void turnRight() { motorSet = "RIGHT"; motor1.run(FORWARD); motor2.run(BACKWARD); delay(400); motorSet = "FORWARD"; motor1.run(FORWARD); motor2.run(FORWARD); } void turnLeft() { motorSet = "LEFT"; motor1.run(BACKWARD); motor2.run(FORWARD); delay(400); motorSet = "FORWARD"; motor1.run(FORWARD); motor2.run(FORWARD); } void veerRight() {motor2.run(BACKWARD); delay(400); motor2.run(FORWARD);} // veering right? set right motor backwards for 400msvoid veerLeft() {motor1.run(BACKWARD); delay(400); motor1.run(FORWARD);} // veering left? set left motor backwards for 400ms Ukázat celý příspěvek