Differences

This shows you the differences between two versions of the page.

Link to this comparison view

pm:prj2025:vradulescu:robert_ion.bolfa [2025/05/25 23:38]
robert_ion.bolfa [6. Audio Control Functions]
pm:prj2025:vradulescu:robert_ion.bolfa [2025/05/26 00:04] (current)
robert_ion.bolfa [Jurnal]
Line 53: Line 53:
  
  
 +===== Software Design =====
  
-= Software Design =+NOTA: 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
  
 +================================================================================
  
 +MEDIU DE DEZVOLTARE
  
 +Arduino IDE 2.3.2
 +- Compilator: AVR-GCC 7.3.0 pentru microcontroller ATmega328P
 +- Target Platform: Arduino UNO R3 (ATmega328P @ 16MHz)
 +- Upload Protocol: AVR109 (USB-to-Serial via CH340/FTDI)
 +- Debugging: Serial Monitor la 9600 baud rate
  
 +Configurări Compilare:
 +    #pragma GCC optimize("​O2"​) ​       // Optimizare nivel 2
 +    #define F_CPU 16000000UL ​         // Clock 16MHz
  
 +================================================================================
  
-==== 7. Utility Functions ==== +LIBRĂRII ȘI SURSE 3RD-PARTY
-<​pre>​ +
-void printSystemInfo() { +
-    // Debug information output +
-    // Pin configuration display +
-    // System status monitoring +
-}+
  
