Skip to content

Commit

Permalink
Add format files and CI job
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Gesel <[email protected]>
  • Loading branch information
pac48 committed Nov 10, 2024
1 parent c093257 commit 347d391
Show file tree
Hide file tree
Showing 17 changed files with 449 additions and 303 deletions.
68 changes: 34 additions & 34 deletions .github/workflows/cmake-single-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ name: CMake on a single platform

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

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
Expand All @@ -20,35 +20,35 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install urdf-parser-py jinja2 numpy
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_TESTING=ON -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/install

- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --target install

- name: Test
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C ${{env.BUILD_TYPE}}

- name: Configure CMake For Fetch Content
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build_fetch -S ${{github.workspace}}/test/fetch_content_test -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: Build For Fetch Content
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build_fetch --config ${{env.BUILD_TYPE}}
- uses: actions/checkout@v4
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install urdf-parser-py jinja2 numpy
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_TESTING=ON -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/install

- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --target install

- name: Test
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C ${{env.BUILD_TYPE}}

- name: Configure CMake For Fetch Content
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build_fetch -S ${{github.workspace}}/test/fetch_content_test -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: Build For Fetch Content
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build_fetch --config ${{env.BUILD_TYPE}}
15 changes: 15 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: format

on:
# Run action on certain pull request events
pull_request:
types: [opened, synchronize, reopened, ready_for_review]

jobs:
pre-commit:
name: pre-commit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: pre-commit/[email protected]
67 changes: 67 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
repos:

# Runs pre-commit hooks and other file format checks.
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-builtin-literals
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-json
- id: check-merge-conflict
- id: check-symlinks
- id: check-toml
- id: check-vcs-permalinks
- id: check-yaml
- id: debug-statements
- id: destroyed-symlinks
- id: detect-private-key
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: forbid-new-submodules
- id: mixed-line-ending
- id: name-tests-test
- id: requirements-txt-fixer
- id: sort-simple-yaml
- id: trailing-whitespace

# Autoformats Python code.
- repo: https://github.com/psf/black.git
rev: 24.10.0
hooks:
- id: black

# Finds spelling issues in code.
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: codespell

# Finds issues in YAML files.
- repo: https://github.com/adrienverge/yamllint
rev: v1.35.1
hooks:
- id: yamllint
args:
[
"--no-warnings",
"--config-data",
"{extends: default, rules: {line-length: disable, braces: {max-spaces-inside: 1}}}",
]
types: [text]
files: \.(yml|yaml)$

- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.10
hooks:
- id: cmake-format

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v14.0.6
hooks:
- id: clang-format
files: \.(c|cc|cxx|cpp|h|hpp|hxx|)$
args: ["-fallback-style=none"]
58 changes: 30 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,45 @@ include(CTest)
include(fast_forward_kinematics.cmake)

