I have to make a vehicle that uses a servo motor and ultrasonic sensor to travel in a straight line, touch a surface, travel back along the same line, stop at the midpoint of the path and return to the beginning.
I am new to Arduino, and coding altogether, but understand the necessary coding for the sensor. I am getting read-outs on my display window of the received distances from the sensor and managed to get my servo to stop when a certain distance had been reached.
However, my issue has been getting the servo to change direction when it touches the wall, and stop at the midpoint, and then continue back to the beginning. When i try and get it to do sequential actions, and scan distances I always encounter problems with the delay function interfering with the ultrasonic sensor code, or a great many other issues.
Can anyone help with the coding for this? I'd appreciate any help on getting my sequences to work; forwards until distance is 0. Then backwards until distance is 1/2 total. Then stop for 10 seconds at this distance. Then backwards until distance is total and stop here.
I have to make a vehicle that uses a servo motor and ultrasonic sensor to travel in a straight line, touch a surface, travel back along the same line, stop at the midpoint of the path and return to the beginning.
I am new to Arduino, and coding altogether, but understand the necessary coding for the sensor. I am getting read-outs on my display window of the received distances from the sensor and managed to get my servo to stop when a certain distance had been reached.
However, my issue has been getting the servo to change direction when it touches the wall, and stop at the midpoint, and then continue back to the beginning. When i try and get it to do sequential actions, and scan distances I always encounter problems with the delay function interfering with the ultrasonic sensor code, or a great many other issues.
Can anyone help with the coding for this? I'd appreciate any help on getting my sequences to work; forwards until distance is 0. Then backwards until distance is 1/2 total. Then stop for 10 seconds at this distance. Then backwards until distance is total and stop here.
Does the vehicle have to steer to actively maintain a straight line? What reference will you use to determine if you are not going straight?
Or will it be good enough to have the wheels fixed straight and just let the motors run to move you forward then backward?
Is the ultrasonic sensor just to determine when you have approached the wall you need to touch? And maybe slow down so you don't slam in to the wall?
If you attach encoders to the drive train, you can count the number of revolutions until you contact the far wall.
Then put it in reverse and count half that many revolutions and stop.
Then continue again for the remainder of the revolutions.
But I am not sure what kind of accuracy you need on the distances.
However, my issue has been getting the servo to change direction when it touches the wall, and stop at the midpoint, and then continue back to the beginning.
Maybe you had a clue what this meant when you typed it, but I certainly don't.
The servo doesn't touch the wall, does it? Even if it did, how is it supposed to know that?
The midpoint of what? The beginning of what?
You can't possibly write code with such "requirements".
The bot start at a point, let's call it point A
It moves forward in a straight line until it comes within a certain distance of an obstacle and it stops for an unspecified period. Let's call the point at which it stops point B
It then moves backwards in a straight line along the path from point B to point A until it is half way between the two until it is half way between the two. Let's call that point C
After some unspecified time it continues backwards in a straight line from point C to point A and stops when it reaches it.
Questions
How are you measuring the distances run, or are you aiming to run the motor for fixed periods ?
How will you maintain a consistent running speed for the bot ?
How will you maintain straight running both forwards and reverse ?
How long should the bot pause at point C ?