Human Following Car

This thread was created to troubleshoot a human following car project.
5 Replies
Maverick
MaverickOP3y ago
@Harsh Thakur I created this thread for your question. In your code (https://pastebin.com/qLAxZQWH), it seems that there is nothing included to handle a situation in which the ultrasonic sensor is > 30cm from the nearest object. What should the car be doing in this situation?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Maverick
MaverickOP3y ago
In your code, there is no command for the car when the distance value is greater than 30. distance > 30. I suggest you add some debugging to your code with Serial.print() and Serial.println(), then connect the car to your computer with the USB cable while holding it in the air as you have in the video. You will be able to see what is happening in the code. For example:
else if(distance > 1 && distance < 10) {
Serial.println("distance between 1 and 10");
Serial.println("STOPPING");
Motor1.setSpeed(0);
Motor1.run(RELEASE);
Motor2.setSpeed(0);
Motor2.run(RELEASE);
Motor3.setSpeed(0);
Motor3.run(RELEASE);
Motor4.setSpeed(0);
Motor4.run(RELEASE);
}
else if(distance > 1 && distance < 10) {
Serial.println("distance between 1 and 10");
Serial.println("STOPPING");
Motor1.setSpeed(0);
Motor1.run(RELEASE);
Motor2.setSpeed(0);
Motor2.run(RELEASE);
Motor3.setSpeed(0);
Motor3.run(RELEASE);
Motor4.setSpeed(0);
Motor4.run(RELEASE);
}
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Maverick
MaverickOP3y ago
At the end of all of your if / else statements for the motors, you could add something like this also:
// Other code...
Motor4.run(RELEASE);
}
else {
Serial.println("Undefined Behavior!");
Serial.print("Distance = ");
Serial.println(distance);
}
// Other code...
Motor4.run(RELEASE);
}
else {
Serial.println("Undefined Behavior!");
Serial.print("Distance = ");
Serial.println(distance);
}
@Harsh Thakur Please let me know if you have solved this problem, so I can mark this thread as "solved".

Did you find this page helpful?