diff --git a/.clang-format/.clang-format b/.clang-format/.clang-format
index ac12564..2fc64ef 100644
--- a/.clang-format/.clang-format
+++ b/.clang-format/.clang-format
@@ -62,8 +62,8 @@ UseTab: Never
# Include
IncludeBlocks: Regroup
IncludeCategories:
- # Headers containing "trajectory_generator"
- - Regex: ".*trajectory_generator.*"
+ # Headers containing "traj_gen"
+ - Regex: ".*traj_gen.*"
Priority: 5
CaseSensitive: true
# Project's headers
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
new file mode 100644
index 0000000..cc141d0
--- /dev/null
+++ b/.github/workflows/build.yml
@@ -0,0 +1,40 @@
+name: ROS 2 CI
+
+on:
+ push:
+ branches: "main"
+ pull_request:
+ branches: "main"
+
+jobs:
+ build-and-test:
+ runs-on: ubuntu-22.04
+ container:
+ image: ros:humble
+
+ steps:
+ - name: Install tools
+ run: apt-get update && apt-get install -y git
+
+ - name: Checkout repository
+ uses: actions/checkout@v4
+ with:
+ path: src/trajectory_generator
+
+ - name: Install dependencies
+ run: |
+ apt-get update
+ apt-get install -y python3-colcon-common-extensions
+ rosdep update
+ rosdep install --from-paths src --ignore-src -y
+
+ - name: Build package
+ run: |
+ . /opt/ros/humble/setup.sh
+ colcon build --packages-select traj_gen --cmake-args -DBUILD_TESTING=ON
+
+ - name: Run tests
+ run: |
+ . /opt/ros/humble/setup.sh
+ colcon test --packages-select traj_gen
+ colcon test-result --all
diff --git a/CMakeLists.txt b/CMakeLists.txt
index af92306..38017cf 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.14)
-project(trajectory_generator)
+project(traj_gen)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
@@ -14,7 +14,7 @@ find_package(ament_cmake_gtest REQUIRED)
# library
add_library(${PROJECT_NAME} SHARED
- src/trajectory_generator.cpp
+ src/common.cpp
src/spline.cpp
)
@@ -26,7 +26,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC
)
target_compile_definitions(${PROJECT_NAME}
- PRIVATE "TRAJECTORY_GENERATOR_BUILDING_LIBRARY"
+ PRIVATE "TRAJ_GEN_BUILDING_LIBRARY"
)
# install setting
@@ -80,14 +80,14 @@ if(BUILD_TESTING)
find_package(GTest REQUIRED)
- add_executable(unit_test_trajectory_generator
- test/unit_test_trajectory_generator.cpp
+ add_executable(unit_test_traj_gen
+ test/unit_test_traj_gen.cpp
)
- target_link_libraries(unit_test_trajectory_generator
+ target_link_libraries(unit_test_traj_gen
${PROJECT_NAME}
GTest::gtest
)
include(GoogleTest)
- gtest_discover_tests(unit_test_trajectory_generator)
+ gtest_discover_tests(unit_test_traj_gen)
endif()
diff --git a/README.md b/README.md
index d0a7e04..5d462a6 100644
--- a/README.md
+++ b/README.md
@@ -1,35 +1,123 @@
# trajectory_generator
-## How to Install
+[](https://github.com/MasazumiImai/trajectory_generator/actions)
+[](https://opensource.org/licenses/Apache-2.0)
-```bash
-mkdir -p ~/ros2_ws/src && ~/ros2_ws/src
-git clone https://github.com/MasazumiImai/trajectory_generator.git
-```
+A lightweight and extensible C++ library for generating and interpolating trajectories for robotics. It provides robust interpolation for N-dimensional vectors (e.g., joint angles, task-space positions) and SO(3) orientations (quaternions).
+
+This package can be used as a standalone C++ library or integrated seamlessly as a ROS 2 (`ament_cmake`) package.
+
+## Features
-## How to Build
+* **N-Dimensional Vector Trajectory:** Generate smooth spline trajectories with position, velocity, and acceleration constraints.
+* **SO(3) Orientation Trajectory:** Perform accurate quaternion interpolation in the SO(3) space using Exponential and Logarithmic maps (`expMap` / `logMap`).
+* **ROS 2 Ready:** Fully compatible with the ROS 2 build system (`colcon`).
-### C++
+## Installation & Build
+
+### Prerequisites
+
+* C++ 17 or higher
+* Eigen3
+* ROS 2 (Optional, for `colcon` build)
+
+### As a Standalone C++ Library
```bash
+git clone https://github.com/MasazumiImai/trajectory_generator.git
cd trajectory_generator
-mkdir -p build && cd build
-cmake .. && make && sudo make install
+mkdir build && cd build
+cmake ..
+make
+sudo make install
```
-### ROS 2
+### As a ROS 2 Package
```bash
+mkdir -p ~/ros2_ws/src && cd ~/ros2_ws/src
+git clone https://github.com/MasazumiImai/trajectory_generator.git
cd ~/ros2_ws
-colcon build --packages-select trajectory_generator && . install/setup.bash
+colcon build --packages-select traj_gen
+source install/setup.bash
```
-## How to Test
+## Quick Start / Usage
+
+### For Pure C++ Projects
+
+If you are using standard CMake without ROS 2, simply find the package and link it in your `CMakeLists.txt`:
+
+```CMake
+find_package(traj_gen REQUIRED)
+
+add_executable(your_app src/main.cpp)
+target_link_libraries(your_app traj_gen::traj_gen)
+```
+
+### For ROS 2 Projects
+
+If you are using this library within a ROS 2 package, add the dependency to your `package.xml`:
+
+```xml
+traj_gen
+````
-### C++
+Then, configure your `CMakeLists.txt`:
+
+```CMake
+find_package(traj_gen REQUIRED)
+
+add_executable(your_node src/your_node.cpp)
+ament_target_dependencies(your_node traj_gen)
+```
+
+### C++ Example
+
+Include the master header to access all trajectory generation features.
+
+```C++
+#include
+#include
+
+int main() {
+ // 1. Define constraints
+ int dof = 3;
+
+ traj_gen::VectorStateConstraint start;
+ start.time = 0.0;
+ start.position = Eigen::VectorXd::Zero(dof);
+ start.velocity = Eigen::VectorXd::Zero(dof);
+
+ traj_gen::VectorStateConstraint end;
+ end.time = 5.0;
+ end.position = Eigen::VectorXd::Ones(dof) * 1.5;
+ end.velocity = Eigen::VectorXd::Zero(dof);
+
+ std::vector constraints = traj_gen::createBoundaryConditions(start, end);
+
+ // 2. Generate Spline Trajectory
+ std::shared_ptr planner = std::make_shared(constraints, dof);
+
+ // 3. Get state at specific time
+ double current_time = 2.5;
+ Eigen::VectorXd pos = planner->getPosition(current_time);
+ Eigen::VectorXd vel = planner->getVelocity(current_time);
+
+ std::cout << "Position at t=2.5: \n" << pos << std::endl;
+
+ return 0;
+}
+```
+
+## Testing
+
+If you want to run the unit tests:
```bash
+cd trajectory_generator
mkdir -p build && cd build
-cmake .. -DBUILD_TESTING=ON && make
+cmake .. -DBUILD_TESTING=ON
+make
ctest -V
```
diff --git a/include/traj_gen/base.hpp b/include/traj_gen/base.hpp
new file mode 100644
index 0000000..4c8e394
--- /dev/null
+++ b/include/traj_gen/base.hpp
@@ -0,0 +1,47 @@
+// Copyright (c) 2025 Masazumi Imai
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef TRAJ_GEN__BASE_HPP_
+#define TRAJ_GEN__BASE_HPP_
+
+#include
+
+#include "traj_gen/visibility_control.h"
+
+namespace traj_gen
+{
+
+class TRAJ_GEN_PUBLIC VectorTrajectoryBase
+{
+public:
+ virtual ~VectorTrajectoryBase() = default;
+
+ virtual Eigen::VectorXd getPosition(double time) = 0;
+
+ virtual Eigen::VectorXd getVelocity(double time) = 0;
+};
+
+class TRAJ_GEN_PUBLIC OrientationTrajectoryBase
+{
+public:
+ virtual ~OrientationTrajectoryBase() = default;
+
+ virtual Eigen::Quaterniond getOrientation(double time) = 0;
+
+ virtual Eigen::Vector3d getAngularVelocity(double time) = 0;
+};
+
+} // namespace traj_gen
+
+#endif // TRAJ_GEN__BASE_HPP_
diff --git a/include/trajectory_generator/trajectory_generator.hpp b/include/traj_gen/common.hpp
similarity index 81%
rename from include/trajectory_generator/trajectory_generator.hpp
rename to include/traj_gen/common.hpp
index 3ca928c..de220d6 100644
--- a/include/trajectory_generator/trajectory_generator.hpp
+++ b/include/traj_gen/common.hpp
@@ -12,19 +12,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#ifndef TRAJECTORY_GENERATOR__TRAJECTORY_GENERATOR_HPP_
-#define TRAJECTORY_GENERATOR__TRAJECTORY_GENERATOR_HPP_
+#ifndef TRAJ_GEN__COMMON_HPP_
+#define TRAJ_GEN__COMMON_HPP_
#include
-#include
-#include