Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add crc calculation for python LowCmd dds package (can be used in both sdk and ros) #3

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Add readme
yihuai-gao committed Feb 6, 2024
commit 7c66f8b91dc31de5b26ebd9513c3d9c3dbad9407
17 changes: 17 additions & 0 deletions python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Usage

The current `crc_module.so` is compiled on arm64 cpu and python3.8 (compatible with the default Go2 environment). Please compile the library yourself if you are running on a different platform/python environment.

To use it in your Python script (both sdk and ros), please put this file to a directory included in `$PYTHONPATH` and refer to `test_crc.py` for an example. You can also put `crc_module.pyi` to the same directory as `crc_module.so` to enable python type hint.

# Compiling

Activate the correct python environment and use `pip install pybind11` to install pybind.
Find the pybind cmake path and replace `/home/unitree/.local/lib/python3.8/site-packages/pybind11/share/cmake/pybind11` in CMakeLists.txt

```bash
cd python
mkdir build && cd build
cmake ..
make
```
4 changes: 4 additions & 0 deletions python/crc_module.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from unitree_go.msg import LowCmd
def get_crc(LowCmd: LowCmd) -> int:
"""Calculates the CRC of a LowCmd message. Same as the C++ function."""
...
3 changes: 2 additions & 1 deletion python/test_crc.py
Original file line number Diff line number Diff line change
@@ -14,4 +14,5 @@


lowcmd.led = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
print(get_crc(lowcmd))
print(get_crc(lowcmd))
lowcmd.crc = get_crc(lowcmd)