add_library(fast_forward_kinematics_header INTERFACE)
target_include_directories(fast_forward_kinematics_header INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
if (BUILD_TESTING)
add_subdirectory(test)
endif ()

target_include_directories(
fast_forward_kinematics_header
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
if(BUILD_TESTING)
add_subdirectory(test)
endif()

include(CMakePackageConfigHelpers)

configure_package_config_file(fast_forward_kinematics-config.cmake.in fast_forward_kinematics-config.cmake
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/fast_forward_kinematics"
PATH_VARS CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
configure_package_config_file(
fast_forward_kinematics-config.cmake.in fast_forward_kinematics-config.cmake
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/fast_forward_kinematics"
PATH_VARS CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR
NO_CHECK_REQUIRED_COMPONENTS_MACRO)

write_basic_package_version_file(fast_forward_kinematics-config-version.cmake
VERSION ${FFK_VERSION} COMPATIBILITY AnyNewerVersion)
write_basic_package_version_file(
fast_forward_kinematics-config-version.cmake
VERSION ${FFK_VERSION}
COMPATIBILITY AnyNewerVersion)

install(FILES
"${CMAKE_BINARY_DIR}/fast_forward_kinematics-config.cmake"
install(
FILES "${CMAKE_BINARY_DIR}/fast_forward_kinematics-config.cmake"
"${CMAKE_BINARY_DIR}/fast_forward_kinematics-config-version.cmake"
"${CMAKE_SOURCE_DIR}/fast_forward_kinematics.cmake"
DESTINATION "${CMAKE_INSTALL_DATADIR}/fast_forward_kinematics/cmake")
DESTINATION "${CMAKE_INSTALL_DATADIR}/fast_forward_kinematics/cmake")

install(DIRECTORY "${CMAKE_SOURCE_DIR}/code_generation" DESTINATION "${CMAKE_INSTALL_DATADIR}/fast_forward_kinematics/cmake")
install(DIRECTORY include/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/fast_forward_kinematics")
install(DIRECTORY "${CMAKE_SOURCE_DIR}/code_generation"
DESTINATION "${CMAKE_INSTALL_DATADIR}/fast_forward_kinematics/cmake")
install(DIRECTORY include/
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/fast_forward_kinematics")

# Create an export set
install(TARGETS fast_forward_kinematics_header EXPORT fast_forward_kinematicsTargets)
install(TARGETS fast_forward_kinematics_header
EXPORT fast_forward_kinematicsTargets)
# Targets files
export(
EXPORT fast_forward_kinematicsTargets
FILE ${CMAKE_CURRENT_BINARY_DIR}/fast_forward_kinematics-targets.cmake
)
export(EXPORT fast_forward_kinematicsTargets
FILE ${CMAKE_CURRENT_BINARY_DIR}/fast_forward_kinematics-targets.cmake)
install(
EXPORT fast_forward_kinematicsTargets
FILE fast_forward_kinematics-targets.cmake
DESTINATION lib/cmake/fast_forward_kinematics
)
EXPORT fast_forward_kinematicsTargets
FILE fast_forward_kinematics-targets.cmake
DESTINATION lib/cmake/fast_forward_kinematics)
8 changes: 4 additions & 4 deletions code_generation/get_num_joints.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

def run():
parser = argparse.ArgumentParser()
parser.add_argument('urdf_file')
parser.add_argument('root_link_name')
parser.add_argument('tip_link_name')
parser.add_argument("urdf_file")
parser.add_argument("root_link_name")
parser.add_argument("tip_link_name")
args = parser.parse_args()

root_link_name = args.root_link_name
Expand All @@ -18,7 +18,7 @@ def run():
while tip_link_name != root_link_name:
tip_joint_name, tip_link_name = robot.parent_map[tip_link_name]
joint = robot.joint_map[tip_joint_name]
if not joint.type == 'fixed':
if not joint.type == "fixed":
joint_names.append(tip_joint_name)

print(f"FAST_FK_NUMBER_OF_JOINTS={len(joint_names)}", end="")
Expand Down
2 changes: 1 addition & 1 deletion code_generation/robot_config.cpp.template
Original file line number Diff line number Diff line change
Expand Up @@ -362,4 +362,4 @@ namespace fast_fk::internal {
}

}
#endif
#endif
2 changes: 1 addition & 1 deletion code_generation/robot_config.cu.template
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,4 @@ namespace fast_fk::internal {
if (cudaerr != cudaSuccess)
std::printf("kernel launch failed with error \"%s\".\n", cudaGetErrorString(cudaerr));
}
}
}
71 changes: 43 additions & 28 deletions code_generation/robot_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

def run():
parser = argparse.ArgumentParser()
parser.add_argument('urdf_file')
parser.add_argument('fk_template')
parser.add_argument('fk_output_file')
parser.add_argument('root_link_name')
parser.add_argument('tip_link_name')
parser.add_argument("urdf_file")
parser.add_argument("fk_template")
parser.add_argument("fk_output_file")
parser.add_argument("root_link_name")
parser.add_argument("tip_link_name")
args = parser.parse_args()

root_link_name = args.root_link_name
Expand All @@ -24,17 +24,29 @@ def get_transform(joint):
xyz = joint.origin.xyz
T = np.eye(4)

yaw = np.array([[np.cos(rpy[2]), np.sin(rpy[2]), 0],
[-np.sin(rpy[2]), np.cos(rpy[2]), 0],
[0, 0, 1]])

pitch = np.array([[np.cos(rpy[1]), 0, np.sin(rpy[1])],
[0, 1, 0],
[-np.sin(rpy[1]), 0, np.cos(rpy[1])]])

roll = np.array([[1, 0, 0],
[0, np.cos(rpy[0]), np.sin(rpy[0])],
[0, -np.sin(rpy[0]), np.cos(rpy[0])]])
yaw = np.array(
[
[np.cos(rpy[2]), np.sin(rpy[2]), 0],
[-np.sin(rpy[2]), np.cos(rpy[2]), 0],
[0, 0, 1],
]
)

pitch = np.array(
[
[np.cos(rpy[1]), 0, np.sin(rpy[1])],
[0, 1, 0],
[-np.sin(rpy[1]), 0, np.cos(rpy[1])],
]
)

roll = np.array(
[
[1, 0, 0],
[0, np.cos(rpy[0]), np.sin(rpy[0])],
[0, -np.sin(rpy[0]), np.cos(rpy[0])],
]
)
T[:3, :3] = yaw @ pitch @ roll
T[:3, 3] = xyz

Expand All @@ -53,40 +65,43 @@ def get_transform(joint):
T_fixed = np.eye(4)
for joint_name in joint_names:
joint = robot.joint_map[joint_name]
if joint.type == 'fixed':
if joint.type == "fixed":
T_fixed = T_fixed * get_transform(joint)
elif joint.type == 'revolute':
elif joint.type == "revolute":
# TODO: need to add joint limits?
T = get_transform(joint) @ T_fixed
T_fixed = np.eye(4)
rotations.append(T[:3, :3])
offsets.append(T[:3, 3])
types.append('revolute')
elif joint.type == 'continuous':
types.append("revolute")
elif joint.type == "continuous":
T = get_transform(joint) @ T_fixed
T_fixed = np.eye(4)
rotations.append(T[:3, :3])
offsets.append(T[:3, 3])
types.append('revolute')
elif joint.type == 'prismatic':
types.append("revolute")
elif joint.type == "prismatic":
# TODO: need to add joint limits?
T = get_transform(joint) @ T_fixed
T_fixed = np.eye(4)
rotations.append(T[:3, :3])
offsets.append(T[:3, 3])
types.append('prismatic')
types.append("prismatic")
else:
raise Exception(f"joint type {joint.type} in URDF not supported")

# truncate near zero values
offsets = [val * (np.abs(val) > 1E-5) for val in offsets]
rotations = [val * (np.abs(val) > 1E-5) for val in rotations]
offsets = [val * (np.abs(val) > 1e-5) for val in offsets]
rotations = [val * (np.abs(val) > 1e-5) for val in rotations]

with open(args.fk_template, 'r') as f:
with open(args.fk_template, "r") as f:
j2_template = Template(f.read())
code = j2_template.render({'rotations': rotations, 'offsets': offsets, 'types': types}, trim_blocks=True)
code = j2_template.render(
{"rotations": rotations, "offsets": offsets, "types": types},
trim_blocks=True,
)

with open(args.fk_output_file, 'w') as f:
with open(args.fk_output_file, "w") as f:
f.write(code)

print(f"FAST_FK_NUMBER_OF_JOINTS={len(types)}", end="")
Expand Down
2 changes: 1 addition & 1 deletion fast_forward_kinematics-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ set(fast_forward_kinematics_FOUND ON)
set_and_check(fast_forward_kinematics_INCLUDE_DIRS "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@")

include("${CMAKE_CURRENT_LIST_DIR}/fast_forward_kinematics-targets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/cmake/fast_forward_kinematics.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/cmake/fast_forward_kinematics.cmake")
Loading

0 comments on commit 347d391

Please sign in to comment.