hi Sisor,
ok, am anfang war ein buchstabe aber mittendrinn eine leerstelle, was evtl. auch die ursache gewesen sein könnte, oder? Jetzt heisst das file "obstacle_avoidance.ino". Ist von sainsmart, evtl. zu kompliziert um damit anzufangen? Ich habe teile bei sainsmart bestellt, da möchte ich die testen, wenn sie da sind![]()
lässt sich in der arduino IDE öffnen, beim compilierversuch kommt:Code:const int EchoPin = 2; // Ultrasonic signal input const int TrigPin = 3; // Ultrasonic signal output const int leftmotorpin1 = 8; //signal output of Dc motor driven plate const int leftmotorpin2 = 9; const int rightmotorpin1 = 6; const int rightmotorpin2 = 7; const int HeadServopin = 10; // signal input of headservo const int Sharppin = 11; // infrared output const int maxStart = 800; //run dec time // Variables int isStart = maxStart; int currDist = 0; //start // distance boolean running = false; void setup() { Serial.begin(9600); // Serial begin texting //signal input port pinMode(EchoPin, INPUT); pinMode(Sharppin, INPUT); //signal output port for (int pinindex = 3; pinindex < 11; pinindex++) { pinMode(pinindex, OUTPUT); // set pins 3 to 10 as outputs } // headservo interface headservo.attach(HeadServopin); //start buffer movable head headservo.write(70); delay(2000); headservo.write(20); delay(2000); } void loop() { if(DEBUG){ Serial.print("running:"); if(running){ Serial.println("true"); } else{ Serial.println("false"); } } if (isStart <= 0) { if(running){ totalhalt(); // stop! } int findsomebody = digitalRead(Sharppin); if(DEBUG){ Serial.print("findsomebody:"); Serial.println(findsomebody); } if(findsomebody > 0) { isStart = maxStart; } delay(4000); return; } isStart--; delay(100); if(DEBUG){ Serial.print("isStart: "); Serial.println(isStart); } currDist = MeasuringDistance(); //measure front distance if(DEBUG){ Serial.print("Current Distance: "); Serial.println(currDist); } if(currDist > 30) { nodanger(); } else if(currDist < 15){ backup(); randTrun(); } else { //whichway(); randTrun(); } } //measure distance, unit “cm” long MeasuringDistance() { long duration; //pinMode(TrigPin, OUTPUT); digitalWrite(TrigPin, LOW); delayMicroseconds(2); digitalWrite(TrigPin, HIGH); delayMicroseconds(5); digitalWrite(TrigPin, LOW); //pinMode(EchoPin, INPUT); duration = pulseIn(EchoPin, HIGH); return duration / 29 / 2; } // forward void nodanger() { running = true; digitalWrite(leftmotorpin1, HIGH); digitalWrite(leftmotorpin2, LOW); digitalWrite(rightmotorpin1, HIGH); digitalWrite(rightmotorpin2, LOW); return; } //backward void backup() { running = true; digitalWrite(leftmotorpin1, LOW); digitalWrite(leftmotorpin2, HIGH); digitalWrite(rightmotorpin1, LOW); digitalWrite(rightmotorpin2, HIGH); delay(1000); } //choose way void whichway() { running = true; totalhalt(); // first stop! headservo.write(20); delay(1000); int lDist = MeasuringDistance(); totalhalt(); // check left distance // probe recovering headservo.write(120); // turn the servo right delay(1000); int rDist = MeasuringDistance(); totalhalt(); if(lDist < rDist) { body_lturn(); } else{ body_rturn(); } // check right distance // probe recovering return; } //remodulate to the original status mechanically void totalhalt() { digitalWrite(leftmotorpin1, HIGH); digitalWrite(leftmotorpin2, HIGH); digitalWrite(rightmotorpin1, HIGH); digitalWrite(rightmotorpin2, HIGH); headservo.write(70); // set servo to face forward running = false; return; delay(1000); } //turn left void body_lturn() { running = true; digitalWrite(leftmotorpin1, LOW); digitalWrite(leftmotorpin2, HIGH); digitalWrite(rightmotorpin1, HIGH); digitalWrite(rightmotorpin2, LOW); delay(1500); totalhalt(); } //turn right void body_rturn() { running = true; digitalWrite(leftmotorpin1, HIGH); digitalWrite(leftmotorpin2, LOW); digitalWrite(rightmotorpin1, LOW); digitalWrite(rightmotorpin2, HIGH); delay(1500); totalhalt(); } void randTrun(){ long randNumber; randomSeed(analogRead(0)); randNumber = random(0, 10); if(randNumber > 5) { body_rturn(); } else { body_lturn(); } }
jetzt weiss ich dass es bedeutet, dass bestimmte libs fehlen. Muss ich diese (welche? alle?) in das verzeichnis mit der zu compilierenden datei kopieren, oder gibt es eine möglichkeit das über pfade in der IDE zu machen? Die IDE bietet die möglichkeit die libs zu includen, reicht das schon?Code:obstacle_avoidance.cpp: In function ‘void setup()’: obstacle_avoidance.cpp:38:1: error: ‘headservo’ was not declared in this scope obstacle_avoidance.cpp: In function ‘void loop()’: obstacle_avoidance.cpp:46:4: error: ‘DEBUG’ was not declared in this scope obstacle_avoidance.cpp:61:4: error: ‘DEBUG’ was not declared in this scope obstacle_avoidance.cpp:73:4: error: ‘DEBUG’ was not declared in this scope obstacle_avoidance.cpp:78:4: error: ‘DEBUG’ was not declared in this scope obstacle_avoidance.cpp: In function ‘void whichway()’: obstacle_avoidance.cpp:130:1: error: ‘headservo’ was not declared in this scope obstacle_avoidance.cpp: In function ‘void totalhalt()’: obstacle_avoidance.cpp:157:1: error: ‘headservo’ was not declared in this scope obstacle_avoidance.cpp:159:1: error: ‘set’ was not declared in this scope obstacle_avoidance.cpp:159:5: error: expected ‘;’ before ‘servo’
danke erstmal...







Zitieren

Lesezeichen