Differences

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

Link to this comparison view

pm:prj2026:vlad.radulescu2901:viorel_cosmin.cucu [2026/05/16 22:00]
viorel_cosmin.cucu
pm:prj2026:vlad.radulescu2901:viorel_cosmin.cucu [2026/05/24 19:15] (current)
viorel_cosmin.cucu [Components and Their Role]
Line 34: Line 34:
   * **Outputs:​** The ESC drives the main motor (speed), the L298N drives the steering motor (direction),​ the LCD shows status, the buzzer gives audio alerts, and the LEDs provide lighting.   * **Outputs:​** The ESC drives the main motor (speed), the L298N drives the steering motor (direction),​ the LCD shows status, the buzzer gives audio alerts, and the LEDs provide lighting.
 ==== Block Diagram ==== ==== Block Diagram ====
-{{:​pm:​prj2026:​vlad.radulescu2901:​block_diagram.jpg?500|}}+{{:​pm:​prj2026:​vlad.radulescu2901:​schema_bloc_cucu.jpg?500|}}
  
  
Line 49: Line 49:
 | Traction Motor | 390 DC Motor (7.4V) | Drives the rover forward and backward from Battery 2's dedicated high-current rail. | | Traction Motor | 390 DC Motor (7.4V) | Drives the rover forward and backward from Battery 2's dedicated high-current rail. |
 | Steering Motor | 3–6V DC Motor | Turns the front axle left or right under L298N control. | | Steering Motor | 3–6V DC Motor | Turns the front axle left or right under L298N control. |
-| Motor Driver | L298N H-Bridge | Accepts PWM (ENA) and two direction pins (IN1/IN2) to drive the steering DC motor. |+| Motor Driver | L298N H-Bridge | Two direction pins (IN1/IN2) to drive the steering DC motor. |
 | LCD Display | 1602 LCD + PCF8574 I2C | "Smart dashboard":​ shows expressive animated eyes in normal mode, parking assist in reverse. | | LCD Display | 1602 LCD + PCF8574 I2C | "Smart dashboard":​ shows expressive animated eyes in normal mode, parking assist in reverse. |
 | Active Buzzer | TMB12A05 5V | Proximity alert (beep rate increases near obstacles) and horn command from phone. | | Active Buzzer | TMB12A05 5V | Proximity alert (beep rate increases near obstacles) and horn command from phone. |
Line 67: Line 67:
 | D4 | PD4 | GPIO Output | HC-SR04 Rear - TRIG | Same reason as D2; rear sensor pins grouped on D4/D5. | | D4 | PD4 | GPIO Output | HC-SR04 Rear - TRIG | Same reason as D2; rear sensor pins grouped on D4/D5. |
 | D5 | PD5 | GPIO Input | HC-SR04 Rear - ECHO | Paired with D4. Mirrors front sensor logic for parking assist. | | D5 | PD5 | GPIO Input | HC-SR04 Rear - ECHO | Paired with D4. Mirrors front sensor logic for parking assist. |
-| D6 | PD6 | Timer 0, OC0A (Fast PWM) | L298N ENA | Only OC0A or OC0B can output Timer 0 PWM. D6 = OC0A - sets steering motor duty cycle (0–255). | 
 | D7 | PD7 | GPIO Output | Headlight LEDs + 220Ω | Simple digital ON/OFF for the LED array. D7 is free from any timer to avoid conflicts. | | D7 | PD7 | GPIO Output | Headlight LEDs + 220Ω | Simple digital ON/OFF for the LED array. D7 is free from any timer to avoid conflicts. |
 | D8 | PB0 | GPIO Output | L298N IN1 | Direction bit for steering H-bridge. No special hardware needed - plain digital output. | | D8 | PB0 | GPIO Output | L298N IN1 | Direction bit for steering H-bridge. No special hardware needed - plain digital output. |
Line 81: Line 80:
  
 ==== Key Design Choices & Electrical Schematic ==== ==== Key Design Choices & Electrical Schematic ====
