Week 14: Interface and Application Programming

May 7, 2024

Project Document - ToGo Pathfinding Project

1. Introduction

“The ToGo Pathfinding Project utilizes a Raspberry Pi 4 and Raspberry Pi Camera 2 to detect ArUco markers and calculate the shortest path on a grid while lighting up the path on LED cells. The system controls LEDs via ESP32-C3 modules embedded within cubes that are marked with ArUco markers. The project incorporates a Flask web framework for inter-device communication and control via a user interface.”

Group Assigment Page

group assignment networking link 🚀

TogoV4

2. System Architecture

“ToGO employs a Raspberry Pi 4 as the main control unit. The Raspberry Pi processes real-time video feed from a connected camera module to detect ArUco markers. The detected marker information is processed through a Flask server running on the Raspberry Pi, which sends appropriate commands to ESP32-C3 modules for LED control. Each cube is equipped with ArUco markers on each face, allowing the system to determine the cube’s orientation.”

TogoV4

3. Main Modules and Functions

TogoV4

TogoV4

TogoV4

TogoV4

4. User Interface

“Users interact with the system through a web interface provided by Flask. The interface allows users to view camera feeds, take snapshots, adjust LED settings, and review system logs. Additionally, it provides capabilities to check and update the connectivity and settings of the ESP modules.”

Main Page

TogoV4

Camera Settings Function

TogoV4

Aruco Detect

TogoV4

Camera and Grid Settings

TogoV4

5. Testing and Results

“The project underwent extensive testing under various scenarios. Parameters such as ArUco marker detection accuracy, response time of LED control, and system stability were focused on. The tests demonstrated that our system operates with high accuracy and low latency effectively.”

Board Simulation

TogoV4

TogoV4

6. Programming Interface and Application Structure

The app.py file serves as the entry point to our application, orchestrating various functionalities through different modules. We utilize a modular architecture to enhance maintainability and reduce the complexity inherent in handling multiple components. Here’s how the program is structured and the roles of the various imported modules:

TogoV4 TogoV4

Example Code Snippet

Here is a snippet from app.py illustrating how these components interact:

from flask import Flask, render_template, jsonify, request
import threading
from picamera2 import Picamera2
import grid
from grid import save_image, detect_and_label_grids
from network_utils import check_esp_connections
from control_esp import send_command_to_esp

# Initialize the Flask app
app = Flask(__name__, static_folder='static', static_url_path='/static')

# Define a route to display the main page
@app.route('/')
def index():
    return render_template('index.html')

# Route for initiating camera connection
@app.route('/connect_camera', methods=['GET'])
def connect_camera():
    threading.Thread(target=setup_camera).start()
    return jsonify({'message': 'Camera connection is initiated.'})

# Main function to launch the Flask app
if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0')

7. Swift Simulation for Pathfinding

The SwiftUI simulation within the ToGo Pathfinding Project leverages SwiftUI to create a dynamic and interactive grid system where users can simulate pathfinding scenarios in real-time. Below are some key features of the Swift simulation:

Togo V4 Main View TogoV4

Path Calculation TogoV4

TogoV4

8. Raspberry Pi Pico W and Adafruit IO Dashboard Project

I integrated a Raspberry Pi Pico W with Adafruit IO to create a real-time dashboard. This project demonstrates to work with microcontrollers and cloud-based IoT platforms.

TogoV4

TogoV4

Source Files

Source Folder