This shows you the differences between two versions of the page.
|
pm:prj2026:jan.vaduva:silvia.berescu [2026/05/23 16:15] silvia.berescu [Pin Mapping — Arduino Labels vs ATmega328P Physical Pins] |
pm:prj2026:jan.vaduva:silvia.berescu [2026/05/23 22:38] (current) silvia.berescu [Hardware Progress] |
||
|---|---|---|---|
| Line 88: | Line 88: | ||
| === Motor Control === | === Motor Control === | ||
| - | + | ||
| The L298N receives direction signals on IN1–IN4 from ATmega pins D8–D11: | The L298N receives direction signals on IN1–IN4 from ATmega pins D8–D11: | ||
| - | ^ IN1 ^ IN2 ^ Motor Left behavior ^ | + | |
| - | | HIGH | LOW | Forward | | + | ^ IN1 ^ IN2 ^ Motor Left behavior ^ |
| - | | LOW | HIGH | Reverse | | + | | LOW | HIGH | Forward | |
| + | | HIGH | LOW | Reverse | | ||
| | LOW | LOW | Stop | | | LOW | LOW | Stop | | ||
| - | + | ||
| The same logic applies to IN3/IN4 for Motor Right. | The same logic applies to IN3/IN4 for Motor Right. | ||
| - | + | ||
| - | Speed is controlled via PWM on both **ENA** (D6/OC0A) and **ENB** (D5/OC0B) using Timer0 Fast PWM mode.This allows independent speed adjustment for each motor to compensate for mechanical differences. | + | Speed is controlled via PWM on both **ENA** (D6/OC0A) and **ENB** |
| + | (D5/OC0B) using Timer0 Fast PWM mode. | ||
| === HC-SR04 Front Sensor === | === HC-SR04 Front Sensor === | ||
| Line 130: | Line 132: | ||
| {{ :pm:prj2026:jan.vaduva:hardware_progress.jpeg?600 |Assembled Robot}} | {{ :pm:prj2026:jan.vaduva:hardware_progress.jpeg?600 |Assembled Robot}} | ||
| + | |||
| The image shows the fully wired robot with all components mounted and powered via the 2x18650 battery pack (7.4V). | The image shows the fully wired robot with all components mounted and powered via the 2x18650 battery pack (7.4V). | ||
| Line 150: | Line 153: | ||
| ===== Software Design ===== | ===== Software Design ===== | ||
| - | ==== Lab Concepts Used ==== | + | ==== Development Environment ==== |
| - | ^ Lab concept ^ Usage in project ^ | + | * **Visual Studio Code + PlatformIO Core 6.1.19** |
| - | | **GPIO** | TRIG/ECHO sensor pins, motor direction pins IN1–IN4 | | + | * **Framework:** Arduino (avr-minicore) used only as build system, all peripheral code written directly on AVR registers |
| - | | **PWM** | Timer0 Fast PWM on OC0A (D6) and OC0B (D5) — both motors | | + | * **Compiler:** avr-gcc (toolchain-atmelavr 7.3.0) |
| - | | **I2C** | TWI communication with LCD 16x2 via PCF8574 on A4/A5 | | + | * **Upload:** custom avrdude with ''xplainedmini'' programmer over USB mEDBG |
| - | | **UART** | Debug data transmission at 9600 baud via TX (D1) | | + | |
| - | | **Interrupts** | INT1 on D3 (PD3) for precise front ECHO pulse measurement | | + | ==== Project Structure ==== |
| + | |||
| + | ^ File ^ Role ^ | ||
| + | | ''main.cpp'' | Motor functions, navigation algorithm, setup/loop | | ||
| + | | ''sensors.cpp/.h'' | HC-SR04 front (INT1 interrupt) and left (polling) | | ||
| + | | ''lcd.cpp/.h'' | TWI/I2C driver + HD44780 LCD functions | | ||
| + | |||
| + | ==== Lab Concepts Used and Justification ==== | ||
| + | |||
| + | ^ Lab concept ^ Justification ^ | ||
| + | | **GPIO** | TRIG/ECHO sensor pins and motor direction pins controlled directly via DDRx/PORTx registers | | ||
| + | | **PWM** | Timer0 Fast PWM on OC0A and OC0B for independent speed control of each motor; allows straight-line correction by setting different OCR values | | ||
| + | | **Interrupts** | INT1 on PD3 for front HC-SR04 ECHO, interrupt-driven measurement is more accurate than polling because the MCU reacts instantly to signal edges without busy-waiting | | ||
| + | | **I2C** | LCD 16x2 via PCF8574 on PC4/PC5; TWI implemented on registers following the same pattern as the lab | | ||
| + | | **Timers** | Timer0 for PWM generation; Timer1 as free-running counter inside INT1 ISR to timestamp ECHO pulse edges and compute distance | | ||
| ==== Navigation Algorithm ==== | ==== Navigation Algorithm ==== | ||
| - | The robot uses the **Left-Hand Wall Follower** algorithm: | + | The robot implements the Left-Hand Wall Follower algorithm. The maze is constructed so the robot always has a left wall present. The decision logic runs continuously in the main loop: |
| + | |||
| + | - If **left is free** (distance > 20cm): turn left 90° then move forward — this is the core left-hand rule, taking every available left turn | ||
| + | - Else if **front is free** (distance > 20cm): move forward, follow the left wall | ||
| + | - Else: turn right 90°, blocked on both sides, only option is right | ||
| + | |||
| + | This guarantees finding the exit in any simply connected maze. | ||
| + | |||
| + | ==== Sensor Implementation ==== | ||
| + | |||
| + | The **front sensor** uses INT1 hardware interrupt for precise ECHO pulse measurement. Timer1 is started on the rising edge of ECHO and stopped on the falling edge. Distance is computed from the elapsed ticks. This approach is more accurate than polling and frees the CPU between measurements. | ||
| + | |||
| + | The **left sensor** uses GPIO polling. PB4 (D12) was chosen instead of D5 because D5 (OC0B) was needed for ENB PWM. Polling is acceptable here since the left wall changes slowly, precision requirements are lower than for the front sensor. | ||
| + | |||
| + | ==== Motor Control ==== | ||
| + | |||
| + | Timer0 Fast PWM at 7.8kHz drives both motors independently via OC0A (left) and OC0B (right). | ||
| + | |||
| + | **Important finding:** The motor direction logic is inverted, determined experimentally during hardware testing. | ||
| + | |||
| + | Motor B runs at a slightly higher PWM value than Motor A to compensate for mechanical differences between the two motors, ensuring straight-line driving. | ||
| + | |||
| + | ==== Calibration ==== | ||
| + | |||
| + | * **Turn delay:** calibrated by placing the robot on a flat surface, calling the turn function, and measuring the resulting angle physically. Adjusted until 90° was achieved consistently. | ||
| + | * **Motor speeds:** OCR0A=180-200, OCR0B=190-200 — calibrated by observing straight-line driving. Motor B speed increased until drift was eliminated. | ||
| + | * **Distance thresholds:** DIST_FRONT_STOP and DIST_LEFT_FAR both set to 20cm — chosen to match the corridor width of the test maze and provide sufficient stopping margin. | ||
| + | |||
| + | |||
| + | ==== Validation ==== | ||
| + | |||
| + | Each component was validated independently before integration: motors tested individually for direction and speed, each sensor tested by placing hand at known distances and verifying LCD readings, turn angles verified physically on grid paper. Full algorithm validated in test maze sections observing behavior for each decision case. | ||
| - | - If left is **free** (distance > 20cm): turn left 90° + move forward | + | ==== Demo Video ==== |
| - | - Else if front is **free** (distance > 20cm): move forward | + | |
| - | - Else: turn right 90° | + | |
| + | //To be added after final maze test// | ||
| ===== Results ===== | ===== Results ===== | ||
| Line 183: | Line 230: | ||
| | Week 2 | Chassis assembly, mounting motors and wheels | Done | | | Week 2 | Chassis assembly, mounting motors and wheels | Done | | ||
| | Week 3 | L298N wiring + electrical schematic | Done | | | Week 3 | L298N wiring + electrical schematic | Done | | ||
| - | | Week 4 | HC-SR04 integration + distance measurement test | Planned | | + | | Week 4 | HC-SR04 integration + LCD I2C integration | Done | |
| - | | Week 5 | LCD I2C integration + data display | Planned | | + | | Week 5 | Navigation algorithm implementation + maze test | Planned | |
| - | | Week 6 | Navigation algorithm implementation + maze test | Planned | | + | | Week 6 | Code optimization, final demo | Planned | |
| - | | Week 7 | 90° turn calibration, code optimization, final demo | Planned | | + | |
| ===== Bibliography / Resources ===== | ===== Bibliography / Resources ===== | ||