Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/ctest-develop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: GTest Sanity Check

on:
push:
branches: [ "develop" ]
pull_request:
branches: [ "develop" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Cmake
run: |
cmake -B build -DBUILD_TESTING=ON
cmake --build build
ctest --test-dir build
cd build && ctest && cd ..

46 changes: 46 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Publish Multi-Target Release

on:
push:
tags:
- 'v*'
branches:
- main
- release


jobs:
release:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install ARM Toolchain for STM
run: sudo apt-get update && sudo apt-get install -y gcc-arm-none-eabi

# Build Linux version
- name: Build Linux target
run: |
cmake -B build_linux -DCMAKE_INSTALL_PREFIX=lib_linux -DBUILD_TESTING=OFF
cmake --build build_linux
cmake --install build_linux
cd lib_linux && zip -r ../linux_package.zip . && cd ..

# Build STM32 version
- name: Build STM32 target
run: |
cmake -B build_stm -DCMAKE_INSTALL_PREFIX=lib_stm -DBUILD_TESTING=OFF -DTARGET_STM=ON
cmake --build build_stm
cmake --install build_stm
cd lib_stm && zip -r ../stm_package.zip . && cd ..

# Upload both release artifacts
- name: Upload release artifacts
uses: actions/upload-artifact@v3
with:
name: release-artifacts-${{ github.ref_name }}
path: |
linux_package.zip
stm_package.zip
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@
*.exe
*.out
*.app

# Build Archive
build*/
lib*/
.vscode/
32 changes: 0 additions & 32 deletions C++.gitignore

This file was deleted.

13 changes: 0 additions & 13 deletions CMake.gitignore

This file was deleted.

75 changes: 54 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,65 @@
option(TARGET_STM "Build for STM32F0 using ARM toolchain" OFF)

cmake_minimum_required(VERSION 3.14)
project(my_project)
project(MotorControllerLib)

# GoogleTest requires at least C++17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
if(TARGET_STM)
message(STATUS "Configuring build for STM32F0")
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/cmake/arm-gcc-toolchain.cmake")
set(CMAKE_CXX_STANDARD 17)
else()
message(STATUS "Configuring build for native Linux")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()

# === Library Target ===
add_library(Odrive STATIC
src/lib.cpp
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

enable_testing()
target_include_directories(Odrive PUBLIC ${CMAKE_SOURCE_DIR}/inc)

add_executable(
utils_test
test/test_can_header.cpp
)
# === Install Targets ===
install(TARGETS Odrive
ARCHIVE DESTINATION lib)

target_include_directories(utils_test PRIVATE ${CMAKE_SOURCE_DIR}/inc)
install(DIRECTORY inc/ DESTINATION include)

target_link_libraries(
utils_test
GTest::gtest_main
)
if(NOT CMAKE_CROSSCOMPILING)
# === Enable Testing ===
include(CTest) # enables BUILD_TESTING option
if(BUILD_TESTING)

# Fetch GoogleTest
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

# === Test Executable ===
add_executable(utils_test
test/test_can_header.cpp
test/test_can_msg.cpp
)

target_include_directories(utils_test PRIVATE ${CMAKE_SOURCE_DIR}/inc)

target_link_libraries(utils_test
PRIVATE
Odrive # <-- your library
GTest::gtest_main
)

include(GoogleTest)
gtest_discover_tests(utils_test)

endif()

include(GoogleTest)
gtest_discover_tests(utils_test)
endif()
78 changes: 50 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
# Introduction

This is an official branch for all the device that need to interact with ODrive or Similar Motor Controller. Our team are currently using ODrive V3.6, ODrive Micro, and ODrive S1.

# Folder Structure

The project is divided into generic code & interface in the /inc and /src folder. Target specific code are linked in the /target folder.

```bash
.
├── inc
├── src
└── target
├── ros
├── seeedxiao
└── stm
```
This is an official library repository for all the device that need to interact with ODrive micro or S1 or similar Motor Controller. Our team are currently using ODrive V3.6, ODrive Micro, and ODrive S1. Currently the command set support ODrive Micro and S1 using documentation 6.11. [ODrive Docs](https://docs.odriverobotics.com/v/latest/guides/getting-started.html)

# Project Objective

In short term, this project is aimed to support ODrive family. In long term, this project is also aiming to support custom FOC Device manufactured in house.
- Device Identification
- Device Command Abstraction over CAN
- Grouping Device Command

- High-Level CAN Message Agent
- Device Identification
- Device Command Abstraction over CAN
- Grouping Device Command
- INS/ GNSS Fusion and Logging
- Device Error Handling
- Robotics Simulation Abstraction(Gazebo)

Anyone using this library still need to integrate application/ simulation on top of this static library.
Anyone using this library still need to integrate this library into the application/ simulation on top of this static library.

On my computer the post-compiled library is libodrive.a.

# Folder Structure

# Interface
The project

```bash
.
├── C++.gitignore
├── CMake.gitignore
├── CMakeLists.txt
├── LICENSE
├── README.md
├── build
├── inc
├── src
└── test
```

## Movement Command

Expand Down Expand Up @@ -77,25 +80,44 @@ class Logging {
}
```

# Compile Library and UnitTest

```bash
# Linux Target
# Option 1:
mkdir build && cd build
cmake .. && cd ..
make

# Option 2:
cmake -B build -DCMAKE_INSTALL_PREFIX=lib -DBUILD_TESTING=OFF
cmake --build build
cmake --install build
```

## Set Command

```c++
//todo
```cpp
# STM Target
cmake -B build_stm -DCMAKE_INSTALL_PREFIX=lib_stm -DBUILD_TESTING=OFF -DTARGET_STM=ON
cmake --build build_stm
cmake --install build_stm
```

# Testing and Validation

```bash
# Create build folder based on CMakeLists.txt
cmake -S . -b build

# Compile the project
cmake -B build -DBUILD_TESTING=ON
cmake --build build
ctest --test-dir build

# Execute test
cd build && ctest && cd ..
```

## Triggering Actions

```bash
git tag -a v0.0.3 -m "Release v0.0.1"
git push --follow-tags origin develop
```

# Acknowledgements
19 changes: 19 additions & 0 deletions cmake/arm-gcc-toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Set compiler
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR cortex-m0)

# Specify cross compiler
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
set(CMAKE_ASM_COMPILER arm-none-eabi-gcc)

# No standard C library, no OS
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
set(CMAKE_EXE_LINKER_FLAGS_INIT "")
set(CMAKE_C_FLAGS_INIT "-mcpu=cortex-m0 -mthumb -mfloat-abi=soft -fno-exceptions -ffunction-sections -fdata-sections")
set(CMAKE_CXX_FLAGS_INIT "${CMAKE_C_FLAGS_INIT} -fno-rtti")
set(CMAKE_ASM_FLAGS_INIT "-mcpu=cortex-m0 -mthumb")

# Prevent default CMake stdlib linkage
set(CMAKE_CXX_STANDARD_LIBRARIES "")
set(CMAKE_C_STANDARD_LIBRARIES "")
19 changes: 19 additions & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.14)
project(LibExample)


set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Add the library manually
add_library(libOdrive STATIC IMPORTED GLOBAL)
set_target_properties(libOdrive PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/lib/odrive/lib/libOdrive.a
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR}/lib/odrive/include
)

# Create your executable
add_executable(exec main.cpp)

# Link the imported static lib
target_link_libraries(exec PRIVATE libOdrive)
Loading