I have an RC car with the following components:
- Arduino Uno
- 2 DC motors (1 for drive motor and one steering motor)
- L293D H Bridge
- 3 Ultrasonic sensors (HC SR04; front, side, rear)
- 9V Battery
and I want to perform a parallel parking sequence with the following concept:
- Car is moving forward at a constant velocity parallel to any potential parking spaces
- While the car is moving, the ultrasonic sensor on the side is constantly measuring for depth
- Once the ultrasonic sensor detects a depth > lets say 10 cm, the car will recognize that there is a potential parking space, however, it needs to be long enough for the car to fit
- At this point, a timer starts while the car moves forward with a constant velocity
- While the depth > 10 cm for 4 seconds (arbitrary time but the idea is velocity x time = distance so if it’s the car is travelling at 0.1 m/s for 4 seconds, the distance is 0.4 m or 40 cm.
- This 40 cm is longer than the car, and there is space to park, therefore, start the parallel parking sequence
- a. Turn all the way to the right
b. Drive motor in reverse for half a second (or whatever value)
c. Wheels all way to left
etc…
-
My problem is, while the millis() function is running, I want to make a copy of the time as soon as the the ultrasonic sensor detects a depth. The timer will continues as long as the depth > 10 cm.
-
The timer will stop as soon as the depth < 10 cm and reset that timer to 0
-
if the time is > whatever time I decide when I do the calculations, then start parallel parking.
-
I’m not sure exactly how to manipulate the timer function so it saves multiple instances of time
-
If someone can help me with the concept, I can definitely code it myself and will ask for feedback as necessary
Thank you so much and ask me anything if it is unclear