-{{:​pm:​prj2026:​vlad.radulescu2901:​cica_schema_cucu.jpg?650|}}+{{:​pm:​prj2026:​vlad.radulescu2901:​schema_cucu_elec.png?650|}}
  
  
-{{:​pm:​prj2026:​vlad.radulescu2901:​kicad_cucu.pdf|}}+{{:​pm:​prj2026:​vlad.radulescu2901:​kicad_cucu2.pdf|}}
  
 The electrical schematic above illustrates the complete wiring of the Land Buster rover. The hardware architecture is built upon the following core engineering rules: The electrical schematic above illustrates the complete wiring of the Land Buster rover. The hardware architecture is built upon the following core engineering rules:
Line 126: Line 125:
 ===== Software Design ===== ===== Software Design =====
  
-==== Development Environment ====+==== Development Environment ​& Libraries Motivation ​====
   * **IDE:** PlatformIO (VS Code)   * **IDE:** PlatformIO (VS Code)
-  * **Language:​** ​Pure AVR +  * **Language:​** C++ (Arduino framework) 
-  * **Compiler:** avr-gcc +  * **AI Assistance:** I used Claude Opus AI to assist with writing the code, structuring the non-blocking logic, and debugging hardware timer issues. 
-  * **Target:** ATmega328P ​Xplained Mini+  * **Libraries Motivation:** 
 +    * ''<​Arduino.h>'':​ The core framework library. I used it for essential built-in functions like ''​millis()''​ (crucial for my non-blocking state machines), ''​pulseIn()''​ (to safely read ultrasonic sensors with a strict timeout), and basic GPIO control (''​pinMode'',​ ''​digitalWrite'',​ ''​analogRead''​). 
 +    * ''<​Wire.h>'':​ The standard I2C library. Used to abstract the low-level TWI (Two-Wire Interface) hardware registers of the ATmega328P, providing robust communication with I2C devices. 
 +    * ''<​LiquidCrystal_I2C.h>'':​ An external library that relies on ''<​Wire.h>''​. It handles the complex data formatting required by the PCF8574 I2C expander attached to the 1602 LCD. I chose to use this library because writing a custom I2C LCD driver from scratch would be redundant and reinventing the wheel, allowing me to easily display custom animated characters. Everything else (like PWM and Timers) was implemented using direct register manipulation.
  
-==== Source Files ==== +==== Justification of Laboratory Functionalities ​==== 
-<​code>​ +The project actively uses 5 core concepts from the PM laboratory: 
-src/ +  * **USARTDebugging ​(Laboratorul ​1):** Essential for wireless communicationThe HC-05 module receives driving commands from the Android phone via the hardware USART peripheral at 9600 baud. 
-├── main.c ​         # Main loop, ISR, command dispatcher +  * **Întreruperi,​ Timere ​(Laboratorul ​2):** Critical for the non-blocking architectureThe project heavily relies on ''​millis()''​ (which operates via Timer 0 overflow interrupts) to manage sensor timing, signal debouncing, and connection failsafe timeouts without halting the CPU. 
-├── usart.c / .h    # USART driver + printf via stdout ​(Lab 1) +  * **Timere, Pulse Width Modulation - PWM (Laboratorul 3):** Used to control ​the speed of the main traction motor via the ESC. Timer 1 (16-bitis manually configured via hardware registers (''​TCCR1A'',​ ''​TCCR1B'',​ ''​ICR1''​) in Fast PWM mode to generate a highly precise 50Hz signalThe ''​OCR1B''​ register is varied between 3500 and 4000 to achieve 4 different speed gears. 
-├── ultrasonic.c    # HC-SR04 distance measurement ​(Lab 2) +  * **Analog Digital Convertor - ADC (Laboratorul ​4):** Used to read the analog voltage from the photoresistor (LDR)The ADC converts the light intensity into a digital value, which is compared against a threshold ​to automatically toggle the headlights. 
-├── motor.c         # ​PWM steering ​control via L298N (Lab 3) +  * **I2C (Laboratorul 6):** Used to communicate with the PCF8574 expander on the back of the 1602 LCD, saving valuable GPIO pins.
-├── adc.c / .h      # ADC driver for photoresistor ​(Lab 4) +
-└── task1.c         # ​ADC read + threshold ​logic (tested standalone) +
-</​code>​+
  
