Skip to content

Commit

Permalink
Dimos (#1130)
Browse files Browse the repository at this point in the history
### Summary
This should be the PR that gets a drivable dashboard on the car.

### Changelist
- Logging
- Improved Types/DS for GPIO

### Testing Done
- [x] runs on local dev
- [x] runs on dev board
- [x] runs on aux dim board

### Resolved Issues
- Solves logging in
[SW-87](https://ubcformulaelectric.atlassian.net/jira/software/projects/SW/boards/20?selectedIssue=SW-87)
- Solves GPIO Navigation in
[SW-72](https://ubcformulaelectric.atlassian.net/jira/software/projects/SW/boards/20?selectedIssue=SW-72)

### Checklist
*Please change `[ ]` to `[x]` when you are ready.*
- [x] I have read and followed the code conventions detailed in
[README.md](../README.md) (*This will save time for both you and the
reviewer!*).
- [x] If this pull request is longer then **500** lines, I have provided
*explicit* justification in the summary above explaining why I *cannot*
break this up into multiple pull requests (*Small PR's are faster and
less painful for everyone involved!*).


[SW-87]:
https://ubcformulaelectric.atlassian.net/browse/SW-87?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

[SW-72]:
https://ubcformulaelectric.atlassian.net/browse/SW-72?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

---------

Co-authored-by: Gus Tahara-Edmonds <[email protected]>
Co-authored-by: peterjinweigu <[email protected]>
Co-authored-by: Edwin <[email protected]>
  • Loading branch information
4 people authored Jun 22, 2024
1 parent 09e4444 commit 1118ff5
Show file tree
Hide file tree
Showing 103 changed files with 3,198 additions and 1,565 deletions.
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ build_fw_deploy_wsl
build_fw_test
build_fw_test_wsl

build_dimos_deploy
build_dimos_dev
build_dimos_test
build_dimos_docker
build_dimos_deploy*
build_dimos_dev*
build_dimos_test*
build_dimos_docker*

environment/bin
CMakeUserPresets.json
Expand Down
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
message("💡 Starting UBC Formula Electric Generate")

cmake_minimum_required(VERSION 3.24)
cmake_minimum_required(VERSION 3.22.3)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 20)
Expand All @@ -12,7 +12,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(REPO_ROOT_DIR ${CMAKE_SOURCE_DIR})
set(SCRIPTS_DIR "${CMAKE_SOURCE_DIR}/scripts")
set(ENV_BIN_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/environment/bin)
cmake_policy(SET CMP0135 NEW)
# cmake_policy(SET CMP0135 NEW)
Set(FETCHCONTENT_QUIET FALSE)
include(scripts/code_generation/jsoncan/jsoncan.cmake)
include(scripts/code_generation/commit_info_gen/commit_info.cmake)
Expand All @@ -36,6 +36,7 @@ include(${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake)
message("✅ Download CPM.cmake")

# ======== Host system specific settings ========
message("🖥️ Host System: ${CMAKE_SYSTEM_NAME}")
IF (WIN32)
message("🪟 Building for Windows")
set(BINARY_SUFFIX ".exe")
Expand Down
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pandas = "*"
pytest = "*"
python-dateutil = "*"
requests = "*"
GitPython = "*"
influxdb-client = "*"
flask = "*"

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

A repository for all software and firmware from UBC Formula Electric.

[![Binary and DBC Generation](https://github.com/UBCFormulaElectric/Consolidated-Firmware/actions/workflows/master_cd.yml/badge.svg)](https://github.com/UBCFormulaElectric/Consolidated-Firmware/actions/workflows/master_cd.yml)

## Table of Contents

- [Consolidated-Firmware](#consolidated-firmware)
Expand Down
14 changes: 12 additions & 2 deletions can_bus/quadruna/dimos/dimos_rx.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
{
"messages": [
]
"messages": [
"FSM_Wheels",
"FSM_Apps",
"FSM_Brake",
"BMS_VoltageAndChargeStats",
"BMS_TractiveSystem",
"BMS_CellTemperatures",
"VC_PowerLimit",
"VC_GlobalShdnNodeStatus",
"INVL_Temperatures1",
"INVR_Temperatures3"
]
}
7 changes: 3 additions & 4 deletions firmware/quadruna/VC/src/app/states/app_driveState.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ void transmitTorqueRequests(float apps_pedal_percentage)

static void driveStateRunOnEntry(void)
{

// Enable buzzer on transition to drive, and start 2s timer.
app_timer_init(&buzzer_timer, BUZZER_ON_DURATION_MS);
app_timer_restart(&buzzer_timer);
Expand Down Expand Up @@ -118,13 +117,13 @@ static void driveStateRunOnTick100Hz(void)
bool turn_tv_led = torque_vectoring_switch_is_on;

// Regen + TV LEDs and update warnings
if(turn_regen_led)
if (turn_regen_led)
{
app_canTx_VC_RegenEnabled_set(true);
app_canTx_VC_Warning_RegenNotAvailable_set(false);
}
if(!regen_switch_is_on)

if (!regen_switch_is_on)
{
app_canTx_VC_RegenEnabled_set(false);
app_canTx_VC_Warning_RegenNotAvailable_set(true);
Expand Down
2 changes: 1 addition & 1 deletion scripts/canup
Submodule canup updated 2 files
+5 −5 boards.py
+10 −19 update.py
3 changes: 3 additions & 0 deletions setup.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
E:\environment-setup-armv8a-poky-linux.bat

& "E:\sysroots\x86_64-w64-mingw32\usr\bin\cmake.exe" -G Ninja -DPLATFORM=dimos -DHANDLE_DEPS=ON -DFIX_FORMATTING=OFF -DTARGET=dev -DUSE_COMMIT_INFO=MINIMAL -S . -B ./build_dimos_deploy
3 changes: 3 additions & 0 deletions software/dimos/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ compile_commands.json

**/*.txt
!**/*/CMakeLists.txt

flash.ps1
flash.sh
11 changes: 5 additions & 6 deletions software/dimos/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
cmake_minimum_required(VERSION 3.24)
cmake_minimum_required(VERSION 3.22.3)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if("${TARGET}" STREQUAL "deploy")
set(EXECUTABLE_NAME dimos)
if ("${TARGET}" STREQUAL "deploy")
elseif ("${TARGET}" STREQUAL "dev")
set(EXECUTABLE_NAME dimos_dev)
else()
else ()
message(FATAL_ERROR "❌ Unknown target ${TARGET}")
endif()
endif ()
set(EXECUTABLE_NAME dimos)

add_subdirectory(src)
10 changes: 8 additions & 2 deletions software/dimos/Dockerfile_build
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ RUN pip3 install -r requirements.txt --break-system-packages
# __deps__
RUN apt-get -q -y install \
qmake6 \
git \
cmake \
ninja \
ninja-build \
gpiod \
libgpiod-dev \
qt6-base-private-dev \
Expand All @@ -62,10 +63,15 @@ RUN apt-get -q -y install \
qml6-module-qtquick-templates \
libqt6opengl6-dev \
libqt6svg6 \
libqt6svg6-dev
libqt6svg6-dev \
libqt6core5compat6 \
libqt6core5compat6-dev

# cleanup
RUN apt-get clean && apt-get autoremove && \
rm -rf /var/lib/apt/lists/*

# make git work
RUN git config --global --add safe.directory '*'

WORKDIR /app
10 changes: 7 additions & 3 deletions software/dimos/Dockerfile_container
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ ARG IMAGE_ARCH=arm64
ARG GPU=-vivante

FROM --platform=linux/${IMAGE_ARCH} torizon/qt6-wayland${GPU}:${BASE_VERSION}

ARG IMAGE_ARCH
ARG GPU

Expand Down Expand Up @@ -35,6 +34,7 @@ RUN apt-get -q -y update && \
RUN apt-get -q -y update && \
apt-get -q -y install \
file \
gpiod \
curl \
qt6-base-private-dev \
qt6-base-dev \
Expand All @@ -49,11 +49,15 @@ RUN apt-get -q -y update && \
qml6-module-qtquick-window \
qml6-module-qtquick-controls \
qml6-module-qtquick-layouts \
qml6-module-qtwayland-compositor \
qml6-module-qtquick-templates \
qml6-module-qtwayland-compositor \
libqt6opengl6 \
libqt6svg6 \
libqt6svg6-dev \
gpiod \
libqt6core5compat6 \
libqt6core5compat6-dev \
qml6-module-qt5compat-graphicaleffects \
qml6-module-qtquick-shapes \
&& \
apt-get clean && apt-get autoremove && \
rm -rf /var/lib/apt/lists/*
Expand Down
69 changes: 28 additions & 41 deletions software/dimos/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,67 +1,54 @@
# FROM THE PARENT SCOPE, WE INHERIT
# - EXECUTABLE_NAME
include(find_qt_libs.cmake) # we need to do this super early because this provides Qt CMake functions
set(CMAKE_AUTOUIC OFF)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
# define sources
set(UI_SOURCES main.cpp assets/resources.qrc)
file(GLOB IO_INC "${CMAKE_CURRENT_SOURCE_DIR}/io/*.h")
file(GLOB SHARED_FILES "${CMAKE_CURRENT_SOURCE_DIR}/shared/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/shared/*.cpp")
file(GLOB TASKS_FILES "${CMAKE_CURRENT_SOURCE_DIR}/tasks/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/tasks/*.cpp")
if("${TARGET}" STREQUAL "deploy")
set(UI_SOURCES main.cpp setup.cpp assets/resources.qrc)
file(GLOB SHARED_FILES "${CMAKE_CURRENT_SOURCE_DIR}/shared/*.cpp")
file(GLOB TASKS_FILES "${CMAKE_CURRENT_SOURCE_DIR}/tasks/*.cpp")
if ("${TARGET}" STREQUAL "deploy")
file(GLOB_RECURSE IO_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/io/*.cpp")
elseif ("${TARGET}" STREQUAL "dev")
file(GLOB_RECURSE IO_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/dev_io/*.cpp")
endif()
set(SOURCES ${UI_SOURCES} ${IO_SOURCES} ${IO_INC} ${SHARED_FILES} ${TASKS_FILES})
endif ()
# Append to IO_SOURCES
list(APPEND IO_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/io/KeyTranslator.cpp")
set(SOURCES ${UI_SOURCES} ${IO_SOURCES} ${SHARED_FILES} ${TASKS_FILES})

# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
qt_add_executable(${EXECUTABLE_NAME} ${SOURCES})
# include directories
target_include_directories(${EXECUTABLE_NAME} PRIVATE shared io assets tasks)
target_include_directories(${EXECUTABLE_NAME} PRIVATE shared io dev_io assets tasks .)
# link libraries
include(find_libs.cmake)
target_link_libraries(${EXECUTABLE_NAME} PRIVATE ${REQUIRED_LIBRARIES})
# to tell which configuration it is from macros
target_compile_definitions(${EXECUTABLE_NAME} PUBLIC "USING_${EXECUTABLE_NAME}") # todo change to using_target_dimos
target_compile_definitions(${EXECUTABLE_NAME} PUBLIC "USING_TARGET_${TARGET}")
target_compile_definitions(${EXECUTABLE_NAME} PRIVATE -DQT_DEBUG -DQT_MESSAGELOGCONTEXT) # W mans https://stackoverflow.com/a/43549795/6833423
if(${TARGET} STREQUAL dev)
target_compile_definitions(${EXECUTABLE_NAME} PRIVATE QT_QML_DEBUG)
endif()
# QML
set_target_properties(${EXECUTABLE_NAME} PROPERTIES AUTOMOC ON AUTORCC ON)
qt_add_qml_module(${EXECUTABLE_NAME}
URI "MainWindow"
VERSION 1.0
QML_FILES ui/MainWindow.qml
URI "DimosMain"
VERSION 1.0
QML_FILES ui/MainWindow.qml
)
#qt_query_qml_module(
# ${EXECUTABLE_NAME}
# URI uri_var
# VERSION version_var
# PLUGIN_TARGET plugin_target_var
# TARGET_PATH target_path_var
# MODULE_RESOURCE_PATH module_resource_path_var
# QMLDIR qmldir_var
# TYPEINFO typeinfo_var
# QML_FILES qml_files_var
# QML_FILES_DEPLOY_PATHS qml_files_deploy_paths_var
# QML_FILES_PREFIX_OVERRIDES qml_files_prefix_overrides_var
# RESOURCES resources_var
# RESOURCES_DEPLOY_PATHS resources_deploy_paths_var
# RESOURCES_PREFIX_OVERRIDES resources_prefix_overrides_var
#)
#
#message(
#"URI: ${uri_var}
#TARGET_PATH: ${target_path_var}
#MODULE_RESOURCE_PATH: ${module_resource_path_var}
#QMLDIR: ${qmldir_var}
#TYPEINFO: ${typeinfo_var}
#QML_FILES: ${qml_files_var}
#QML_FILES_DEPLOY_PATHS: ${qml_files_deploy_paths_var}"
#)
# add qml modules
add_subdirectory(ui)
target_link_libraries(${EXECUTABLE_NAME} PRIVATE DimosConstantsplugin Switcherplugin Pagesplugin Squircleplugin)
target_compile_definitions(DimosConstants PUBLIC "USING_${EXECUTABLE_NAME}") # L QML compiler
target_link_libraries(${EXECUTABLE_NAME} PUBLIC
DimosConstantsplugin
Switcherplugin
Pagesplugin
Componentsplugin
DimSwitchesplugin
CanQMLplugin
)
target_compile_definitions(DimosConstants PUBLIC "USING_TARGET_${TARGET}") # L QML compiler
target_link_libraries(CanQML PUBLIC dimos_can)

# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
Expand Down
17 changes: 8 additions & 9 deletions software/dimos/src/dev_io/can.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
#include "can.h"
#include <iostream>
#include <thread>
#include <chrono>
#include <qlogging.h>

using std::cout, std::endl;
#include "can.h"
#include "dev_io_utils.h"

Result<std::monostate, CanConnectionError> Can_Init()
{
cout << "Can Initialized" << endl;
qInfo("Can Initialized");
return std::monostate{};
}

Result<JsonCanMsg, CanReadError> Can_Read()
{
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
cout << "Can Read Requested\n";
if (const WaitDelegateResult res = wait_delegate_thread(); res == WaitDelegateResult::INTERRUPTED)
return CanReadError::Timeout;
// qInfo("Can Read Requested");
return JsonCanMsg{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
}

Result<std::monostate, CanWriteError> Can_Write(const JsonCanMsg *msg)
{
cout << "Can with id " << msg->std_id << " Written\n";
// qInfo("Can with id %d Written", msg->std_id);
return std::monostate{};
}
20 changes: 20 additions & 0 deletions software/dimos/src/dev_io/dev_io_utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "dev_io_utils.h"

#include <QThread>
#include <thread>

static constexpr int TIMEOUT_TIME_MSEC = 3000;
static constexpr int RESPONSE_TIME = 30;
static constexpr int CYCLES = TIMEOUT_TIME_MSEC / RESPONSE_TIME; // CYCLES * RESPONSE_TIME = TIMEOUT_TIME_MSEC

WaitDelegateResult wait_delegate_thread()
{
for (int i = 0; i < CYCLES; i++)
{
std::this_thread::sleep_for(std::chrono::milliseconds(RESPONSE_TIME));
if (QThread::currentThread()->isInterruptionRequested())
return WaitDelegateResult::INTERRUPTED;
}

return WaitDelegateResult::TIMEOUT;
}
9 changes: 9 additions & 0 deletions software/dimos/src/dev_io/dev_io_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

enum class WaitDelegateResult
{
TIMEOUT,
INTERRUPTED
};

[[nodiscard]] WaitDelegateResult wait_delegate_thread();
Loading

0 comments on commit 1118ff5

Please sign in to comment.