If either side is three centimeters further away than the other, the robot will turn in that direction to follow its predicted path. Our robot will try to stay ten centimeters behind the target object, moving forwards and backward depending on the targetâs position. This was done to prevent interference from walls or objects far away from the target object. If there is nothing in front of the robot for seventy centimeters, it will stop moving until something is in front of it. Below that is our object-following logic. First, we set our servo to sixty degrees, calculate the distance to the object, then move the servo sixty degrees to the left to do it again. The two integers initialized in the last line store the distance in centimeters from the target to the ultrasonic sensor. A larger carSpeed value will make your robot faster, but also consume more energy. ![]() ![]() carSpeed2 can be used to make the car turn faster or slower while retaining the same forward and backward carSpeed value. If you are not using the same car as I am, you will need to change these values to fit your motorsâ pins.ĬarSpeed(0-255) is the maximum analog value the motors will be given. The EN and IN pins are used to assign motor speed values and motor direction, respectively. I am using A4 and A5 because that is the default configuration for the Elegoo Car. You can use digital pins if you would like. Analog 4 and 5 are used in this case, but if you are planning on using different pins make sure to change these. Next, you will see the pins I have assigned to the ultrasonic sensor. This will be used to swivel the ultrasonic sensor. The first thing you will notice is the servo motor.
0 Comments
Leave a Reply. |