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

feat: xacro compilation #361

Merged
merged 21 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2723baa
aip launch fix for XX1
Owen-Liuyuxuan Dec 19, 2024
17eb547
aip_xx1_gen2 example
Owen-Liuyuxuan Dec 19, 2024
0b2d64f
clean up
Owen-Liuyuxuan Dec 19, 2024
5a9e75a
feat(aip_urdf_compiler): significantly improve documentation; add add…
Owen-Liuyuxuan Dec 20, 2024
596d5b0
fix(xx1_des): add frame_id for certain sensors to restore the origina…
Owen-Liuyuxuan Dec 20, 2024
c6095b6
fix(xx1_gen2_des): add frame_id for certain sensors to restore the or…
Owen-Liuyuxuan Dec 20, 2024
bc97d66
create a cmake macro to simplify adaptation of other packages
Owen-Liuyuxuan Dec 20, 2024
c2fd487
xx1_des utilize the new macro
Owen-Liuyuxuan Dec 20, 2024
8634e74
xx1_gen2 utilize the new macro
Owen-Liuyuxuan Dec 20, 2024
3f54a6f
fixbug
Owen-Liuyuxuan Dec 20, 2024
b54e73b
fix debug
Owen-Liuyuxuan Dec 20, 2024
51ad4bd
ci(pre-commit): autofix
pre-commit-ci[bot] Dec 20, 2024
0203f72
add requirement on jinja2
Owen-Liuyuxuan Dec 20, 2024
fa928b0
Merge branch 'feat/xacro_compilation' of https://github.com/tier4/aip…
Owen-Liuyuxuan Dec 20, 2024
877c9f5
add GNSS type; improve error handling; fix velodyne sensor names
Owen-Liuyuxuan Dec 23, 2024
ddbc8f7
added read me documentation, improve the warning and debugging outputs
Owen-Liuyuxuan Dec 23, 2024
ef0bff6
improve documentation
Owen-Liuyuxuan Dec 23, 2024
415326c
fix grammar
Owen-Liuyuxuan Dec 23, 2024
1c21d10
fix cspell
Owen-Liuyuxuan Dec 23, 2024
91ff326
unify the name in aip_urdf_compiler to be URDF compile
Owen-Liuyuxuan Dec 26, 2024
13bb21f
fix bug
Owen-Liuyuxuan Dec 26, 2024
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
19 changes: 19 additions & 0 deletions aip_urdf_compiler/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.5)
project(aip_urdf_compiler)

find_package(ament_cmake_auto REQUIRED)

ament_auto_find_build_dependencies()

# Install cmake directory
install(
DIRECTORY cmake templates scripts
DESTINATION share/${PROJECT_NAME}
)

# Export the package's share directory path

# Add the config extras
ament_package(
CONFIG_EXTRAS "cmake/aip_cmake_urdf_compile.cmake"
)
33 changes: 33 additions & 0 deletions aip_urdf_compiler/cmake/aip_cmake_urdf_compile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@



