This shows you the differences between two versions of the page.
pm:prj2021:abasoc:dariuscell [2021/06/03 02:47] radu.nichita [Asamblarea robotului] |
pm:prj2021:abasoc:dariuscell [2021/06/03 16:54] (current) radu.nichita [Software Design] |
||
---|---|---|---|
Line 15: | Line 15: | ||
===== Motivație ===== | ===== Motivație ===== | ||
- | * dorința de a combina integra în cadrul unui proiect cunoșțințele de Android dobândite în cadrul workshop-ului [[https://ocw.cs.pub.ro/courses/moby|Mobylab]] | ||
* participarea la concursul [[https://perpetuum.lsacbucuresti.ro/| Perpetuum]], unde am realizat un automat de dat pagini | * participarea la concursul [[https://perpetuum.lsacbucuresti.ro/| Perpetuum]], unde am realizat un automat de dat pagini | ||
+ | * dorința de a realiza un robot, ce poate evita obstacolele și să să fie controlat de pe telefon. (acesta poate fi apoi îmbunătățit pentru a filma și a monitoriza locuința de la distanță). | ||
===== Structură proiect===== | ===== Structură proiect===== | ||
Line 51: | Line 51: | ||
===== Schema bloc ===== | ===== Schema bloc ===== | ||
- | {{:pm:prj2021:abasoc:schema_pm_dariuscell_initial.jpg?750|}} | + | {{:pm:prj2021:abasoc:dariuscell_schema_bloc.png?750|}} |
===== Schema electrică ===== | ===== Schema electrică ===== | ||
Line 78: | Line 78: | ||
* s = mișcare înapoi, urmată de oprire | * s = mișcare înapoi, urmată de oprire | ||
* q = oprirea robotului | * q = oprirea robotului | ||
- | * De ce toate operațiile în afară de w necesită oprire? Pentru că partea frontală a robotului are montat un senzor ultrasonic, capabil să detecteze obstacolele din față. El se va opri automat când va ajunge la o distanță apropiată de acestea, fără a se ciocni de ele. | + | * De ce toate operațiile în afară de w necesită oprire? Pentru că partea frontală a robotului are montat un senzor ultrasonic, capabil să detecteze obstacolele din față. El se va opri automat când va ajunge la o distanță apropiată de acestea, fără a se ciocni de ele. |
+ | |||
+ | <spoiler Cod Arduino> | ||
+ | <code cpp> | ||
+ | #include <SoftwareSerial.h> | ||
+ | |||
+ | |||
+ | #define DELTA_SPEED 10 // increase / decrease in speed; | ||
+ | #define MIN_SPEED_ALLOWED 120 | ||
+ | #define BALANCE_DIFFERENCE 17 | ||
+ | |||
+ | #define SPEED 127 | ||
+ | #define SPEED_TURNING 100 | ||
+ | |||
+ | #define UP_DIRECTION 'w' | ||
+ | #define DOWN_DIRECTION 's' | ||
+ | #define STOP_DIRECTION 'q' | ||
+ | #define LEFT_DIRECTION 'a' | ||
+ | #define RIGHT_DIRECTION 'd' | ||
+ | |||
+ | int In3 = 8; // left wheel - int3 | ||
+ | int In4 = 9; // left wheel - int4 | ||
+ | int In2 = 12; // right wheel - int2 | ||
+ | int In1 = 13; // right wheel - int1 | ||
+ | int ENA = 5; // left wheel | ||
+ | int ENB = 6; // right wheel | ||
+ | int robot_speed = 0; | ||
+ | |||
+ | |||
+ | bool goesForward = false; | ||
+ | bool moving = false; | ||
+ | int rx_pin = 4; // pin 4 as RX | ||
+ | int tx_pin = 2; // pin 2 as TX | ||
+ | |||
+ | |||
+ | SoftwareSerial BTSerial(tx_pin, rx_pin); | ||
+ | |||
+ | char bt_data; | ||
+ | String arduino_data; | ||
+ | |||
+ | |||
+ | void setup() | ||
+ | { | ||
+ | |||
+ | |||
+ | pinMode(In1, OUTPUT); | ||
+ | pinMode(In2, OUTPUT); | ||
+ | pinMode(ENA, OUTPUT); | ||
+ | |||
+ | pinMode(In3, OUTPUT); | ||
+ | pinMode(In4, OUTPUT); | ||
+ | pinMode(ENB, OUTPUT); | ||
+ | |||
+ | digitalWrite(In1, LOW); | ||
+ | digitalWrite(In2, HIGH); | ||
+ | |||
+ | digitalWrite(In3, LOW); | ||
+ | digitalWrite(In4, HIGH); | ||
+ | |||
+ | analogWrite(ENA, robot_speed); | ||
+ | analogWrite(ENB, robot_speed); | ||
+ | |||
+ | BTSerial.begin(9600); | ||
+ | Serial.begin(9600); | ||
+ | delay(1000); | ||
+ | } | ||
+ | |||
+ | |||
+ | void moveForward() { | ||
+ | |||
+ | if(!goesForward || !moving) { | ||
+ | moveStop(); | ||
+ | goesForward = true; | ||
+ | moving = true; | ||
+ | digitalWrite(In1, LOW); | ||
+ | digitalWrite(In2, HIGH); | ||
+ | |||
+ | digitalWrite(In3, LOW); | ||
+ | digitalWrite(In4, HIGH); | ||
+ | |||
+ | for (; robot_speed < SPEED; robot_speed +=2) { | ||
+ | analogWrite(ENA, robot_speed + BALANCE_DIFFERENCE); | ||
+ | analogWrite(ENB, robot_speed); | ||
+ | delay(5); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void moveStop() { | ||
+ | for (; robot_speed > 0; robot_speed -=2) { | ||
+ | analogWrite(ENA, robot_speed + BALANCE_DIFFERENCE); | ||
+ | analogWrite(ENB, robot_speed); | ||
+ | delay(5); | ||
+ | } | ||
+ | robot_speed = 0; | ||
+ | analogWrite(ENA, robot_speed); | ||
+ | analogWrite(ENB, robot_speed); | ||
+ | moving = false; | ||
+ | } | ||
+ | |||
+ | void moveBackward() { | ||
+ | if(goesForward || !moving) { | ||
+ | moveStop(); | ||
+ | moving = true; | ||
+ | goesForward=false; | ||
+ | digitalWrite(In1, HIGH); | ||
+ | digitalWrite(In2, LOW); | ||
+ | digitalWrite(In3, HIGH); | ||
+ | digitalWrite(In4, LOW); | ||
+ | for (; robot_speed <SPEED; robot_speed +=2) { | ||
+ | analogWrite(ENA, robot_speed + BALANCE_DIFFERENCE); | ||
+ | analogWrite(ENB, robot_speed); | ||
+ | delay(5); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void turnLeft() { | ||
+ | if (moving) { | ||
+ | analogWrite(ENA, 0); | ||
+ | analogWrite(ENB, SPEED); | ||
+ | delay(300); | ||
+ | robot_speed = SPEED; | ||
+ | for (; robot_speed > 0; robot_speed -=2) { | ||
+ | analogWrite(ENB, robot_speed); | ||
+ | delay(5); | ||
+ | } | ||
+ | analogWrite(ENA, 0); | ||
+ | analogWrite(ENB, 0); | ||
+ | moving = false; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void turnRight() { | ||
+ | if (moving) { | ||
+ | analogWrite(ENA, SPEED); | ||
+ | analogWrite(ENB, 0); | ||
+ | delay(300); | ||
+ | robot_speed = SPEED; | ||
+ | for (; robot_speed > 0; robot_speed -=2) { | ||
+ | analogWrite(ENA, robot_speed); | ||
+ | delay(5); | ||
+ | } | ||
+ | analogWrite(ENA, 0); | ||
+ | analogWrite(ENB, 0); | ||
+ | moving = false; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | if (BTSerial.available()) { | ||
+ | bt_data = BTSerial.read(); | ||
+ | if (bt_data == UP_DIRECTION) { | ||
+ | moveForward(); | ||
+ | } else if (bt_data == DOWN_DIRECTION) { | ||
+ | moveBackward(); | ||
+ | } else if (bt_data == STOP_DIRECTION){ | ||
+ | moveStop(); | ||
+ | } else if (bt_data == LEFT_DIRECTION) { | ||
+ | turnLeft(); | ||
+ | } else if (bt_data == RIGHT_DIRECTION) { | ||
+ | turnRight(); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | </spoiler> | ||
====== Rezultate Obținute ====== | ====== Rezultate Obținute ====== | ||
- | TODO | + | |
+ | {{:pm:prj2021:abasoc:dariuscell_pozafata.jpeg?750|}} | ||
+ | |||
+ | |||
+ | {{:pm:prj2021:abasoc:dariuscell_pozaspate.jpeg?750|}} | ||
+ | |||
+ | {{:pm:prj2021:abasoc:dariuscell_pozalateral.jpeg?750|}} | ||
====== Concluzie ====== | ====== Concluzie ====== | ||
Line 116: | Line 290: | ||
* Un scurt videoclip cu controlarea robotului se poate găsi [[https://ctipub-my.sharepoint.com/:v:/g/personal/radu_nichita_stud_acs_upb_ro/EVXoO72hb6tLpcfEDG2-atsBtVpu9aZRlXRrDzkYLEsNXg?e=146yws | aici]] | * Un scurt videoclip cu controlarea robotului se poate găsi [[https://ctipub-my.sharepoint.com/:v:/g/personal/radu_nichita_stud_acs_upb_ro/EVXoO72hb6tLpcfEDG2-atsBtVpu9aZRlXRrDzkYLEsNXg?e=146yws | aici]] | ||
+ | |||
+ | * Schema electrică [[https://ctipub-my.sharepoint.com/:u:/g/personal/radu_nichita_stud_acs_upb_ro/EdArhdfFa9RKgb9fSnLsFksBLKbnhHqRDocTF867bN8BNA?e=0rcr1b | schema_electrica2021.sch]] | ||
====== Documentație ====== | ====== Documentație ====== |