This shows you the differences between two versions of the page.
pm:prj2022:robert:mini_wall-e [2022/05/27 18:26] ovidiu.ghibea [Introducere] |
pm:prj2022:robert:mini_wall-e [2022/05/27 19:33] (current) ovidiu.ghibea [Jurnal] |
||
---|---|---|---|
Line 12: | Line 12: | ||
===== Descriere generală ===== | ===== Descriere generală ===== | ||
- | Small robot that is capable of sensing incoming obstacles and avoid them. In hopes of becoming like the original WALL-E one day, He's training to improve his navigation system. Once the switch is turned on, the robot will start moving in a straight line. The ultrasonic sensor placed on the front of the robot will pick up any incoming waves and will translate this into distance in the code. If the received distance will be lower than a certain threshold Mini WALL-E will stop and signal to the motor driver module to turn left until there is nothing in front of him anymore, after which he will continue moving. | + | Small robot that is capable of sensing incoming obstacles and avoid them. Once the switch is turned on, the robot will start moving in a straight line. The ultrasonic sensor placed on the front of the robot will pick up any incoming waves and will translate this into distance in the code. If the received distance will be lower than a certain threshold He will stop and signal to the motor driver module to turn left until there is nothing in front of him anymore, after which he will continue moving. |
{{:pm:prj2022:robert:oa.png?300 |}} | {{:pm:prj2022:robert:oa.png?300 |}} | ||
===== Hardware Design ===== | ===== Hardware Design ===== | ||
- | |||
Components | Components | ||
Line 30: | Line 29: | ||
| Chassis | 1 | | | Chassis | 1 | | ||
| Jumper Wires | 1 | | | Jumper Wires | 1 | | ||
+ | |||
+ | Electric diagram: | ||
+ | |||
+ | {{:pm:prj2022:robert:rob.png?300|}} | ||
===== Software Design ===== | ===== Software Design ===== | ||
- | <note tip> | + | *Development environments used: ArduinoIDE |
- | Descrierea codului aplicaţiei (firmware): | + | |
- | * mediu de dezvoltare (if any) (e.g. AVR Studio, CodeVisionAVR) | + | |
- | * librării şi surse 3rd-party (e.g. Procyon AVRlib) | + | |
- | * algoritmi şi structuri pe care plănuiţi să le implementaţi | + | |
- | * (etapa 3) surse şi funcţii implementate | + | |
- | </note> | + | |
+ | *Used libraries:\\ | ||
+ | https://www.arduino.cc/reference/en/libraries/pcm/ | ||
+ | |||
+ | ==== How It Works ==== | ||
+ | |||
+ | |||
+ | First define trig and echo pin of HC-SR04 in the program. In this project the trig pin is connected to GPIO9 and echo pin is connected to GPIO10 of Arduino NANO. | ||
+ | <code cpp> | ||
+ | int trigPin = 9; // trig pin of HC-SR04 | ||
+ | |||
+ | int echoPin = 10; // Echo pin of HC-SR04 | ||
+ | </code> | ||
+ | Define pins for input of LM298N Motor Driver Module. The LM298N has 4 data input pins used to control the direction of motor connected to it. | ||
+ | <code cpp> | ||
+ | int revleft4 = 4; //REVerse motion of Left motor | ||
+ | int fwdleft5 = 5; //ForWarD motion of Left motor | ||
+ | int revright6 = 6; //REVerse motion of Right motor | ||
+ | int fwdright7 = 7; //ForWarD motion of Right motor | ||
+ | </code> | ||
+ | In setup() function, define the data direction of utilised GPIO pins. The four Motor pins and Trig pin is set as OUTPUT and Echo Pin is set as Input. | ||
+ | <code cpp> | ||
+ | pinMode(revleft4, OUTPUT); // set Motor pins as output | ||
+ | pinMode(fwdleft5, OUTPUT); | ||
+ | pinMode(revright6, OUTPUT); | ||
+ | pinMode(fwdright7, OUTPUT); | ||
+ | pinMode(trigPin, OUTPUT); // set trig pin as output | ||
+ | pinMode(echoPin, INPUT); //set echo pin as input to capture reflected waves | ||
+ | </code> | ||
+ | In loop() function, get the distance from HC-SR04 and based on the distance move the motor direction. The distance will show the object distance coming in front of the robot. The Distance is taken by bursting a beam of ultrasonic up to 10 us and receiving it after 10us. To learn more about measuring distance using Ultrasonic sensor and Arduino, follow the link. | ||
+ | <code cpp> | ||
+ | digitalWrite(trigPin, LOW); | ||
+ | delayMicroseconds(2); | ||
+ | digitalWrite(trigPin, HIGH); // send waves for 10 us | ||
+ | delayMicroseconds(10); | ||
+ | duration = pulseIn(echoPin, HIGH); // receive reflected waves | ||
+ | distance = duration / 58.2; // convert to distance | ||
+ | delay(10); | ||
+ | </code> | ||
+ | If the distance is greater than the defined distance means there is not obstacle in its path and it will moving in forward direction. | ||
+ | <code cpp> | ||
+ | if (distance > 19) | ||
+ | { | ||
+ | digitalWrite(fwdright7, HIGH); // move forward | ||
+ | digitalWrite(revright6, LOW); | ||
+ | digitalWrite(fwdleft5, HIGH); | ||
+ | digitalWrite(revleft4, LOW); | ||
+ | } | ||
+ | </code> | ||
+ | If the distance is less than the defined distance to avoid obstacle means there is some obstacle ahead. So in this situation robot will stop for a while and movebackwards after that again stop for a while and then take turn to another direction. | ||
+ | <code cpp> | ||
+ | if (distance < 18) | ||
+ | { | ||
+ | digitalWrite(fwdright7, LOW); //Stop | ||
+ | digitalWrite(revright6, LOW); | ||
+ | digitalWrite(fwdleft5, LOW); | ||
+ | digitalWrite(revleft4, LOW); | ||
+ | delay(500); | ||
+ | digitalWrite(fwdright7, LOW); //movebackword | ||
+ | digitalWrite(revright6, HIGH); | ||
+ | digitalWrite(fwdleft5, LOW); | ||
+ | digitalWrite(revleft4, HIGH); | ||
+ | delay(500); | ||
+ | digitalWrite(fwdright7, LOW); //Stop | ||
+ | digitalWrite(revright6, LOW); | ||
+ | digitalWrite(fwdleft5, LOW); | ||
+ | digitalWrite(revleft4, LOW); | ||
+ | delay(100); | ||
+ | digitalWrite(fwdright7, HIGH); | ||
+ | digitalWrite(revright6, LOW); | ||
+ | digitalWrite(revleft4, LOW); | ||
+ | digitalWrite(fwdleft5, LOW); | ||
+ | delay(500); | ||
+ | } | ||
+ | </code> | ||
+ | This is how a robot can avoid obstacles in its path without getting stuck anywhere. | ||
===== Rezultate Obţinute ===== | ===== Rezultate Obţinute ===== | ||
Line 49: | Line 121: | ||
===== Concluzii ===== | ===== Concluzii ===== | ||
- | ===== Download ===== | + | After finishing the project, I learned that:\\ |
+ | *While the code is simple, the hardest part was the making of the chasis. | ||
- | <note warning> | + | *Some parts have very tough bolts to unscrew which led to a lot of wasted time |
- | O arhivă (sau mai multe dacă este cazul) cu fişierele obţinute în urma realizării proiectului: surse, scheme, etc. Un fişier README, un ChangeLog, un script de compilare şi copiere automată pe uC crează întotdeauna o impresie bună ;-). | + | |
- | Fişierele se încarcă pe wiki folosind facilitatea **Add Images or other files**. Namespace-ul în care se încarcă fişierele este de tipul **:pm:prj20??:c?** sau **:pm:prj20??:c?:nume_student** (dacă este cazul). **Exemplu:** Dumitru Alin, 331CC -> **:pm:prj2009:cc:dumitru_alin**. | + | *It was fun to see it work after all the effort put in it |
- | </note> | + | |
+ | ===== Download ===== | ||
- | ===== Jurnal ===== | + | {{:pm:prj2022:robert:obsav.rar|Source Code}} |
+ | |||
+ | {{:pm:prj2022:robert:rob.png?linkonly|Electric Diagram}} | ||
- | <note tip> | ||
- | Puteți avea și o secțiune de jurnal în care să poată urmări asistentul de proiect progresul proiectului. | ||
- | </note> | ||
===== Bibliografie/Resurse ===== | ===== Bibliografie/Resurse ===== | ||
- | <note> | + | *[[https://store.arduino.cc/products/arduino-uno-rev3/|Arduino UNO]] |
- | Listă cu documente, datasheet-uri, resurse Internet folosite, eventual grupate pe **Resurse Software** şi **Resurse Hardware**. | + | *[[https://www.newark.com/stmicroelectronics/l298n/ic-bridge-driver-dual-298/dp/10WX1394?rpsku=rel1:32M1527&isexcsku=false|SparkFun Dual H-Bridge motor drivers L298]] |
- | </note> | + | *[[https://www.sparkfun.com/products/15569|SparkFun Ultrasonic Sensor - HC-SR04]] |
<html><a class="media mediafile mf_pdf" href="?do=export_pdf">Export to PDF</a></html> | <html><a class="media mediafile mf_pdf" href="?do=export_pdf">Export to PDF</a></html> | ||