-==== Lab 1 - USART: Bluetooth Control ​==== +==== Project Skeleton, Interaction,​ and Validation ​==== 
-The HC-05 sends bytes from the phone app at 9600 baud. The **RX Complete Interrupt ​(RXCIE0)** fires automatically when byte arrives.+The software is structured around a single, highly optimized, non-blocking ''​loop()'':​ 
 +  ​* **Interaction:​** The loop continuously checks for incoming Bluetooth commands. It then alternates reading the front and rear ultrasonic sensors. Based on the distances, it evaluates the Autonomous Emergency Braking ​(AEBlogic. Finally, it sets the motor outputs and updates the LCD animations without using any delays. 
 +  ​* **Validation:​** I validated the system by building ​custom Android application that receives live telemetry from the car (sensor distances, light levels, active gear). I tested edge cases by driving at full speed towards walls to ensure the AEB triggers correctly and stops the car before impact.
  
-<code c> +==== Sensor Calibration ==== 
-// usart.c +  * **Photoresistor ​(LDR):** It is connected in a voltage divider with a 10kΩ resistor. I calibrated the software by reading the ADC values in different lighting conditions. I set the threshold to ''​400''​ so the headlights turn on automatically only when the room gets dark. 
-void USART0_init(unsigned int ubrr) { +  * **Ultrasonic Sensors ​(HC-SR04):** Distance is calculated using ''​duration ​58''​. To calibrate them for real-time useI reduced the timeout from the default 1,​000,​000µs to just ''​15000µs''​. This limits the max read distance to ~2.5 meters, which is perfectly calibrated for indoor use and prevents the code from freezing when no echo is received.
-    UBRR0H ​(unsigned char)(ubrr >> 8); +
-    UBRR0L ​(unsigned char)ubrr; +
-    ​UCSR0B = (1 << RXEN0| (1 << TXEN0) | (1 << RXCIE0); +
-    ​UCSR0C = (1 << USBS0) | (3 << UCSZ00)// 8-bit, 2 stop bits +
-+
-</code>+
  
-<code c> +==== Optimizations and Bug Fixes ==== 
-// main.c - ISR +How, why, and where I optimized the code: 
-volatile char comanda_bt = 0;+  * **Alternating Sensor Reads:** Initially, reading both ultrasonic sensors blocked the CPU for up to 40ms per loop. I optimized this by reading only *one* sensor per frame (front, then back). This cut the blocking time in half, making the steering perfectly responsive. 
 +  * **Removed Delays:** I eliminated all ''​delay()''​ calls from the main loop, replacing them with ''​millis()''​ state machines to keep the CPU free
 +  * **The Stuttering Bug (Critical Fix):** During development,​ the car had a major bug where the motor would stutter constantly. I originally used Timer for the steering PWM and changed its prescaler from ''/​64''​ to ''/​1''​ to get more torque. **Why it broke:** Timer 0 is used internally by the framework for ''​millis()''​. Changing the prescaler made ''​millis()''​ run 64x faster than normal. This caused my 800ms safety failsafe to trigger every 12.5 real milliseconds,​ violently turning the motor on and off. **How I fixed it:** I removed the Timer 0 manipulation entirely, used simple ''​digitalWrite()''​ for steering (giving full power), and the stuttering disappeared instantly.
  
-ISR(USART_RX_vect) { +==== Novelty ==== 
-    char c UDR0; +The main element of novelty is the **Autonomous Emergency Braking (AEB)** layered on top of manual RC control. Unlike a normal RC car that crashes if you make a mistakethis car intelligently intercepts your Bluetooth commands. If you command it to drive forward into a wallthe software debounces the sensor readings and overrides your commandapplying a neutral brake to stop the car automatically. It implements a "​directional block":​ it stops you from hitting the wall in frontbut still allows you to reverse safely.
-    if (c !'​\r'​ && c !'​\n'​) comanda_bt ​c; +
-+
-</​code>​ +
-Commands: ''​F''​ Forward''​B''​ Backward''​L''​ Left''​R''​ Right, ''​S''​ Stop, ''​H''​ Horn''​1''/''​2''/''​3''​ Speed mode.+
  
-==== Lab 2 - Timers: Ultrasonic Distance ​==== +===== Custom Android Application ===== 
-**Timer 1** measures ​the HC-SR04 echo pulseAt 16MHz prescaler 8one tick = 0.5µs → ''​distance_cm = ticks / 116''​+To control ​the rover, I developed a custom Android application from scratchInstead of relying on generic Bluetooth terminal appsthis dedicated app provides a custom user interface tailored for drivingIt features: 
- +  * A responsive joystick and button layout for steering and acceleration
-<code c> +  ​* 4 selectable speed gears (including a Turbo mode). 
-// ultrasonic.c +  ​* Real-time telemetrythe app receives data back from the car (like sensor distancesand provides haptic feedback ​(vibrationwhen the Autonomous Emergency Braking ​(AEBsystem is triggered.
-uint16_t get_distance() { +
-    PORTD &= ~(1 << PD2); _delay_us(2);​ +
-    PORTD |=  (1 << PD2); _delay_us(10);​ +
-    PORTD &= ~(1 << PD2); +
- +
-    uint32_t counter = 0; +
-    while (!(PIND & (1 << PD4))) { +
-        if (++counter > 100000) return 0; +
-    } +
- +
-    TCNT1 = 0; +
-    TCCR1B = (1 << CS11); +
-    while (PIND & (1 << PD4)) { +
-        if (TCNT1 > 40000) break; +
-    } +
-    TCCR1B = 0; +
-    return TCNT1 / 116; +
-+
-</​code>​ +
- +
-==== Lab 3 - PWM: Steering Control ==== +
-**Timer 0** in Fast PWM mode on OC0A (PD6). ''​OCR0A''​ sets duty cycle (0-255). ''​PB0''/''​PB1''​ select direction+
- +
-<code c> +
-// motor.c +
-void motor_steering_init() { +
-    DDRD |= (1 << PD6); +
-    DDRB |= (1 << PB0) | (1 << PB1); +
-    TCCR0A = (1 << COM0A1) | (1 << WGM01) | (1 << WGM00); +
-    TCCR0B = (1 << CS01) | (1 << CS00); // prescaler 64 +
-    OCR0A = 0; +
-+
- +
-void motor_steer(int direction, uint8_t power) { +
-    OCR0A = power; +
-    if (direction == 1)       { PORTB |=  (1<<​PB0);​ PORTB &= ~(1<<​PB1);​ } +
-    else if (direction == -1) { PORTB &= ~(1<<​PB0);​ PORTB |=  (1<<​PB1);​ } +
-    else                      { PORTB &= ~(1<<​PB0);​ PORTB &= ~(1<<​PB1);​ } +
-+
-</​code>​ +
- +
-==== Lab 4 - ADCAutomatic Headlights ==== +
-Photoresistor on **PC0 (ADC0)** in voltage divider. When dark → LEDs turn on automatically. +
- +
-<code c> +
-// adc.c +
-void adc_init() +
-    ADCSRA = (1 << ADEN| (7 << ADPS0); // prescaler 128 +
-    ADMUX  = (1 << REFS0); ​              // AVcc reference +
-+
- +
-uint16_t myAnalogRead(uint8_t channel) { +
-    ADMUX &= 0b11100000;​ +
-    ADMUX |= (channel & 0b00000111);​ +
-    ADCSRA |= (1 << ADSC); +
-    while (ADCSRA & (1 << ADSC)); +
-    return ADC; +
-+
-</​code>​ +
- +
-==== Lab 6 - I2C: LCD Telemetry ==== +
-🔄 **In progress.** TWI hardware used at 100kHz. Registers: ''​TWBR'',​ ''​TWSR'',​ ''​TWCR'',​ ''​TWDR''​. LCD will show speed mode and distance.+
  
  
pm/prj2026/vlad.radulescu2901/viorel_cosmin.cucu.1778958055.txt.gz · Last modified: 2026/05/16 22:00 by viorel_cosmin.cucu
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