DRLTT SDK¶
Software Development Kit (SDK) for deploying DRLTT into a real-time system, CPU-only and runtime efficient.
Interfaces¶
The Interface of C++ SDK: sdk/drltt-sdk/trajectory_tracker/trajectory_tracker.h
The Interface of Python SDK: sdk/assets/exported-python-sdk/trajectory_tracker.py
Compilation and Exporting¶
This project employs cmake as build system.. The compilation is recommended to be done within a Docker container.
Build Docker Image¶
Build the Docker image drltt:runtime following the instructions in Docker instructions.
Debugging the building process¶
./compile-in-docker.sh can be used to debug the building process. Pass interaction argument to enter the container instead of launching the building process directly.
./compile-in-docker.sh interactive
Furthermore, pass nonsudo argument to avoid entering SUDO account.
./compile-in-docker.sh interactive nonsudo
Run sample program¶
TODO: An executable sample program is coming soon.
If you prefer to use shared libraries on your host machine, please prepend your shared libraries’ path to LD_LIBRARY_PATH.
Static Linking with LibTorch¶
To ensure static linking with LibTorch, you may need to clone the PyTorch’s source code and compile a static version from the source:
PYTORCH_DIR=path/to/pytorch ./compile-in-docker.sh interactive
# in docker container
cd $PYTORCH_DIR && ./scripts/build_mobile.sh
References:
Deployment¶
NOTE: Currently, Python SDK may not be compatible with the user’s PyTorch installation due to incompatibility of shared library unless the user export it on the host machine. Plan to be resolved in the future.
Unpackage the exported tarball and set LD_LIBRARY_PATH manually (effectively modifying it during runtime is not possible):
tar xvzf drltt_sdk_py.tar.gz -C ./
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:./drltt_sdk_py/lib
Reference: https://man7.org/linux/man-pages/man8/ld.so.8.html
Import drltt_sdk_py. As no depedency required except for Python=3.8, you can run the trajectory tracking directly:
from drltt_sdk_py import TrajectoryTracker
tracker = TrajectoryTracker()
reference_line = [(0.1 * 5.0 * step_index, 0.1 * 4.0 * step_index) for step_index in range(60)]
tracked_states, tracked_actions = tracker.track_traference_line(reference_line)
To check the numeric precision, run the following test:
cd drltt_sdk_py && ./check.sh
Development¶
Code format¶
This project uses clang-format to format CXX code according to Google C/C++ Code Style settings.
To launch code-format, run bash format-code.sh:
#!/bin/bash
echo "FORMATTING CPP CODE..."
find . -regex '.*\.\(cpp\|hpp\|cu\|cuh\|c\|h\)' \
-not -path "./build/*" \
-not -path "./proto_gen/*" \
-exec clang-format \
--verbose --style=file -i {} \;
To customize your own clang-format config file, run:
clang-format -style=llvm -dump-config > .clang-format
Debugging¶
Following global objects are useful for achieving runtime result consistency on the Python side and the C++ side:
python:
common.io.GLOBAL_DEBUG_INFOcpp:
drltt::global_debug_info
For example, to compare runtime values of rotation_radius_inv, you may add two lines of code as follows before running ./test/test-cpp.sh fast to launch the debugging process:
diff --git a/sdk/drltt-sdk/dynamics_models/bicycle_model.cpp b/sdk/drltt-sdk/dynamics_models/bicycle_model.cpp
index b694343..bcf01e4 100644
--- a/sdk/drltt-sdk/dynamics_models/bicycle_model.cpp
+++ b/sdk/drltt-sdk/dynamics_models/bicycle_model.cpp
@@ -96,6 +96,8 @@ bool BicycleModel::ComputeRotationRelatedVariables(
*rotation_radius_inv =
std::sin(*omega) / _hyper_parameter.bicycle_model().rearwheel_to_cog();
+ global_debug_info.add_data(*rotation_radius_inv);
+
return true;
}
diff --git a/simulator/dynamics_models/bicycle_model.py b/simulator/dynamics_models/bicycle_model.py
index a2df076..c93e8fe 100644
--- a/simulator/dynamics_models/bicycle_model.py
+++ b/simulator/dynamics_models/bicycle_model.py
@@ -180,6 +180,8 @@ class BicycleModel(BaseDynamicsModel):
omega = normalize_angle(omega)
rotation_radius_inv = np.sin(omega) / hyper_parameter.rearwheel_to_cog
+ from common import GLOBAL_DEBUG_INFO;GLOBAL_DEBUG_INFO.data.append(rotation_radius_inv)
+
return omega, rotation_radius_inv
@property
Check out log file to check the data. gt_data (ground-truth) denotes value on the Python side and rt_data (runtime) denotes value on the C++ side.
5: Test case: 323, Step: 28
5: gt_data: 0.000584156, rt_data: 0.000584146
5: Test case: 323, Step: 29
5: gt_data: -8.38374e-05, rt_data: -8.38471e-05
5: Test case: 323, Step: 30
5: gt_data: -0.00092932, rt_data: -0.00092933
5: Test case: 323, Step: 31
5: gt_data: -0.00189424, rt_data: -0.00189425
References: