Skip to content

badgerloop-software/sc2-driver-io

Repository files navigation

Solar Car 2 Driver IO Program

Solar Car Dashboard

Frontend Options

Qt GUI (Legacy - for desktop development)

  • Full graphical interface with QML components
  • Higher resource usage (~50-100MB RAM, 5-15% CPU)
  • Requires desktop environment

Textual Terminal GUI (New - for Raspberry Pi deployment) ⭐

  • Lightweight terminal-based interface
  • Minimal resource usage (~5-15MB RAM, 0.5-2% CPU)
  • 70-90% performance improvement over Qt
  • Located in textual_frontend/ directory
  • See textual_frontend/README.md for details

Libraries/Frameworks

  • Qt - Development framework (legacy GUI)
  • Textual - Terminal GUI framework (new lightweight option)
  • RapidJSON - JSON parsing library

Cloning the Data Format Repository and Initializing the Submodule

  1. If you don't already have an SSH key, generate a new SSH key (only the steps under "Generating a new SSH key" are required) and add it to your GitHub account.
  2. Once you have an SSH key, clone this repository to your computer. Make sure to clone it using SSH (when you go to copy the clone link, there will be an SSH option above the link).
  3. Next, cd into the sc1-driver-io repository and run git submodule update --init.

Running with CMake

CMake is a more popular project make system, it allows you to edit the project with your ide of choice and enables features like autocomplete while not bounded to using qtcreator.

  1. If you are using windows, install Ubuntu via WSL, you can use any other distribution if you're experienced with linux.
  2. Ensure you have cmake and build-essentials installed you can do so by sudo apt install build-essential cmake
  3. Install qt packages with sudo apt install qt5-doc qtbase5-examples qtbase5-doc-html qtdeclarative5-dev qml-module-qtquick-controls2
  4. cdinto your project directory and mkdir build to create a new build folder then cd build
  5. Run cmake .. to generate make file for the project, then run make to compile the project.
  6. To execute the program run ./solar-car-dashboard.

Contributing to the Dashboard

  1. Again, make sure you have Qt installed on your computer.
  2. Clone the repository to your computer (see steps 0-1 of "Cloning the Data Format Repository and Initializing the Submodule" for instructions on cloning a repo using SSH).
  3. If you have not already, clone the sc1-data-format repository and initialize the submodule (see instructions above).
  4. Open the repository in Qt Creator and, if necessary, configure the project using the appropriate kit for your environment.
  5. Run git submodule update --remote to update necessary submodules. You should also do this any time the submodule might have changed (i.e. whenever the data format has been modified).
    1. To avoid pushing changes that use obsolete data, update the submodule before you git push your changes. If there are changes to the data format, run the dashboard to make sure your code still works.
  6. To run the dashboard on your computer, simply press the green arrow in the bottom-left corner of the Qt Creator window. To run the project on a Raspberry Pi, see "Compiling and Running the Project on a Rapberry Pi" below.
  7. Once you have finished making your necessary changes to your code, switch to a new branch that has a good name for the feature or names the Jira issue (e.g. SW-23/skeleton).
  8. Commit related changes to that branch and push to this repository. (Do this often so that it is easy to finely revert to a previous state!)
    1. When committing and pushing changes, do not add your solar-car-dashboard.pro.user file to the version control, as this is specific to your computer.
  9. Once you are happy with the state of your code, open a pull request and request someone to conduct a code review. It may be kicked back with some suggestions or edits, but when it is accepted, it will be merged with main. Congrats! Now it's just time to rinse and repeat.

Running on Raspberry Pi (Updated Architecture) -> WORK IN PROGRESS

Modern Hybrid Approach:

The project now uses a hybrid C++/Python architecture optimized for the Pi:

  1. C++ Backend (./build/sc2-driver-io): Headless telemetry processor

    • Runs as root for GPS/hardware access
    • Real-time CAN processing and data validation
    • Low-latency, high-performance core
  2. Python Coordinator (./main.py): System orchestrator

    • Multi-threaded coordination (CAN, GPS, CSV logging)
    • External module integration
    • Runs as sunpi user
  3. Textual Terminal GUI (./textual_frontend/): Optional lightweight dashboard

    • 70-90% less resource usage than Qt
    • Terminal-based interface
    • Integrates with existing Weston setup

Integration with Existing Pi Setup:

Your Pi runs Raspberry Pi OS Lite with Weston compositor. The new architecture provides three deployment options:

  1. Headless Mode (Recommended): Disables Weston, runs terminal dashboard on tty2

    • Maximum performance and resource savings
    • Access dashboard: Alt+F2, console: Alt+F1
  2. Hybrid Mode: Keeps Weston running + adds terminal dashboard on tty2

    • Maintains existing functionality
    • Switch between Weston (Alt+F1) and dashboard (Alt+F2)
  3. Weston Integration: Launches SC2 components from within Weston autolaunch

    • Integrates with existing /home/sunpi/.config/weston.ini setup
    • Maintains current boot flow

Setup:

# Run the integrated setup script
cd textual_frontend
chmod +x setup_autolaunch.sh
sudo ./setup_autolaunch.sh

The script will prompt you to choose your preferred integration mode.

Compiling and Running the Project on a Raspberry Pi (Legacy Qt Method)

  1. If running the project on the driver IO board, skip this step, as the necessary dependencies have already been installed on it. Otherwise, if you have not already, install the dependencies on the Raspberry Pi:
    sudo apt install build-essential cmake
    sudo apt install qt5-doc qtbase5-examples qtbase5-doc-html qtdeclarative5-dev qml-module-qtquick-controls2
    
  2. Copy the project to the Raspberry Pi.
  3. make a build directory with in the project, make sure you are in the directory
  4. Make and run the project on the Raspberry Pi by running the following commands:
    cmake ..
    make
    ./solar-car-dashboard
    

Project Structure

This section provides an overview of the key folders and their purposes in the Solar Car 1 Driver IO project.

Root Directory

  • CMakeLists.txt: Build configuration file for CMake, used to compile the C++ backend.
  • main.cpp: C++ entry point for headless telemetry processor (modernized, no Qt dependencies).
  • main.py: Python entry point for system coordinator (multi-threaded orchestration).
  • Config.cpp/h: Configuration management (converted from Qt to standard C++).
  • config.json: JSON file containing application configuration settings.

textual_frontend/

NEW: Lightweight terminal-based GUI replacement for Qt dashboard.

  • textual_dashboard.py: Main terminal dashboard application using Textual library.
  • dashboard_launcher.py: Bridge between C++ backend and dashboard interface.
  • setup_autolaunch.sh: Raspberry Pi integration script (works with existing Weston setup).
  • README.md: Complete documentation for terminal GUI setup and usage.

3rdparty/

Contains third-party libraries used in the project.

  • rapidjson/: Header-only JSON parsing library for C++.
  • serial/: Library for serial communication (serialib), used for interfacing with serial devices like GPS.

backend/

Handles backend data processing and communication.

  • backendProcesses.cpp/h: Manages backend processes, including telemetry data handling via TCP, UDP, and SQL connections. Runs in a separate thread to process incoming data.
  • dataFetcher.cpp/h: Fetches data from network sources (TCP server), integrates GPS data, and manages data buffers.
  • file_sync/: Contains scripts for synchronizing files, likely for uploading telemetry data.
  • telemetrylib/: Library for telemetry operations, including TCP, UDP, SQL, and DTI (Data Transmission Interface) handling.

DataProcessor/

Responsible for processing and unpacking telemetry data.

  • dataUnpacker.cpp/h: Core class that unpacks binary data into readable properties exposed to the QML UI, such as fan speed, timestamps, LED statuses, and shutdown circuit states.
  • CMakeLists.txt: Build configuration for the DataProcessor module.

ethernet_sim/

Simulation tools for testing ethernet communication.

  • main.py: Python script that simulates telemetry data transmission over ethernet, using the data format from sc1-data-format and GPS datasets.
  • gps_dataset/: Sample GPS data files (CSV, GPX, JSON) used in simulations.

gps/

GPS functionality module.

  • gps.cpp/h: Class for interfacing with GPS devices via serial communication, parsing NMEA data to extract latitude, longitude, and altitude.

sc1-data-format/

Git submodule containing the data format definitions for telemetry packets. This folder is empty until the submodule is initialized (see cloning instructions above).

UI/

User interface components built with Qt QML.

  • Items/: QML files defining UI components like Dashboard, Speed, Batteries, Blinkers, etc.
  • Images/: Image assets (PNG, SVG) for the dashboard, such as needles, icons, and backgrounds.
  • fonts/: Font files (Work Sans) used in the UI, with licensing information.

About

Solar Car 2 Driver IO Program - Firmware, Networking, and Dashboard

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 10