-bool validateDistance(float dist) { +Core Arduino Libraries: 
-    // Input validation pentru măsurători +    ​#include <​Servo.h> ​               ​// v1.2.1 Control PWM servomotoare 
-    // Range checking: ​2-400cm +    ​#include <​SoftwareSerial.h> ​      // v1.0 - UART software pentru DFPlayer
-    // Invalid reading filtering +
-+
-</​pre>​+
  
-----+External Libraries:​ 
 +    #include <​DFRobotDFPlayerMini.h> ​ // v1.0.6 ​Control DFPlayer Mini
  
-== Memory & Performance Metrics ==+- Sursă: DFRobot Official Library (GitHub: 2.1M downloads) 
 +- Funcționalitate:​ Control complet player audio MP3 
 +- Protocoale: Serial AT commands pentru control volum/track
  
-=== Resource Utilization === +Hardware Abstraction Layer: 
-<pre> +    #​define TRIG_PIN 2 
-// Flash Memory Usage +    #​define ECHO_PIN 3 
-Program Storage: ~18,432 bytes (56.9% of 32,256 bytes) +    #​define SERVO1_PIN 4 
-Dynamic Memory: ~1,024 bytes (50.0% of 2,048 bytes)+    #​define SERVO2_PIN 5 
 +    #define DFPLAYER_RX 6 
 +    #define DFPLAYER_TX 7
  
-// Execution Performance ​  +================================================================================
-Setup Time: ~2 seconds (DFPlayer init) +
-Loop Cycle: ~100ms (măsurare + processing) +
-Interrupt Response: <50µs (hardware priority) +
-</​pre>​+
  
-=== Algorithm Complexity === +ALGORITMI ȘI STRUCTURI IMPLEMENTATE
-* '''​measureDistance()''':​ O(1) - constant time +
-* '''​State transitions''':​ O(1) - boolean comparison ​  +
-* '''​PWM generation''':​ O(1) - hardware timer +
-* '''​ISR execution''':​ O(1) - direct flag setting+
  
-----+1. Algoritm Măsurare Distanță (Time-of-Flight)
  
-== Software Architecture Pattern ==+Algorithm: measureDistance() 
 +Input: None (GPIO control) 
 +Output: float distance [cm] 
 +Complexity: O(1) - constant time
  
-=== Event-Driven Architecture ​=== +Pseudocode:​ 
-<pre>+1. Generate 10µs TRIG pulse 
 +2. Measure ECHO pulse duration 
 +3. Apply formula: distance ​(duration * 0.034) / 2 
 +4. Validate result (timeout handling) 
 + 
 +-------------------------------------------------------------------------------- 
 + 
 +2. State Machine pentru Proximity Detection 
 + 
 +States: {IDLE, NEAR, FAR} 
 +Transitions:​  
 +    distance < 30cm → NEAR 
 +    distance ≥ 30cm → FAR 
 +             
 +State Actions: 
 +    - NEAR: servo.write(90°) + play(001.mp3) 
 +    - FAR:  servo.write(270°) + play(002.mp3) 
 + 
 +-------------------------------------------------------------------------------- 
 + 
 +3. Interrupt Service Routine (ISR) 
 + 
 +Algorithm: echoInterrupt() 
 +Trigger: CHANGE on Pin 3 (INT1) 
 +Features:  
 +    - Debounce filtering (200ms window) 
 +    - Volatile flag setting 
 +    - Non-blocking execution (<​10µs) 
 + 
 +-------------------------------------------------------------------------------- 
 + 
 +4. PWM Control Algorithm 
 + 
 +Function: moveServosTo(angle) 
 +Input: int angle [0-359°] 
 +Process:  
 +    - Convert angle to PWM duty cycle 
 +    - Simultaneous dual servo control 
 +    - Non-blocking execution 
 + 
 +================================================================================ 
 + 
 +STRUCTURI DE DATE 
 + 
 +Global Variables:​ 
 +    // Volatile pentru ISR communication 
 +    volatile bool proximityDetected = false; 
 +    volatile unsigned long lastInterruptTime = 0; 
 + 
 +    // State management 
 +    float distance = 0; 
 +    bool isClose = false; 
 +    bool lastState = false; 
 + 
 +    // Configuration constants 
 +    const float THRESHOLD_DISTANCE = 30.0; // cm 
 +    const unsigned long DEBOUNCE_TIME = 200; // ms 
 + 
 +Object Instances:​ 
 +    Servo servo1, servo2; ​                   // PWM control objects 
 +    SoftwareSerial dfPlayerSerial(7,​ 8);     // UART software instance 
 +    DFRobotDFPlayerMini dfPlayer; ​           // Audio player controller 
 + 
 +================================================================================ 
 + 
 +SURSE ȘI FUNCȚII IMPLEMENTATE (ETAPA 3) 
 + 
 +CORE FUNCTIONS:​ 
 + 
 +1. Setup & Initialization 
 +    void setup() 
 +    ├── Serial.begin(9600) ​          // Debug interface 
 +    ├── GPIO_Config() ​               // Pin modes pentru TRIG/ECHO 
 +    ├── PWM_Config() ​                // Servo attachment 
 +    ├── Interrupt_Config() ​          // INT1 setup pe ECHO 
 +    └── Audio_Init() ​                // DFPlayer initialization 
 + 
 +2. Main Control Loop 
 +    void loop() 
 +    ├── distance = measureDistance() ​   // GPIO măsurare 
 +    ├── stateCheck(distance) ​          // State machine logic 
 +    ├── actionExecution() ​             // PWM + Audio control 
 +    └── serialDebug() ​                 // Monitoring output 
 + 
 +3. GPIO Control Functions 
 +    float measureDistance() { 
 +        // Time-of-flight calculation 
 +        // Input: GPIO pulse generation 
 +        // Output: Distance în cm 
 +        // Error handling: timeout protection 
 +    } 
 + 
 +4. PWM Control Functions 
 +    void moveServosTo(int angle) { 
 +        // Simultaneous dual servo control 
 +        // PWM signal generation @ 50Hz 
 +        // Angle range: 0-359° (cu overflow handling) 
 +    } 
 + 
 +    void activateProximityMode() { 
 +        // Composite action: PWM + Audio 
 +        // Servo rotation: 0° → 90° 
 +        // Audio trigger: 001.mp3 
 +    } 
 + 
 +    void deactivateProximityMode() { 
 +        // Composite action: PWM + Audio   
 +        // Servo rotation: 90° → 270° (-90°) 
 +        // Audio trigger: 002.mp3 
 +    } 
 + 
 +5. Interrupt Handling 
 +    void echoInterrupt() { 
 +        // ISR pentru ECHO pin change 
 +        // Debounce protection 
 +        // Flag setting pentru main loop 
 +        // Execution time: <10µs 
 +    } 
 + 
 +6. Audio Control Functions 
 +    bool initializeDFPlayer() { 
 +        // DFPlayer initialization sequence 
 +        // Volume configuration (0-30) 
 +        // SD card validation 
 +        // Error handling pentru connection 
 +    } 
 + 
 +7. Utility Functions 
 +    void printSystemInfo() { 
 +        // Debug information output 
 +        // Pin configuration display 
 +        // System status monitoring 
 +    } 
 + 
 +    bool validateDistance(float dist) { 
 +        // Input validation pentru măsurători 
 +        // Range checking: 2-400cm 
 +        // Invalid reading filtering 
 +    } 
 + 
 +================================================================================ 
 + 
 +MEMORY & PERFORMANCE METRICS 
 + 
 +Resource Utilization:​ 
 +    Flash Memory Usage: 
 +    Program Storage: ~18,432 bytes (56.9% of 32,256 bytes) 
 +    Dynamic Memory: ~1,024 bytes (50.0% of 2,048 bytes) 
 + 
 +    Execution Performance: ​  
 +    Setup Time: ~2 seconds (DFPlayer init) 
 +    Loop Cycle: ~100ms (măsurare + processing) 
 +    Interrupt Response: ​<50µs (hardware priority) 
 + 
 +Algorithm Complexity:​ 
 +    - measureDistance():​ O(1) - constant time 
 +    - State transitions:​ O(1) - boolean comparison ​  
 +    - PWM generation: O(1) - hardware timer 
 +    - ISR execution: O(1) - direct flag setting 
 + 
 +================================================================================ 
 + 
 +SOFTWARE ARCHITECTURE PATTERN 
 + 
 +Event-Driven Architecture:​
 Hardware Events → ISR → Flag Setting → Main Loop Processing → Action Execution Hardware Events → ISR → Flag Setting → Main Loop Processing → Action Execution
       ↑              ↑         ​↑ ​             ↑                    ↑       ↑              ↑         ​↑ ​             ↑                    ↑
    ​GPIO/​Timer ​   Interrupt ​  ​Volatile ​     State Machine ​     PWM/Serial    ​GPIO/​Timer ​   Interrupt ​  ​Volatile ​     State Machine ​     PWM/Serial
-</​pre>​ 
  
-=== Non-Blocking Design ​=== +Non-Blocking Design: 
-* '''​Concurrent execution'''​: PWM, Audio, GPIO în paralel +    ​- ​Concurrent execution: PWM, Audio, GPIO în paralel 
-* '''​Interrupt priority'''​: Hardware events cu prioritate maximă ​  +    ​- ​Interrupt priority: Hardware events cu prioritate maximă ​  
-* '''​Timer-based delays'''​: Evitarea blocking calls în loop principal+    ​- ​Timer-based delays: Evitarea blocking calls în loop principal
  
-----+================================================================================
  
-== Error Handling ​Recovery ==+ERROR HANDLING ​RECOVERY
  
-=== Implemented Safeguards ​=== +Implemented Safeguards: 
-<pre> +    // Timeout protection 
-// Timeout protection +    long duration = pulseIn(ECHO_PIN,​ HIGH, 30000); 
-long duration = pulseIn(ECHO_PIN,​ HIGH, 30000); +    if (duration == 0) return 0; // Invalid reading 
-if (duration == 0) return 0; // Invalid reading+ 
 +    // Debounce filtering ​  
 +    if (currentTime - lastInterruptTime < DEBOUNCE_TIME) return; 
 + 
 +    // DFPlayer connection validation 
 +    if (!dfPlayer.begin(dfPlayerSerial)) { 
 +        Serial.println("​DFPlayer Error!"​);​ 
 +        while(true) delay(0); // Safe halt 
 +    } 
 + 
 +Graceful Degradation:​ 
 +    - Sensor failure: Continue operation cu last known state 
 +    - Audio failure: Maintain servo functionality ​  
 +    - Power fluctuations:​ Automatic recovery după reset 
 + 
 +================================================================================ 
 + 
 +TABEL FUNCȚII IMPLEMENTATE 
 +setup() -> Init; loop -> Main; measureDistande() -> GPIO; moveServosTo() -> PWM; echoInterrupt() -> ISR; activateProximityMode() -> Composite 
 +deactivateProximityMode()->​ Composite; initializeDfplayer() -> audio 
 +    ​
  
-// Debounce filtering  ​ 
-if (currentTime - lastInterruptTime < DEBOUNCE_TIME) return; 
  
-// DFPlayer connection validation 
-if (!dfPlayer.begin(dfPlayerSerial)) { 
-    Serial.println("​DFPlayer Error!"​);​ 
-    while(true) delay(0); // Safe halt 
-} 
-</​pre>​ 
  
-=== Graceful Degradation === 
-* '''​Sensor failure''':​ Continue operation cu last known state 
-* '''​Audio failure''':​ Maintain servo functionality  ​ 
-* '''​Power fluctuations''':​ Automatic recovery după reset 
  
----- 
  
-== Tabel Funcții Implementate == 
  
-{| class="​wikitable"​ 
-|- 
-! Funcție !! Tip !! Complexitate !! Descriere 
-|- 
-| <​code>​setup()</​code>​ || Initialization || O(1) || Configurare hardware și librării 
-|- 
-| <​code>​loop()</​code>​ || Main Control || O(1) || Bucla principală non-blocking 
-|- 
-| <​code>​measureDistance()</​code>​ || GPIO || O(1) || Măsurare ultrasonică Time-of-Flight 
-|- 
-| <​code>​moveServosTo()</​code>​ || PWM || O(1) || Control sincronizat dual servo 
-|- 
-| <​code>​echoInterrupt()</​code>​ || ISR || O(1) || Handler întrerupere cu debounce 
-|- 
-| <​code>​activateProximityMode()</​code>​ || Composite || O(1) || PWM + Audio pentru apropriere 
-|- 
-| <​code>​deactivateProximityMode()</​code>​ || Composite || O(1) || PWM + Audio pentru îndepărtare 
-|- 
-| <​code>​initializeDFPlayer()</​code>​ || Audio || O(1) || Setup player MP3 cu validare 
-|} 
 ===== Rezultate Obţinute ===== ===== Rezultate Obţinute =====
  
 <note tip> <note tip>
-Care au fost rezultatele obţinute în urma realizării ​proiectului ​vostru.+In urma realizarii ​proiectului ​, in cele din urma dupa mult debug si multi nervi totul merge conform asteptarilor. Atunci cand ma apropii de senzor  
 +, masca se deschide si un sunet canta inauntrul ei din difuzorul atasat la mini dfplayer.
 </​note>​ </​note>​
  
 ===== Concluzii ===== ===== Concluzii =====
 +Am ramas cu un gust placut dupa acest proiect, m-a facut sa imi explorez iubita pasiune de a face lego la un alt nivel :D 
 ===== Download ===== ===== Download =====
  
-<note warning>​ +https://github.com/​Robert326/​IronMan_Mask
-O arhivă (sau mai multe dacă este cazul) cu fişierele obţinute în urma realizării proiectuluisurse, 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**. 
-</​note>​ 
  
-===== Jurnal ===== 
- 
-<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 =====
pm/prj2025/vradulescu/robert_ion.bolfa.1748205495.txt.gz · Last modified: 2025/05/25 23:38 by robert_ion.bolfa
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0