macro(aip_cmake_urdf_compile)
# Set the correct paths
find_package(PythonInterp REQUIRED) # cspell: ignore Interp
set(aip_urdf_compiler_BASE_DIR "${aip_urdf_compiler_DIR}/../")
set(PYTHON_SCRIPT "${aip_urdf_compiler_BASE_DIR}/scripts/compile_urdf.py")
set(PYTHON_TEMPLATE_DIRECTORY "${aip_urdf_compiler_BASE_DIR}/templates")
set(PYTHON_CALIBRATION_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/config")
set(PYTHON_XACRO_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/urdf")

message(STATUS "PYTHON_SCRIPT path: ${PYTHON_SCRIPT}")
message(STATUS "PYTHON_TEMPLATE_DIRECTORY path: ${PYTHON_TEMPLATE_DIRECTORY}")

# Verify that the required files exist
if(NOT EXISTS "${PYTHON_SCRIPT}")
message(FATAL_ERROR "Could not find compile_urdf.py at ${PYTHON_SCRIPT}")
endif()

# Create a custom command to run the Python script
add_custom_target(xacro_compilation ALL
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python_script_run_flag
)

add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/python_script_run_flag
COMMAND ${PYTHON_EXECUTABLE} ${PYTHON_SCRIPT} ${PYTHON_TEMPLATE_DIRECTORY} ${PYTHON_CALIBRATION_DIRECTORY} ${PYTHON_XACRO_DIRECTORY} ${PROJECT_NAME}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${PYTHON_SCRIPT}
COMMENT "Running Python script for URDF creation"
)
endmacro()
17 changes: 17 additions & 0 deletions aip_urdf_compiler/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<package format="2">
<name>aip_urdf_compiler</name>
<version>0.1.0</version>
<description>The aip_urdf_compiler package</description>

<maintainer email="[email protected]">Yukihiro Saito</maintainer>
<maintainer email="[email protected]">Yuxuan Liu</maintainer>
<license>Apache 2</license>

<buildtool_depend>ament_cmake_auto</buildtool_depend>
<depend>python3-jinja2</depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
142 changes: 142 additions & 0 deletions aip_urdf_compiler/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# aip_urdf_compiler

## Overview

The aip_urdf_compiler package provides tools for dynamically generating URDF (Unified Robot Description Format) files from configuration files during the build process. It simplifies sensor model management by automatically URDF models from sensor configurations.

## Key Features

- Dynamic URDF generation during colcon build
- Automated sensor transform processing
- Support for multiple sensor types and configurations

## Usage

### Package Integration

To use aip_urdf_compiler in your description package:

- Add the dependency in `package.xml`:

```xml
<depend>aip_urdf_compiler</depend>
```

- Add the following to `CMakeLists.txt`:

```cmake
find_package(aip_urdf_compiler REQUIRED)
aip_cmake_urdf_compile()
```

- Configure your sensors in `config/sensors.yaml` with metadata values (Note: do not need to add meta values in `individual_params`):

- `type`: Required string, corresponding to the string value from [existing sensors](#existing-sensors)
- `frame_id`: Optional string, overwrites the TF frame ID.

- Clean up existing `.xacro` files and add to `.gitignore`:

```gitignore
# In your URDF folder
*.xacro
```

### Existing Sensors

```python
class LinkType(enum.Enum):
"""Enum class for the type of the link."""

CAMERA = "monocular_camera"
IMU = "imu"
LIVOX = "livox_horizon"
PANDAR_40P = "pandar_40p"
PANDAR_OT128 = "pandar_ot128"
PANDAR_XT32 = "pandar_xt32"
PANDAR_QT = "pandar_qt"
PANDAR_QT128 = "pandar_qt128"
VELODYNE16 = "velodyne_16"
VLS128 = "velodyne_128"
RADAR = "radar"
GNSS = "gnss"
JOINT_UNITS = "units"
```

## Architecture

### Components

1. **aip_urdf_compiler**

- Main package handling URDF generation
- Processes configuration files
- Manages build-time compilation

2. **aip_cmake_urdf_compile**

- CMake macro implementation
- Creates build targets
- Ensures URDF regeneration on each build

3. **compile_urdf.py**
- Configuration parser
- Transform processor
- URDF generator

### Compilation Process

1. **Configuration Reading**

- Parses `config/sensors.yaml`
- Extracts transformation data
- Validates configurations

2. **Transform Processing**

- Processes each sensor transform
- Determines sensor types and frame IDs
- Generates appropriate macro strings
- Creates `sensors.xacro`

3. **Joint Unit Processing**
- Handles joint unit transforms
- Processes related YAML files
- Generates separate URDF xacro files

## Adding New Sensors

1. Add sensor descriptions (xacro module files) in either:

- Your target package
- `common_sensor_description` package

2. Update the following in `compile_urdf.py`:
- `LinkType` enumeration
- `link_dict` mapping

## Troubleshooting

### Debug Logs

Check build logs for debugging information:

```bash
cat $workspace/log/build_<timestamp>/aip_{project}_description/streams.log
```

### Common Issues

1. Missing sensor definitions

- Ensure sensor type is defined in `LinkType`
- Verify xacro file exists in description package

2. TF Trees errors
- Check frame_id values in sensors.yaml
- Verify transform chain completeness

## Contributing

1. Follow ROS coding standards
2. Test URDF generation with various configurations
3. Update documentation for new features
Loading
Loading